]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-3.0-3.18.1-201501042021.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.18.1-201501042021.patch
CommitLineData
f6f7f858
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..8fa9957 100644
966--- a/arch/arm/include/asm/atomic.h
967+++ b/arch/arm/include/asm/atomic.h
968@@ -18,17 +18,41 @@
969 #include <asm/barrier.h>
970 #include <asm/cmpxchg.h>
971
972+#ifdef CONFIG_GENERIC_ATOMIC64
973+#include <asm-generic/atomic64.h>
974+#endif
975+
976 #define ATOMIC_INIT(i) { (i) }
977
978 #ifdef __KERNEL__
979
980+#ifdef CONFIG_THUMB2_KERNEL
981+#define REFCOUNT_TRAP_INSN "bkpt 0xf1"
982+#else
983+#define REFCOUNT_TRAP_INSN "bkpt 0xf103"
984+#endif
985+
986+#define _ASM_EXTABLE(from, to) \
987+" .pushsection __ex_table,\"a\"\n"\
988+" .align 3\n" \
989+" .long " #from ", " #to"\n" \
990+" .popsection"
991+
992 /*
993 * On ARM, ordinary assignment (str instruction) doesn't clear the local
994 * strex/ldrex monitor on some implementations. The reason we can use it for
995 * atomic_set() is the clrex or dummy strex done on every exception return.
996 */
997 #define atomic_read(v) ACCESS_ONCE((v)->counter)
998+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
999+{
1000+ return ACCESS_ONCE(v->counter);
1001+}
1002 #define atomic_set(v,i) (((v)->counter) = (i))
1003+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
1004+{
1005+ v->counter = i;
1006+}
1007
1008 #if __LINUX_ARM_ARCH__ >= 6
1009
1010@@ -38,26 +62,50 @@
1011 * to ensure that the update happens.
1012 */
1013
1014-#define ATOMIC_OP(op, c_op, asm_op) \
1015-static inline void atomic_##op(int i, atomic_t *v) \
1016+#ifdef CONFIG_PAX_REFCOUNT
1017+#define __OVERFLOW_POST \
1018+ " bvc 3f\n" \
1019+ "2: " REFCOUNT_TRAP_INSN "\n"\
1020+ "3:\n"
1021+#define __OVERFLOW_POST_RETURN \
1022+ " bvc 3f\n" \
1023+" mov %0, %1\n" \
1024+ "2: " REFCOUNT_TRAP_INSN "\n"\
1025+ "3:\n"
1026+#define __OVERFLOW_EXTABLE \
1027+ "4:\n" \
1028+ _ASM_EXTABLE(2b, 4b)
1029+#else
1030+#define __OVERFLOW_POST
1031+#define __OVERFLOW_POST_RETURN
1032+#define __OVERFLOW_EXTABLE
1033+#endif
1034+
1035+#define __ATOMIC_OP(op, suffix, c_op, asm_op, post_op, extable) \
1036+static inline void atomic_##op##suffix(int i, atomic##suffix##_t *v) \
1037 { \
1038 unsigned long tmp; \
1039 int result; \
1040 \
1041 prefetchw(&v->counter); \
1042- __asm__ __volatile__("@ atomic_" #op "\n" \
1043+ __asm__ __volatile__("@ atomic_" #op #suffix "\n" \
1044 "1: ldrex %0, [%3]\n" \
1045 " " #asm_op " %0, %0, %4\n" \
1046+ post_op \
1047 " strex %1, %0, [%3]\n" \
1048 " teq %1, #0\n" \
1049-" bne 1b" \
1050+" bne 1b\n" \
1051+ extable \
1052 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
1053 : "r" (&v->counter), "Ir" (i) \
1054 : "cc"); \
1055 } \
1056
1057-#define ATOMIC_OP_RETURN(op, c_op, asm_op) \
1058-static inline int atomic_##op##_return(int i, atomic_t *v) \
1059+#define ATOMIC_OP(op, c_op, asm_op) __ATOMIC_OP(op, , c_op, asm_op, , )\
1060+ __ATOMIC_OP(op, _unchecked, c_op, asm_op##s, __OVERFLOW_POST, __OVERFLOW_EXTABLE)
1061+
1062+#define __ATOMIC_OP_RETURN(op, suffix, c_op, asm_op, post_op, extable) \
1063+static inline int atomic_##op##_return##suffix(int i, atomic##suffix##_t *v)\
1064 { \
1065 unsigned long tmp; \
1066 int result; \
1067@@ -65,12 +113,14 @@ static inline int atomic_##op##_return(int i, atomic_t *v) \
1068 smp_mb(); \
1069 prefetchw(&v->counter); \
1070 \
1071- __asm__ __volatile__("@ atomic_" #op "_return\n" \
1072+ __asm__ __volatile__("@ atomic_" #op "_return" #suffix "\n" \
1073 "1: ldrex %0, [%3]\n" \
1074 " " #asm_op " %0, %0, %4\n" \
1075+ post_op \
1076 " strex %1, %0, [%3]\n" \
1077 " teq %1, #0\n" \
1078-" bne 1b" \
1079+" bne 1b\n" \
1080+ extable \
1081 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
1082 : "r" (&v->counter), "Ir" (i) \
1083 : "cc"); \
1084@@ -80,6 +130,9 @@ static inline int atomic_##op##_return(int i, atomic_t *v) \
1085 return result; \
1086 }
1087
1088+#define ATOMIC_OP_RETURN(op, c_op, asm_op) __ATOMIC_OP_RETURN(op, , c_op, asm_op, , )\
1089+ __ATOMIC_OP_RETURN(op, _unchecked, c_op, asm_op##s, __OVERFLOW_POST_RETURN, __OVERFLOW_EXTABLE)
1090+
1091 static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1092 {
1093 int oldval;
1094@@ -115,12 +168,24 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1095 __asm__ __volatile__ ("@ atomic_add_unless\n"
1096 "1: ldrex %0, [%4]\n"
1097 " teq %0, %5\n"
1098-" beq 2f\n"
1099-" add %1, %0, %6\n"
1100+" beq 4f\n"
1101+" adds %1, %0, %6\n"
1102+
1103+#ifdef CONFIG_PAX_REFCOUNT
1104+" bvc 3f\n"
1105+"2: " REFCOUNT_TRAP_INSN "\n"
1106+"3:\n"
1107+#endif
1108+
1109 " strex %2, %1, [%4]\n"
1110 " teq %2, #0\n"
1111 " bne 1b\n"
1112-"2:"
1113+"4:"
1114+
1115+#ifdef CONFIG_PAX_REFCOUNT
1116+ _ASM_EXTABLE(2b, 4b)
1117+#endif
1118+
1119 : "=&r" (oldval), "=&r" (newval), "=&r" (tmp), "+Qo" (v->counter)
1120 : "r" (&v->counter), "r" (u), "r" (a)
1121 : "cc");
1122@@ -131,14 +196,36 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1123 return oldval;
1124 }
1125
1126+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1127+{
1128+ unsigned long oldval, res;
1129+
1130+ smp_mb();
1131+
1132+ do {
1133+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1134+ "ldrex %1, [%3]\n"
1135+ "mov %0, #0\n"
1136+ "teq %1, %4\n"
1137+ "strexeq %0, %5, [%3]\n"
1138+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1139+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1140+ : "cc");
1141+ } while (res);
1142+
1143+ smp_mb();
1144+
1145+ return oldval;
1146+}
1147+
1148 #else /* ARM_ARCH_6 */
1149
1150 #ifdef CONFIG_SMP
1151 #error SMP not supported on pre-ARMv6 CPUs
1152 #endif
1153
1154-#define ATOMIC_OP(op, c_op, asm_op) \
1155-static inline void atomic_##op(int i, atomic_t *v) \
1156+#define __ATOMIC_OP(op, suffix, c_op, asm_op) \
1157+static inline void atomic_##op##suffix(int i, atomic##suffix##_t *v) \
1158 { \
1159 unsigned long flags; \
1160 \
1161@@ -147,8 +234,11 @@ static inline void atomic_##op(int i, atomic_t *v) \
1162 raw_local_irq_restore(flags); \
1163 } \
1164
1165-#define ATOMIC_OP_RETURN(op, c_op, asm_op) \
1166-static inline int atomic_##op##_return(int i, atomic_t *v) \
1167+#define ATOMIC_OP(op, c_op, asm_op) __ATOMIC_OP(op, , c_op, asm_op) \
1168+ __ATOMIC_OP(op, _unchecked, c_op, asm_op)
1169+
1170+#define __ATOMIC_OP_RETURN(op, suffix, c_op, asm_op) \
1171+static inline int atomic_##op##_return##suffix(int i, atomic##suffix##_t *v)\
1172 { \
1173 unsigned long flags; \
1174 int val; \
1175@@ -161,6 +251,9 @@ static inline int atomic_##op##_return(int i, atomic_t *v) \
1176 return val; \
1177 }
1178
1179+#define ATOMIC_OP_RETURN(op, c_op, asm_op) __ATOMIC_OP_RETURN(op, , c_op, asm_op)\
1180+ __ATOMIC_OP_RETURN(op, _unchecked, c_op, asm_op)
1181+
1182 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1183 {
1184 int ret;
1185@@ -175,6 +268,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1186 return ret;
1187 }
1188
1189+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1190+{
1191+ return atomic_cmpxchg((atomic_t *)v, old, new);
1192+}
1193+
1194 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1195 {
1196 int c, old;
1197@@ -196,16 +294,38 @@ ATOMIC_OPS(sub, -=, sub)
1198
1199 #undef ATOMIC_OPS
1200 #undef ATOMIC_OP_RETURN
1201+#undef __ATOMIC_OP_RETURN
1202 #undef ATOMIC_OP
1203+#undef __ATOMIC_OP
1204
1205 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1206+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1207+{
1208+ return xchg(&v->counter, new);
1209+}
1210
1211 #define atomic_inc(v) atomic_add(1, v)
1212+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1213+{
1214+ atomic_add_unchecked(1, v);
1215+}
1216 #define atomic_dec(v) atomic_sub(1, v)
1217+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1218+{
1219+ atomic_sub_unchecked(1, v);
1220+}
1221
1222 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1223+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1224+{
1225+ return atomic_add_return_unchecked(1, v) == 0;
1226+}
1227 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1228 #define atomic_inc_return(v) (atomic_add_return(1, v))
1229+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1230+{
1231+ return atomic_add_return_unchecked(1, v);
1232+}
1233 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1234 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1235
1236@@ -216,6 +336,14 @@ typedef struct {
1237 long long counter;
1238 } atomic64_t;
1239
1240+#ifdef CONFIG_PAX_REFCOUNT
1241+typedef struct {
1242+ long long counter;
1243+} atomic64_unchecked_t;
1244+#else
1245+typedef atomic64_t atomic64_unchecked_t;
1246+#endif
1247+
1248 #define ATOMIC64_INIT(i) { (i) }
1249
1250 #ifdef CONFIG_ARM_LPAE
1251@@ -232,6 +360,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1252 return result;
1253 }
1254
1255+static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1256+{
1257+ long long result;
1258+
1259+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1260+" ldrd %0, %H0, [%1]"
1261+ : "=&r" (result)
1262+ : "r" (&v->counter), "Qo" (v->counter)
1263+ );
1264+
1265+ return result;
1266+}
1267+
1268 static inline void atomic64_set(atomic64_t *v, long long i)
1269 {
1270 __asm__ __volatile__("@ atomic64_set\n"
1271@@ -240,6 +381,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1272 : "r" (&v->counter), "r" (i)
1273 );
1274 }
1275+
1276+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1277+{
1278+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1279+" strd %2, %H2, [%1]"
1280+ : "=Qo" (v->counter)
1281+ : "r" (&v->counter), "r" (i)
1282+ );
1283+}
1284 #else
1285 static inline long long atomic64_read(const atomic64_t *v)
1286 {
1287@@ -254,6 +404,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1288 return result;
1289 }
1290
1291+static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1292+{
1293+ long long result;
1294+
1295+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1296+" ldrexd %0, %H0, [%1]"
1297+ : "=&r" (result)
1298+ : "r" (&v->counter), "Qo" (v->counter)
1299+ );
1300+
1301+ return result;
1302+}
1303+
1304 static inline void atomic64_set(atomic64_t *v, long long i)
1305 {
1306 long long tmp;
1307@@ -268,29 +431,57 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1308 : "r" (&v->counter), "r" (i)
1309 : "cc");
1310 }
1311+
1312+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1313+{
1314+ long long tmp;
1315+
1316+ prefetchw(&v->counter);
1317+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1318+"1: ldrexd %0, %H0, [%2]\n"
1319+" strexd %0, %3, %H3, [%2]\n"
1320+" teq %0, #0\n"
1321+" bne 1b"
1322+ : "=&r" (tmp), "=Qo" (v->counter)
1323+ : "r" (&v->counter), "r" (i)
1324+ : "cc");
1325+}
1326 #endif
1327
1328-#define ATOMIC64_OP(op, op1, op2) \
1329-static inline void atomic64_##op(long long i, atomic64_t *v) \
1330+#undef __OVERFLOW_POST_RETURN
1331+#define __OVERFLOW_POST_RETURN \
1332+ " bvc 3f\n" \
1333+" mov %0, %1\n" \
1334+" mov %H0, %H1\n" \
1335+ "2: " REFCOUNT_TRAP_INSN "\n"\
1336+ "3:\n"
1337+
1338+#define __ATOMIC64_OP(op, suffix, op1, op2, post_op, extable) \
1339+static inline void atomic64_##op##suffix(long long i, atomic64##suffix##_t *v)\
1340 { \
1341 long long result; \
1342 unsigned long tmp; \
1343 \
1344 prefetchw(&v->counter); \
1345- __asm__ __volatile__("@ atomic64_" #op "\n" \
1346+ __asm__ __volatile__("@ atomic64_" #op #suffix "\n" \
1347 "1: ldrexd %0, %H0, [%3]\n" \
1348 " " #op1 " %Q0, %Q0, %Q4\n" \
1349 " " #op2 " %R0, %R0, %R4\n" \
1350+ post_op \
1351 " strexd %1, %0, %H0, [%3]\n" \
1352 " teq %1, #0\n" \
1353-" bne 1b" \
1354+" bne 1b\n" \
1355+ extable \
1356 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
1357 : "r" (&v->counter), "r" (i) \
1358 : "cc"); \
1359 } \
1360
1361-#define ATOMIC64_OP_RETURN(op, op1, op2) \
1362-static inline long long atomic64_##op##_return(long long i, atomic64_t *v) \
1363+#define ATOMIC64_OP(op, op1, op2) __ATOMIC64_OP(op, , op1, op2, , ) \
1364+ __ATOMIC64_OP(op, _unchecked, op1, op2##s, __OVERFLOW_POST, __OVERFLOW_EXTABLE)
1365+
1366+#define __ATOMIC64_OP_RETURN(op, op1, op2, post_op, extable) \
1367+static inline long long atomic64_##op##_return##suffix(long long i, atomic64##suffix##_t *v) \
1368 { \
1369 long long result; \
1370 unsigned long tmp; \
1371@@ -298,13 +489,15 @@ static inline long long atomic64_##op##_return(long long i, atomic64_t *v) \
1372 smp_mb(); \
1373 prefetchw(&v->counter); \
1374 \
1375- __asm__ __volatile__("@ atomic64_" #op "_return\n" \
1376+ __asm__ __volatile__("@ atomic64_" #op "_return" #suffix "\n" \
1377 "1: ldrexd %0, %H0, [%3]\n" \
1378 " " #op1 " %Q0, %Q0, %Q4\n" \
1379 " " #op2 " %R0, %R0, %R4\n" \
1380+ post_op \
1381 " strexd %1, %0, %H0, [%3]\n" \
1382 " teq %1, #0\n" \
1383-" bne 1b" \
1384+" bne 1b\n" \
1385+ extable \
1386 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
1387 : "r" (&v->counter), "r" (i) \
1388 : "cc"); \
1389@@ -314,6 +507,9 @@ static inline long long atomic64_##op##_return(long long i, atomic64_t *v) \
1390 return result; \
1391 }
1392
1393+#define ATOMIC64_OP_RETURN(op, op1, op2) __ATOMIC64_OP_RETURN(op, , op1, op2, , ) \
1394+ __ATOMIC64_OP_RETURN(op, _unchecked, op1, op2##s, __OVERFLOW_POST_RETURN, __OVERFLOW_EXTABLE)
1395+
1396 #define ATOMIC64_OPS(op, op1, op2) \
1397 ATOMIC64_OP(op, op1, op2) \
1398 ATOMIC64_OP_RETURN(op, op1, op2)
1399@@ -323,7 +519,12 @@ ATOMIC64_OPS(sub, subs, sbc)
1400
1401 #undef ATOMIC64_OPS
1402 #undef ATOMIC64_OP_RETURN
1403+#undef __ATOMIC64_OP_RETURN
1404 #undef ATOMIC64_OP
1405+#undef __ATOMIC64_OP
1406+#undef __OVERFLOW_EXTABLE
1407+#undef __OVERFLOW_POST_RETURN
1408+#undef __OVERFLOW_POST
1409
1410 static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1411 long long new)
1412@@ -351,6 +552,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1413 return oldval;
1414 }
1415
1416+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1417+ long long new)
1418+{
1419+ long long oldval;
1420+ unsigned long res;
1421+
1422+ smp_mb();
1423+
1424+ do {
1425+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1426+ "ldrexd %1, %H1, [%3]\n"
1427+ "mov %0, #0\n"
1428+ "teq %1, %4\n"
1429+ "teqeq %H1, %H4\n"
1430+ "strexdeq %0, %5, %H5, [%3]"
1431+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1432+ : "r" (&ptr->counter), "r" (old), "r" (new)
1433+ : "cc");
1434+ } while (res);
1435+
1436+ smp_mb();
1437+
1438+ return oldval;
1439+}
1440+
1441 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1442 {
1443 long long result;
1444@@ -376,21 +602,35 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1445 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1446 {
1447 long long result;
1448- unsigned long tmp;
1449+ u64 tmp;
1450
1451 smp_mb();
1452 prefetchw(&v->counter);
1453
1454 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1455-"1: ldrexd %0, %H0, [%3]\n"
1456-" subs %Q0, %Q0, #1\n"
1457-" sbc %R0, %R0, #0\n"
1458+"1: ldrexd %1, %H1, [%3]\n"
1459+" subs %Q0, %Q1, #1\n"
1460+" sbcs %R0, %R1, #0\n"
1461+
1462+#ifdef CONFIG_PAX_REFCOUNT
1463+" bvc 3f\n"
1464+" mov %Q0, %Q1\n"
1465+" mov %R0, %R1\n"
1466+"2: " REFCOUNT_TRAP_INSN "\n"
1467+"3:\n"
1468+#endif
1469+
1470 " teq %R0, #0\n"
1471-" bmi 2f\n"
1472+" bmi 4f\n"
1473 " strexd %1, %0, %H0, [%3]\n"
1474 " teq %1, #0\n"
1475 " bne 1b\n"
1476-"2:"
1477+"4:\n"
1478+
1479+#ifdef CONFIG_PAX_REFCOUNT
1480+ _ASM_EXTABLE(2b, 4b)
1481+#endif
1482+
1483 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1484 : "r" (&v->counter)
1485 : "cc");
1486@@ -414,13 +654,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1487 " teq %0, %5\n"
1488 " teqeq %H0, %H5\n"
1489 " moveq %1, #0\n"
1490-" beq 2f\n"
1491+" beq 4f\n"
1492 " adds %Q0, %Q0, %Q6\n"
1493-" adc %R0, %R0, %R6\n"
1494+" adcs %R0, %R0, %R6\n"
1495+
1496+#ifdef CONFIG_PAX_REFCOUNT
1497+" bvc 3f\n"
1498+"2: " REFCOUNT_TRAP_INSN "\n"
1499+"3:\n"
1500+#endif
1501+
1502 " strexd %2, %0, %H0, [%4]\n"
1503 " teq %2, #0\n"
1504 " bne 1b\n"
1505-"2:"
1506+"4:\n"
1507+
1508+#ifdef CONFIG_PAX_REFCOUNT
1509+ _ASM_EXTABLE(2b, 4b)
1510+#endif
1511+
1512 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1513 : "r" (&v->counter), "r" (u), "r" (a)
1514 : "cc");
1515@@ -433,10 +685,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1516
1517 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1518 #define atomic64_inc(v) atomic64_add(1LL, (v))
1519+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1520 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1521+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1522 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1523 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1524 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1525+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1526 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1527 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1528 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1529diff --git a/arch/arm/include/asm/barrier.h b/arch/arm/include/asm/barrier.h
1530index c6a3e73..35cca85 100644
1531--- a/arch/arm/include/asm/barrier.h
1532+++ b/arch/arm/include/asm/barrier.h
1533@@ -63,7 +63,7 @@
1534 do { \
1535 compiletime_assert_atomic_type(*p); \
1536 smp_mb(); \
1537- ACCESS_ONCE(*p) = (v); \
1538+ ACCESS_ONCE_RW(*p) = (v); \
1539 } while (0)
1540
1541 #define smp_load_acquire(p) \
1542diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1543index 75fe66b..ba3dee4 100644
1544--- a/arch/arm/include/asm/cache.h
1545+++ b/arch/arm/include/asm/cache.h
1546@@ -4,8 +4,10 @@
1547 #ifndef __ASMARM_CACHE_H
1548 #define __ASMARM_CACHE_H
1549
1550+#include <linux/const.h>
1551+
1552 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1553-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1554+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1555
1556 /*
1557 * Memory returned by kmalloc() may be used for DMA, so we must make
1558@@ -24,5 +26,6 @@
1559 #endif
1560
1561 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1562+#define __read_only __attribute__ ((__section__(".data..read_only")))
1563
1564 #endif
1565diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1566index 10e78d0..dc8505d 100644
1567--- a/arch/arm/include/asm/cacheflush.h
1568+++ b/arch/arm/include/asm/cacheflush.h
1569@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1570 void (*dma_unmap_area)(const void *, size_t, int);
1571
1572 void (*dma_flush_range)(const void *, const void *);
1573-};
1574+} __no_const;
1575
1576 /*
1577 * Select the calling method
1578diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1579index 5233151..87a71fa 100644
1580--- a/arch/arm/include/asm/checksum.h
1581+++ b/arch/arm/include/asm/checksum.h
1582@@ -37,7 +37,19 @@ __wsum
1583 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1584
1585 __wsum
1586-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1587+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1588+
1589+static inline __wsum
1590+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1591+{
1592+ __wsum ret;
1593+ pax_open_userland();
1594+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1595+ pax_close_userland();
1596+ return ret;
1597+}
1598+
1599+
1600
1601 /*
1602 * Fold a partial checksum without adding pseudo headers
1603diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1604index abb2c37..96db950 100644
1605--- a/arch/arm/include/asm/cmpxchg.h
1606+++ b/arch/arm/include/asm/cmpxchg.h
1607@@ -104,6 +104,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1608
1609 #define xchg(ptr,x) \
1610 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1611+#define xchg_unchecked(ptr,x) \
1612+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1613
1614 #include <asm-generic/cmpxchg-local.h>
1615
1616diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1617index 6ddbe44..b5e38b1 100644
1618--- a/arch/arm/include/asm/domain.h
1619+++ b/arch/arm/include/asm/domain.h
1620@@ -48,18 +48,37 @@
1621 * Domain types
1622 */
1623 #define DOMAIN_NOACCESS 0
1624-#define DOMAIN_CLIENT 1
1625 #ifdef CONFIG_CPU_USE_DOMAINS
1626+#define DOMAIN_USERCLIENT 1
1627+#define DOMAIN_KERNELCLIENT 1
1628 #define DOMAIN_MANAGER 3
1629+#define DOMAIN_VECTORS DOMAIN_USER
1630 #else
1631+
1632+#ifdef CONFIG_PAX_KERNEXEC
1633 #define DOMAIN_MANAGER 1
1634+#define DOMAIN_KERNEXEC 3
1635+#else
1636+#define DOMAIN_MANAGER 1
1637+#endif
1638+
1639+#ifdef CONFIG_PAX_MEMORY_UDEREF
1640+#define DOMAIN_USERCLIENT 0
1641+#define DOMAIN_UDEREF 1
1642+#define DOMAIN_VECTORS DOMAIN_KERNEL
1643+#else
1644+#define DOMAIN_USERCLIENT 1
1645+#define DOMAIN_VECTORS DOMAIN_USER
1646+#endif
1647+#define DOMAIN_KERNELCLIENT 1
1648+
1649 #endif
1650
1651 #define domain_val(dom,type) ((type) << (2*(dom)))
1652
1653 #ifndef __ASSEMBLY__
1654
1655-#ifdef CONFIG_CPU_USE_DOMAINS
1656+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1657 static inline void set_domain(unsigned val)
1658 {
1659 asm volatile(
1660@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1661 isb();
1662 }
1663
1664-#define modify_domain(dom,type) \
1665- do { \
1666- struct thread_info *thread = current_thread_info(); \
1667- unsigned int domain = thread->cpu_domain; \
1668- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1669- thread->cpu_domain = domain | domain_val(dom, type); \
1670- set_domain(thread->cpu_domain); \
1671- } while (0)
1672-
1673+extern void modify_domain(unsigned int dom, unsigned int type);
1674 #else
1675 static inline void set_domain(unsigned val) { }
1676 static inline void modify_domain(unsigned dom, unsigned type) { }
1677diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1678index afb9caf..9a0bac0 100644
1679--- a/arch/arm/include/asm/elf.h
1680+++ b/arch/arm/include/asm/elf.h
1681@@ -115,7 +115,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1682 the loader. We need to make sure that it is out of the way of the program
1683 that it will "exec", and that there is sufficient room for the brk. */
1684
1685-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1686+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1687+
1688+#ifdef CONFIG_PAX_ASLR
1689+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1690+
1691+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1692+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1693+#endif
1694
1695 /* When the program starts, a1 contains a pointer to a function to be
1696 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1697@@ -125,10 +132,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1698 extern void elf_set_personality(const struct elf32_hdr *);
1699 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1700
1701-struct mm_struct;
1702-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1703-#define arch_randomize_brk arch_randomize_brk
1704-
1705 #ifdef CONFIG_MMU
1706 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1707 struct linux_binprm;
1708diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1709index de53547..52b9a28 100644
1710--- a/arch/arm/include/asm/fncpy.h
1711+++ b/arch/arm/include/asm/fncpy.h
1712@@ -81,7 +81,9 @@
1713 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1714 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1715 \
1716+ pax_open_kernel(); \
1717 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1718+ pax_close_kernel(); \
1719 flush_icache_range((unsigned long)(dest_buf), \
1720 (unsigned long)(dest_buf) + (size)); \
1721 \
1722diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1723index 53e69da..3fdc896 100644
1724--- a/arch/arm/include/asm/futex.h
1725+++ b/arch/arm/include/asm/futex.h
1726@@ -46,6 +46,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1727 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1728 return -EFAULT;
1729
1730+ pax_open_userland();
1731+
1732 smp_mb();
1733 /* Prefetching cannot fault */
1734 prefetchw(uaddr);
1735@@ -63,6 +65,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1736 : "cc", "memory");
1737 smp_mb();
1738
1739+ pax_close_userland();
1740+
1741 *uval = val;
1742 return ret;
1743 }
1744@@ -93,6 +97,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1745 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1746 return -EFAULT;
1747
1748+ pax_open_userland();
1749+
1750 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1751 "1: " TUSER(ldr) " %1, [%4]\n"
1752 " teq %1, %2\n"
1753@@ -103,6 +109,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1754 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1755 : "cc", "memory");
1756
1757+ pax_close_userland();
1758+
1759 *uval = val;
1760 return ret;
1761 }
1762@@ -125,6 +133,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1763 return -EFAULT;
1764
1765 pagefault_disable(); /* implies preempt_disable() */
1766+ pax_open_userland();
1767
1768 switch (op) {
1769 case FUTEX_OP_SET:
1770@@ -146,6 +155,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1771 ret = -ENOSYS;
1772 }
1773
1774+ pax_close_userland();
1775 pagefault_enable(); /* subsumes preempt_enable() */
1776
1777 if (!ret) {
1778diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1779index 83eb2f7..ed77159 100644
1780--- a/arch/arm/include/asm/kmap_types.h
1781+++ b/arch/arm/include/asm/kmap_types.h
1782@@ -4,6 +4,6 @@
1783 /*
1784 * This is the "bare minimum". AIO seems to require this.
1785 */
1786-#define KM_TYPE_NR 16
1787+#define KM_TYPE_NR 17
1788
1789 #endif
1790diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1791index 9e614a1..3302cca 100644
1792--- a/arch/arm/include/asm/mach/dma.h
1793+++ b/arch/arm/include/asm/mach/dma.h
1794@@ -22,7 +22,7 @@ struct dma_ops {
1795 int (*residue)(unsigned int, dma_t *); /* optional */
1796 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1797 const char *type;
1798-};
1799+} __do_const;
1800
1801 struct dma_struct {
1802 void *addr; /* single DMA address */
1803diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1804index f98c7f3..e5c626d 100644
1805--- a/arch/arm/include/asm/mach/map.h
1806+++ b/arch/arm/include/asm/mach/map.h
1807@@ -23,17 +23,19 @@ struct map_desc {
1808
1809 /* types 0-3 are defined in asm/io.h */
1810 enum {
1811- MT_UNCACHED = 4,
1812- MT_CACHECLEAN,
1813- MT_MINICLEAN,
1814+ MT_UNCACHED_RW = 4,
1815+ MT_CACHECLEAN_RO,
1816+ MT_MINICLEAN_RO,
1817 MT_LOW_VECTORS,
1818 MT_HIGH_VECTORS,
1819- MT_MEMORY_RWX,
1820+ __MT_MEMORY_RWX,
1821 MT_MEMORY_RW,
1822- MT_ROM,
1823- MT_MEMORY_RWX_NONCACHED,
1824+ MT_MEMORY_RX,
1825+ MT_ROM_RX,
1826+ MT_MEMORY_RW_NONCACHED,
1827+ MT_MEMORY_RX_NONCACHED,
1828 MT_MEMORY_RW_DTCM,
1829- MT_MEMORY_RWX_ITCM,
1830+ MT_MEMORY_RX_ITCM,
1831 MT_MEMORY_RW_SO,
1832 MT_MEMORY_DMA_READY,
1833 };
1834diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1835index 891a56b..48f337e 100644
1836--- a/arch/arm/include/asm/outercache.h
1837+++ b/arch/arm/include/asm/outercache.h
1838@@ -36,7 +36,7 @@ struct outer_cache_fns {
1839
1840 /* This is an ARM L2C thing */
1841 void (*write_sec)(unsigned long, unsigned);
1842-};
1843+} __no_const;
1844
1845 extern struct outer_cache_fns outer_cache;
1846
1847diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1848index 4355f0e..cd9168e 100644
1849--- a/arch/arm/include/asm/page.h
1850+++ b/arch/arm/include/asm/page.h
1851@@ -23,6 +23,7 @@
1852
1853 #else
1854
1855+#include <linux/compiler.h>
1856 #include <asm/glue.h>
1857
1858 /*
1859@@ -114,7 +115,7 @@ struct cpu_user_fns {
1860 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1861 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1862 unsigned long vaddr, struct vm_area_struct *vma);
1863-};
1864+} __no_const;
1865
1866 #ifdef MULTI_USER
1867 extern struct cpu_user_fns cpu_user;
1868diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1869index 78a7793..e3dc06c 100644
1870--- a/arch/arm/include/asm/pgalloc.h
1871+++ b/arch/arm/include/asm/pgalloc.h
1872@@ -17,6 +17,7 @@
1873 #include <asm/processor.h>
1874 #include <asm/cacheflush.h>
1875 #include <asm/tlbflush.h>
1876+#include <asm/system_info.h>
1877
1878 #define check_pgt_cache() do { } while (0)
1879
1880@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1881 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1882 }
1883
1884+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1885+{
1886+ pud_populate(mm, pud, pmd);
1887+}
1888+
1889 #else /* !CONFIG_ARM_LPAE */
1890
1891 /*
1892@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1893 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1894 #define pmd_free(mm, pmd) do { } while (0)
1895 #define pud_populate(mm,pmd,pte) BUG()
1896+#define pud_populate_kernel(mm,pmd,pte) BUG()
1897
1898 #endif /* CONFIG_ARM_LPAE */
1899
1900@@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1901 __free_page(pte);
1902 }
1903
1904+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1905+{
1906+#ifdef CONFIG_ARM_LPAE
1907+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1908+#else
1909+ if (addr & SECTION_SIZE)
1910+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1911+ else
1912+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1913+#endif
1914+ flush_pmd_entry(pmdp);
1915+}
1916+
1917 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1918 pmdval_t prot)
1919 {
1920@@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1921 static inline void
1922 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1923 {
1924- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1925+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1926 }
1927 #define pmd_pgtable(pmd) pmd_page(pmd)
1928
1929diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1930index 5cfba15..f415e1a 100644
1931--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1932+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1933@@ -20,12 +20,15 @@
1934 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1935 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1936 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1937+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1938 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1939 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1940 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1941+
1942 /*
1943 * - section
1944 */
1945+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1946 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1947 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1948 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1949@@ -37,6 +40,7 @@
1950 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1951 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1952 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1953+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1954
1955 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1956 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1957@@ -66,6 +70,7 @@
1958 * - extended small page/tiny page
1959 */
1960 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1961+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1962 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1963 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1964 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1965diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1966index f027941..f36ce30 100644
1967--- a/arch/arm/include/asm/pgtable-2level.h
1968+++ b/arch/arm/include/asm/pgtable-2level.h
1969@@ -126,6 +126,9 @@
1970 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1971 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1972
1973+/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1974+#define L_PTE_PXN (_AT(pteval_t, 0))
1975+
1976 /*
1977 * These are the memory types, defined to be compatible with
1978 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1979diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1980index 9fd61c7..f8f1cff 100644
1981--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1982+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1983@@ -76,6 +76,7 @@
1984 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1985 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1986 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1987+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1988 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1989
1990 /*
1991diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1992index a31ecdad..95e98d4 100644
1993--- a/arch/arm/include/asm/pgtable-3level.h
1994+++ b/arch/arm/include/asm/pgtable-3level.h
1995@@ -81,6 +81,7 @@
1996 #define L_PTE_USER (_AT(pteval_t, 1) << 6) /* AP[1] */
1997 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1998 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1999+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2000 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
2001 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55)
2002 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56)
2003@@ -92,10 +93,12 @@
2004 #define L_PMD_SECT_SPLITTING (_AT(pmdval_t, 1) << 56)
2005 #define L_PMD_SECT_NONE (_AT(pmdval_t, 1) << 57)
2006 #define L_PMD_SECT_RDONLY (_AT(pteval_t, 1) << 58)
2007+#define PMD_SECT_RDONLY PMD_SECT_AP2
2008
2009 /*
2010 * To be used in assembly code with the upper page attributes.
2011 */
2012+#define L_PTE_PXN_HIGH (1 << (53 - 32))
2013 #define L_PTE_XN_HIGH (1 << (54 - 32))
2014 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
2015
2016diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
2017index 3b30062..01a5f9d 100644
2018--- a/arch/arm/include/asm/pgtable.h
2019+++ b/arch/arm/include/asm/pgtable.h
2020@@ -33,6 +33,9 @@
2021 #include <asm/pgtable-2level.h>
2022 #endif
2023
2024+#define ktla_ktva(addr) (addr)
2025+#define ktva_ktla(addr) (addr)
2026+
2027 /*
2028 * Just any arbitrary offset to the start of the vmalloc VM area: the
2029 * current 8MB value just means that there will be a 8MB "hole" after the
2030@@ -48,6 +51,9 @@
2031 #define LIBRARY_TEXT_START 0x0c000000
2032
2033 #ifndef __ASSEMBLY__
2034+extern pteval_t __supported_pte_mask;
2035+extern pmdval_t __supported_pmd_mask;
2036+
2037 extern void __pte_error(const char *file, int line, pte_t);
2038 extern void __pmd_error(const char *file, int line, pmd_t);
2039 extern void __pgd_error(const char *file, int line, pgd_t);
2040@@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2041 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2042 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2043
2044+#define __HAVE_ARCH_PAX_OPEN_KERNEL
2045+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2046+
2047+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2048+#include <asm/domain.h>
2049+#include <linux/thread_info.h>
2050+#include <linux/preempt.h>
2051+
2052+static inline int test_domain(int domain, int domaintype)
2053+{
2054+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2055+}
2056+#endif
2057+
2058+#ifdef CONFIG_PAX_KERNEXEC
2059+static inline unsigned long pax_open_kernel(void) {
2060+#ifdef CONFIG_ARM_LPAE
2061+ /* TODO */
2062+#else
2063+ preempt_disable();
2064+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2065+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2066+#endif
2067+ return 0;
2068+}
2069+
2070+static inline unsigned long pax_close_kernel(void) {
2071+#ifdef CONFIG_ARM_LPAE
2072+ /* TODO */
2073+#else
2074+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2075+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2076+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2077+ preempt_enable_no_resched();
2078+#endif
2079+ return 0;
2080+}
2081+#else
2082+static inline unsigned long pax_open_kernel(void) { return 0; }
2083+static inline unsigned long pax_close_kernel(void) { return 0; }
2084+#endif
2085+
2086 /*
2087 * This is the lowest virtual address we can permit any user space
2088 * mapping to be mapped at. This is particularly important for
2089@@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2090 /*
2091 * The pgprot_* and protection_map entries will be fixed up in runtime
2092 * to include the cachable and bufferable bits based on memory policy,
2093- * as well as any architecture dependent bits like global/ASID and SMP
2094- * shared mapping bits.
2095+ * as well as any architecture dependent bits like global/ASID, PXN,
2096+ * and SMP shared mapping bits.
2097 */
2098 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2099
2100@@ -267,7 +315,7 @@ PTE_BIT_FUNC(mknexec, |= L_PTE_XN);
2101 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2102 {
2103 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2104- L_PTE_NONE | L_PTE_VALID;
2105+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2106 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2107 return pte;
2108 }
2109diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2110index c25ef3e..735f14b 100644
2111--- a/arch/arm/include/asm/psci.h
2112+++ b/arch/arm/include/asm/psci.h
2113@@ -32,7 +32,7 @@ struct psci_operations {
2114 int (*affinity_info)(unsigned long target_affinity,
2115 unsigned long lowest_affinity_level);
2116 int (*migrate_info_type)(void);
2117-};
2118+} __no_const;
2119
2120 extern struct psci_operations psci_ops;
2121 extern struct smp_operations psci_smp_ops;
2122diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2123index 18f5a55..5072a40 100644
2124--- a/arch/arm/include/asm/smp.h
2125+++ b/arch/arm/include/asm/smp.h
2126@@ -107,7 +107,7 @@ struct smp_operations {
2127 int (*cpu_disable)(unsigned int cpu);
2128 #endif
2129 #endif
2130-};
2131+} __no_const;
2132
2133 struct of_cpu_method {
2134 const char *method;
2135diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2136index ce73ab6..7310f8a 100644
2137--- a/arch/arm/include/asm/thread_info.h
2138+++ b/arch/arm/include/asm/thread_info.h
2139@@ -78,9 +78,9 @@ struct thread_info {
2140 .flags = 0, \
2141 .preempt_count = INIT_PREEMPT_COUNT, \
2142 .addr_limit = KERNEL_DS, \
2143- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2144- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2145- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2146+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2147+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2148+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2149 .restart_block = { \
2150 .fn = do_no_restart_syscall, \
2151 }, \
2152@@ -154,7 +154,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2153 #define TIF_SYSCALL_AUDIT 9
2154 #define TIF_SYSCALL_TRACEPOINT 10
2155 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2156-#define TIF_NOHZ 12 /* in adaptive nohz mode */
2157+/* within 8 bits of TIF_SYSCALL_TRACE
2158+ * to meet flexible second operand requirements
2159+ */
2160+#define TIF_GRSEC_SETXID 12
2161+#define TIF_NOHZ 13 /* in adaptive nohz mode */
2162 #define TIF_USING_IWMMXT 17
2163 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2164 #define TIF_RESTORE_SIGMASK 20
2165@@ -168,10 +172,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2166 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2167 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2168 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2169+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2170
2171 /* Checks for any syscall work in entry-common.S */
2172 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2173- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2174+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2175
2176 /*
2177 * Change these and you break ASM code in entry-common.S
2178diff --git a/arch/arm/include/asm/tls.h b/arch/arm/include/asm/tls.h
2179index 5f833f7..76e6644 100644
2180--- a/arch/arm/include/asm/tls.h
2181+++ b/arch/arm/include/asm/tls.h
2182@@ -3,6 +3,7 @@
2183
2184 #include <linux/compiler.h>
2185 #include <asm/thread_info.h>
2186+#include <asm/pgtable.h>
2187
2188 #ifdef __ASSEMBLY__
2189 #include <asm/asm-offsets.h>
2190@@ -89,7 +90,9 @@ static inline void set_tls(unsigned long val)
2191 * at 0xffff0fe0 must be used instead. (see
2192 * entry-armv.S for details)
2193 */
2194+ pax_open_kernel();
2195 *((unsigned int *)0xffff0ff0) = val;
2196+ pax_close_kernel();
2197 #endif
2198 }
2199
2200diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2201index 4767eb9..bf00668 100644
2202--- a/arch/arm/include/asm/uaccess.h
2203+++ b/arch/arm/include/asm/uaccess.h
2204@@ -18,6 +18,7 @@
2205 #include <asm/domain.h>
2206 #include <asm/unified.h>
2207 #include <asm/compiler.h>
2208+#include <asm/pgtable.h>
2209
2210 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2211 #include <asm-generic/uaccess-unaligned.h>
2212@@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2213 static inline void set_fs(mm_segment_t fs)
2214 {
2215 current_thread_info()->addr_limit = fs;
2216- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2217+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2218 }
2219
2220 #define segment_eq(a,b) ((a) == (b))
2221
2222+#define __HAVE_ARCH_PAX_OPEN_USERLAND
2223+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2224+
2225+static inline void pax_open_userland(void)
2226+{
2227+
2228+#ifdef CONFIG_PAX_MEMORY_UDEREF
2229+ if (segment_eq(get_fs(), USER_DS)) {
2230+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2231+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2232+ }
2233+#endif
2234+
2235+}
2236+
2237+static inline void pax_close_userland(void)
2238+{
2239+
2240+#ifdef CONFIG_PAX_MEMORY_UDEREF
2241+ if (segment_eq(get_fs(), USER_DS)) {
2242+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2243+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2244+ }
2245+#endif
2246+
2247+}
2248+
2249 #define __addr_ok(addr) ({ \
2250 unsigned long flag; \
2251 __asm__("cmp %2, %0; movlo %0, #0" \
2252@@ -198,8 +226,12 @@ extern int __get_user_64t_4(void *);
2253
2254 #define get_user(x,p) \
2255 ({ \
2256+ int __e; \
2257 might_fault(); \
2258- __get_user_check(x,p); \
2259+ pax_open_userland(); \
2260+ __e = __get_user_check(x,p); \
2261+ pax_close_userland(); \
2262+ __e; \
2263 })
2264
2265 extern int __put_user_1(void *, unsigned int);
2266@@ -244,8 +276,12 @@ extern int __put_user_8(void *, unsigned long long);
2267
2268 #define put_user(x,p) \
2269 ({ \
2270+ int __e; \
2271 might_fault(); \
2272- __put_user_check(x,p); \
2273+ pax_open_userland(); \
2274+ __e = __put_user_check(x,p); \
2275+ pax_close_userland(); \
2276+ __e; \
2277 })
2278
2279 #else /* CONFIG_MMU */
2280@@ -269,6 +305,7 @@ static inline void set_fs(mm_segment_t fs)
2281
2282 #endif /* CONFIG_MMU */
2283
2284+#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2285 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2286
2287 #define user_addr_max() \
2288@@ -286,13 +323,17 @@ static inline void set_fs(mm_segment_t fs)
2289 #define __get_user(x,ptr) \
2290 ({ \
2291 long __gu_err = 0; \
2292+ pax_open_userland(); \
2293 __get_user_err((x),(ptr),__gu_err); \
2294+ pax_close_userland(); \
2295 __gu_err; \
2296 })
2297
2298 #define __get_user_error(x,ptr,err) \
2299 ({ \
2300+ pax_open_userland(); \
2301 __get_user_err((x),(ptr),err); \
2302+ pax_close_userland(); \
2303 (void) 0; \
2304 })
2305
2306@@ -368,13 +409,17 @@ do { \
2307 #define __put_user(x,ptr) \
2308 ({ \
2309 long __pu_err = 0; \
2310+ pax_open_userland(); \
2311 __put_user_err((x),(ptr),__pu_err); \
2312+ pax_close_userland(); \
2313 __pu_err; \
2314 })
2315
2316 #define __put_user_error(x,ptr,err) \
2317 ({ \
2318+ pax_open_userland(); \
2319 __put_user_err((x),(ptr),err); \
2320+ pax_close_userland(); \
2321 (void) 0; \
2322 })
2323
2324@@ -474,11 +519,44 @@ do { \
2325
2326
2327 #ifdef CONFIG_MMU
2328-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2329-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2330+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2331+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2332+
2333+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2334+{
2335+ unsigned long ret;
2336+
2337+ check_object_size(to, n, false);
2338+ pax_open_userland();
2339+ ret = ___copy_from_user(to, from, n);
2340+ pax_close_userland();
2341+ return ret;
2342+}
2343+
2344+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2345+{
2346+ unsigned long ret;
2347+
2348+ check_object_size(from, n, true);
2349+ pax_open_userland();
2350+ ret = ___copy_to_user(to, from, n);
2351+ pax_close_userland();
2352+ return ret;
2353+}
2354+
2355 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2356-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2357+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2358 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2359+
2360+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2361+{
2362+ unsigned long ret;
2363+ pax_open_userland();
2364+ ret = ___clear_user(addr, n);
2365+ pax_close_userland();
2366+ return ret;
2367+}
2368+
2369 #else
2370 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2371 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2372@@ -487,6 +565,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2373
2374 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2375 {
2376+ if ((long)n < 0)
2377+ return n;
2378+
2379 if (access_ok(VERIFY_READ, from, n))
2380 n = __copy_from_user(to, from, n);
2381 else /* security hole - plug it */
2382@@ -496,6 +577,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2383
2384 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2385 {
2386+ if ((long)n < 0)
2387+ return n;
2388+
2389 if (access_ok(VERIFY_WRITE, to, n))
2390 n = __copy_to_user(to, from, n);
2391 return n;
2392diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2393index 5af0ed1..cea83883 100644
2394--- a/arch/arm/include/uapi/asm/ptrace.h
2395+++ b/arch/arm/include/uapi/asm/ptrace.h
2396@@ -92,7 +92,7 @@
2397 * ARMv7 groups of PSR bits
2398 */
2399 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2400-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2401+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2402 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2403 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2404
2405diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2406index a88671c..1cc895e 100644
2407--- a/arch/arm/kernel/armksyms.c
2408+++ b/arch/arm/kernel/armksyms.c
2409@@ -55,7 +55,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2410
2411 /* networking */
2412 EXPORT_SYMBOL(csum_partial);
2413-EXPORT_SYMBOL(csum_partial_copy_from_user);
2414+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2415 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2416 EXPORT_SYMBOL(__csum_ipv6_magic);
2417
2418@@ -91,9 +91,9 @@ EXPORT_SYMBOL(__memzero);
2419 #ifdef CONFIG_MMU
2420 EXPORT_SYMBOL(copy_page);
2421
2422-EXPORT_SYMBOL(__copy_from_user);
2423-EXPORT_SYMBOL(__copy_to_user);
2424-EXPORT_SYMBOL(__clear_user);
2425+EXPORT_SYMBOL(___copy_from_user);
2426+EXPORT_SYMBOL(___copy_to_user);
2427+EXPORT_SYMBOL(___clear_user);
2428
2429 EXPORT_SYMBOL(__get_user_1);
2430 EXPORT_SYMBOL(__get_user_2);
2431diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2432index 2f5555d..d493c91 100644
2433--- a/arch/arm/kernel/entry-armv.S
2434+++ b/arch/arm/kernel/entry-armv.S
2435@@ -47,6 +47,87 @@
2436 9997:
2437 .endm
2438
2439+ .macro pax_enter_kernel
2440+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2441+ @ make aligned space for saved DACR
2442+ sub sp, sp, #8
2443+ @ save regs
2444+ stmdb sp!, {r1, r2}
2445+ @ read DACR from cpu_domain into r1
2446+ mov r2, sp
2447+ @ assume 8K pages, since we have to split the immediate in two
2448+ bic r2, r2, #(0x1fc0)
2449+ bic r2, r2, #(0x3f)
2450+ ldr r1, [r2, #TI_CPU_DOMAIN]
2451+ @ store old DACR on stack
2452+ str r1, [sp, #8]
2453+#ifdef CONFIG_PAX_KERNEXEC
2454+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2455+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2456+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2457+#endif
2458+#ifdef CONFIG_PAX_MEMORY_UDEREF
2459+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2460+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2461+#endif
2462+ @ write r1 to current_thread_info()->cpu_domain
2463+ str r1, [r2, #TI_CPU_DOMAIN]
2464+ @ write r1 to DACR
2465+ mcr p15, 0, r1, c3, c0, 0
2466+ @ instruction sync
2467+ instr_sync
2468+ @ restore regs
2469+ ldmia sp!, {r1, r2}
2470+#endif
2471+ .endm
2472+
2473+ .macro pax_open_userland
2474+#ifdef CONFIG_PAX_MEMORY_UDEREF
2475+ @ save regs
2476+ stmdb sp!, {r0, r1}
2477+ @ read DACR from cpu_domain into r1
2478+ mov r0, sp
2479+ @ assume 8K pages, since we have to split the immediate in two
2480+ bic r0, r0, #(0x1fc0)
2481+ bic r0, r0, #(0x3f)
2482+ ldr r1, [r0, #TI_CPU_DOMAIN]
2483+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2484+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2485+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2486+ @ write r1 to current_thread_info()->cpu_domain
2487+ str r1, [r0, #TI_CPU_DOMAIN]
2488+ @ write r1 to DACR
2489+ mcr p15, 0, r1, c3, c0, 0
2490+ @ instruction sync
2491+ instr_sync
2492+ @ restore regs
2493+ ldmia sp!, {r0, r1}
2494+#endif
2495+ .endm
2496+
2497+ .macro pax_close_userland
2498+#ifdef CONFIG_PAX_MEMORY_UDEREF
2499+ @ save regs
2500+ stmdb sp!, {r0, r1}
2501+ @ read DACR from cpu_domain into r1
2502+ mov r0, sp
2503+ @ assume 8K pages, since we have to split the immediate in two
2504+ bic r0, r0, #(0x1fc0)
2505+ bic r0, r0, #(0x3f)
2506+ ldr r1, [r0, #TI_CPU_DOMAIN]
2507+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2508+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2509+ @ write r1 to current_thread_info()->cpu_domain
2510+ str r1, [r0, #TI_CPU_DOMAIN]
2511+ @ write r1 to DACR
2512+ mcr p15, 0, r1, c3, c0, 0
2513+ @ instruction sync
2514+ instr_sync
2515+ @ restore regs
2516+ ldmia sp!, {r0, r1}
2517+#endif
2518+ .endm
2519+
2520 .macro pabt_helper
2521 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2522 #ifdef MULTI_PABORT
2523@@ -89,11 +170,15 @@
2524 * Invalid mode handlers
2525 */
2526 .macro inv_entry, reason
2527+
2528+ pax_enter_kernel
2529+
2530 sub sp, sp, #S_FRAME_SIZE
2531 ARM( stmib sp, {r1 - lr} )
2532 THUMB( stmia sp, {r0 - r12} )
2533 THUMB( str sp, [sp, #S_SP] )
2534 THUMB( str lr, [sp, #S_LR] )
2535+
2536 mov r1, #\reason
2537 .endm
2538
2539@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2540 .macro svc_entry, stack_hole=0, trace=1
2541 UNWIND(.fnstart )
2542 UNWIND(.save {r0 - pc} )
2543+
2544+ pax_enter_kernel
2545+
2546 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2547+
2548 #ifdef CONFIG_THUMB2_KERNEL
2549 SPFIX( str r0, [sp] ) @ temporarily saved
2550 SPFIX( mov r0, sp )
2551@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2552 ldmia r0, {r3 - r5}
2553 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2554 mov r6, #-1 @ "" "" "" ""
2555+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2556+ @ offset sp by 8 as done in pax_enter_kernel
2557+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2558+#else
2559 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2560+#endif
2561 SPFIX( addeq r2, r2, #4 )
2562 str r3, [sp, #-4]! @ save the "real" r0 copied
2563 @ from the exception stack
2564@@ -368,6 +462,9 @@ ENDPROC(__fiq_abt)
2565 .macro usr_entry, trace=1
2566 UNWIND(.fnstart )
2567 UNWIND(.cantunwind ) @ don't unwind the user space
2568+
2569+ pax_enter_kernel_user
2570+
2571 sub sp, sp, #S_FRAME_SIZE
2572 ARM( stmib sp, {r1 - r12} )
2573 THUMB( stmia sp, {r0 - r12} )
2574@@ -478,7 +575,9 @@ __und_usr:
2575 tst r3, #PSR_T_BIT @ Thumb mode?
2576 bne __und_usr_thumb
2577 sub r4, r2, #4 @ ARM instr at LR - 4
2578+ pax_open_userland
2579 1: ldrt r0, [r4]
2580+ pax_close_userland
2581 ARM_BE8(rev r0, r0) @ little endian instruction
2582
2583 @ r0 = 32-bit ARM instruction which caused the exception
2584@@ -512,11 +611,15 @@ __und_usr_thumb:
2585 */
2586 .arch armv6t2
2587 #endif
2588+ pax_open_userland
2589 2: ldrht r5, [r4]
2590+ pax_close_userland
2591 ARM_BE8(rev16 r5, r5) @ little endian instruction
2592 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2593 blo __und_usr_fault_16 @ 16bit undefined instruction
2594+ pax_open_userland
2595 3: ldrht r0, [r2]
2596+ pax_close_userland
2597 ARM_BE8(rev16 r0, r0) @ little endian instruction
2598 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2599 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2600@@ -546,7 +649,8 @@ ENDPROC(__und_usr)
2601 */
2602 .pushsection .fixup, "ax"
2603 .align 2
2604-4: str r4, [sp, #S_PC] @ retry current instruction
2605+4: pax_close_userland
2606+ str r4, [sp, #S_PC] @ retry current instruction
2607 ret r9
2608 .popsection
2609 .pushsection __ex_table,"a"
2610@@ -766,7 +870,7 @@ ENTRY(__switch_to)
2611 THUMB( str lr, [ip], #4 )
2612 ldr r4, [r2, #TI_TP_VALUE]
2613 ldr r5, [r2, #TI_TP_VALUE + 4]
2614-#ifdef CONFIG_CPU_USE_DOMAINS
2615+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2616 ldr r6, [r2, #TI_CPU_DOMAIN]
2617 #endif
2618 switch_tls r1, r4, r5, r3, r7
2619@@ -775,7 +879,7 @@ ENTRY(__switch_to)
2620 ldr r8, =__stack_chk_guard
2621 ldr r7, [r7, #TSK_STACK_CANARY]
2622 #endif
2623-#ifdef CONFIG_CPU_USE_DOMAINS
2624+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2625 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2626 #endif
2627 mov r5, r0
2628diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2629index 6bb09d4..113e875 100644
2630--- a/arch/arm/kernel/entry-common.S
2631+++ b/arch/arm/kernel/entry-common.S
2632@@ -11,18 +11,46 @@
2633 #include <asm/assembler.h>
2634 #include <asm/unistd.h>
2635 #include <asm/ftrace.h>
2636+#include <asm/domain.h>
2637 #include <asm/unwind.h>
2638
2639+#include "entry-header.S"
2640+
2641 #ifdef CONFIG_NEED_RET_TO_USER
2642 #include <mach/entry-macro.S>
2643 #else
2644 .macro arch_ret_to_user, tmp1, tmp2
2645+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2646+ @ save regs
2647+ stmdb sp!, {r1, r2}
2648+ @ read DACR from cpu_domain into r1
2649+ mov r2, sp
2650+ @ assume 8K pages, since we have to split the immediate in two
2651+ bic r2, r2, #(0x1fc0)
2652+ bic r2, r2, #(0x3f)
2653+ ldr r1, [r2, #TI_CPU_DOMAIN]
2654+#ifdef CONFIG_PAX_KERNEXEC
2655+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2656+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2657+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2658+#endif
2659+#ifdef CONFIG_PAX_MEMORY_UDEREF
2660+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2661+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2662+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2663+#endif
2664+ @ write r1 to current_thread_info()->cpu_domain
2665+ str r1, [r2, #TI_CPU_DOMAIN]
2666+ @ write r1 to DACR
2667+ mcr p15, 0, r1, c3, c0, 0
2668+ @ instruction sync
2669+ instr_sync
2670+ @ restore regs
2671+ ldmia sp!, {r1, r2}
2672+#endif
2673 .endm
2674 #endif
2675
2676-#include "entry-header.S"
2677-
2678-
2679 .align 5
2680 /*
2681 * This is the fast syscall return path. We do as little as
2682@@ -406,6 +434,12 @@ ENTRY(vector_swi)
2683 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2684 #endif
2685
2686+ /*
2687+ * do this here to avoid a performance hit of wrapping the code above
2688+ * that directly dereferences userland to parse the SWI instruction
2689+ */
2690+ pax_enter_kernel_user
2691+
2692 adr tbl, sys_call_table @ load syscall table pointer
2693
2694 #if defined(CONFIG_OABI_COMPAT)
2695diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2696index 4176df7..a901f8d 100644
2697--- a/arch/arm/kernel/entry-header.S
2698+++ b/arch/arm/kernel/entry-header.S
2699@@ -196,6 +196,60 @@
2700 msr cpsr_c, \rtemp @ switch back to the SVC mode
2701 .endm
2702
2703+ .macro pax_enter_kernel_user
2704+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2705+ @ save regs
2706+ stmdb sp!, {r0, r1}
2707+ @ read DACR from cpu_domain into r1
2708+ mov r0, sp
2709+ @ assume 8K pages, since we have to split the immediate in two
2710+ bic r0, r0, #(0x1fc0)
2711+ bic r0, r0, #(0x3f)
2712+ ldr r1, [r0, #TI_CPU_DOMAIN]
2713+#ifdef CONFIG_PAX_MEMORY_UDEREF
2714+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2715+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2716+#endif
2717+#ifdef CONFIG_PAX_KERNEXEC
2718+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2719+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2720+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2721+#endif
2722+ @ write r1 to current_thread_info()->cpu_domain
2723+ str r1, [r0, #TI_CPU_DOMAIN]
2724+ @ write r1 to DACR
2725+ mcr p15, 0, r1, c3, c0, 0
2726+ @ instruction sync
2727+ instr_sync
2728+ @ restore regs
2729+ ldmia sp!, {r0, r1}
2730+#endif
2731+ .endm
2732+
2733+ .macro pax_exit_kernel
2734+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2735+ @ save regs
2736+ stmdb sp!, {r0, r1}
2737+ @ read old DACR from stack into r1
2738+ ldr r1, [sp, #(8 + S_SP)]
2739+ sub r1, r1, #8
2740+ ldr r1, [r1]
2741+
2742+ @ write r1 to current_thread_info()->cpu_domain
2743+ mov r0, sp
2744+ @ assume 8K pages, since we have to split the immediate in two
2745+ bic r0, r0, #(0x1fc0)
2746+ bic r0, r0, #(0x3f)
2747+ str r1, [r0, #TI_CPU_DOMAIN]
2748+ @ write r1 to DACR
2749+ mcr p15, 0, r1, c3, c0, 0
2750+ @ instruction sync
2751+ instr_sync
2752+ @ restore regs
2753+ ldmia sp!, {r0, r1}
2754+#endif
2755+ .endm
2756+
2757 #ifndef CONFIG_THUMB2_KERNEL
2758 .macro svc_exit, rpsr, irq = 0
2759 .if \irq != 0
2760@@ -215,6 +269,9 @@
2761 blne trace_hardirqs_off
2762 #endif
2763 .endif
2764+
2765+ pax_exit_kernel
2766+
2767 msr spsr_cxsf, \rpsr
2768 #if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_32v6K)
2769 @ We must avoid clrex due to Cortex-A15 erratum #830321
2770@@ -290,6 +347,9 @@
2771 blne trace_hardirqs_off
2772 #endif
2773 .endif
2774+
2775+ pax_exit_kernel
2776+
2777 ldr lr, [sp, #S_SP] @ top of the stack
2778 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2779
2780diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2781index b37752a..ff5cb72 100644
2782--- a/arch/arm/kernel/fiq.c
2783+++ b/arch/arm/kernel/fiq.c
2784@@ -95,7 +95,10 @@ void set_fiq_handler(void *start, unsigned int length)
2785 void *base = vectors_page;
2786 unsigned offset = FIQ_OFFSET;
2787
2788+ pax_open_kernel();
2789 memcpy(base + offset, start, length);
2790+ pax_close_kernel();
2791+
2792 if (!cache_is_vipt_nonaliasing())
2793 flush_icache_range((unsigned long)base + offset, offset +
2794 length);
2795diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2796index 664eee8..f470938 100644
2797--- a/arch/arm/kernel/head.S
2798+++ b/arch/arm/kernel/head.S
2799@@ -437,7 +437,7 @@ __enable_mmu:
2800 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2801 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2802 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2803- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2804+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2805 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2806 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2807 #endif
2808diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2809index 6a4dffe..4a86a70 100644
2810--- a/arch/arm/kernel/module.c
2811+++ b/arch/arm/kernel/module.c
2812@@ -38,12 +38,39 @@
2813 #endif
2814
2815 #ifdef CONFIG_MMU
2816-void *module_alloc(unsigned long size)
2817+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2818 {
2819+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2820+ return NULL;
2821 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2822- GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2823+ GFP_KERNEL, prot, NUMA_NO_NODE,
2824 __builtin_return_address(0));
2825 }
2826+
2827+void *module_alloc(unsigned long size)
2828+{
2829+
2830+#ifdef CONFIG_PAX_KERNEXEC
2831+ return __module_alloc(size, PAGE_KERNEL);
2832+#else
2833+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2834+#endif
2835+
2836+}
2837+
2838+#ifdef CONFIG_PAX_KERNEXEC
2839+void module_free_exec(struct module *mod, void *module_region)
2840+{
2841+ module_free(mod, module_region);
2842+}
2843+EXPORT_SYMBOL(module_free_exec);
2844+
2845+void *module_alloc_exec(unsigned long size)
2846+{
2847+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2848+}
2849+EXPORT_SYMBOL(module_alloc_exec);
2850+#endif
2851 #endif
2852
2853 int
2854diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2855index 07314af..c46655c 100644
2856--- a/arch/arm/kernel/patch.c
2857+++ b/arch/arm/kernel/patch.c
2858@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2859 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2860 int size;
2861
2862+ pax_open_kernel();
2863 if (thumb2 && __opcode_is_thumb16(insn)) {
2864 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2865 size = sizeof(u16);
2866@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2867 *(u32 *)addr = insn;
2868 size = sizeof(u32);
2869 }
2870+ pax_close_kernel();
2871
2872 flush_icache_range((uintptr_t)(addr),
2873 (uintptr_t)(addr) + size);
2874diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2875index fe972a2..a772d83 100644
2876--- a/arch/arm/kernel/process.c
2877+++ b/arch/arm/kernel/process.c
2878@@ -207,6 +207,7 @@ void machine_power_off(void)
2879
2880 if (pm_power_off)
2881 pm_power_off();
2882+ BUG();
2883 }
2884
2885 /*
2886@@ -220,7 +221,7 @@ void machine_power_off(void)
2887 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2888 * to use. Implementing such co-ordination would be essentially impossible.
2889 */
2890-void machine_restart(char *cmd)
2891+__noreturn void machine_restart(char *cmd)
2892 {
2893 local_irq_disable();
2894 smp_send_stop();
2895@@ -246,8 +247,8 @@ void __show_regs(struct pt_regs *regs)
2896
2897 show_regs_print_info(KERN_DEFAULT);
2898
2899- print_symbol("PC is at %s\n", instruction_pointer(regs));
2900- print_symbol("LR is at %s\n", regs->ARM_lr);
2901+ printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2902+ printk("LR is at %pA\n", (void *)regs->ARM_lr);
2903 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2904 "sp : %08lx ip : %08lx fp : %08lx\n",
2905 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2906@@ -424,12 +425,6 @@ unsigned long get_wchan(struct task_struct *p)
2907 return 0;
2908 }
2909
2910-unsigned long arch_randomize_brk(struct mm_struct *mm)
2911-{
2912- unsigned long range_end = mm->brk + 0x02000000;
2913- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2914-}
2915-
2916 #ifdef CONFIG_MMU
2917 #ifdef CONFIG_KUSER_HELPERS
2918 /*
2919@@ -445,7 +440,7 @@ static struct vm_area_struct gate_vma = {
2920
2921 static int __init gate_vma_init(void)
2922 {
2923- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2924+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2925 return 0;
2926 }
2927 arch_initcall(gate_vma_init);
2928@@ -474,81 +469,13 @@ const char *arch_vma_name(struct vm_area_struct *vma)
2929 return is_gate_vma(vma) ? "[vectors]" : NULL;
2930 }
2931
2932-/* If possible, provide a placement hint at a random offset from the
2933- * stack for the signal page.
2934- */
2935-static unsigned long sigpage_addr(const struct mm_struct *mm,
2936- unsigned int npages)
2937-{
2938- unsigned long offset;
2939- unsigned long first;
2940- unsigned long last;
2941- unsigned long addr;
2942- unsigned int slots;
2943-
2944- first = PAGE_ALIGN(mm->start_stack);
2945-
2946- last = TASK_SIZE - (npages << PAGE_SHIFT);
2947-
2948- /* No room after stack? */
2949- if (first > last)
2950- return 0;
2951-
2952- /* Just enough room? */
2953- if (first == last)
2954- return first;
2955-
2956- slots = ((last - first) >> PAGE_SHIFT) + 1;
2957-
2958- offset = get_random_int() % slots;
2959-
2960- addr = first + (offset << PAGE_SHIFT);
2961-
2962- return addr;
2963-}
2964-
2965-static struct page *signal_page;
2966-extern struct page *get_signal_page(void);
2967-
2968-static const struct vm_special_mapping sigpage_mapping = {
2969- .name = "[sigpage]",
2970- .pages = &signal_page,
2971-};
2972-
2973 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2974 {
2975 struct mm_struct *mm = current->mm;
2976- struct vm_area_struct *vma;
2977- unsigned long addr;
2978- unsigned long hint;
2979- int ret = 0;
2980-
2981- if (!signal_page)
2982- signal_page = get_signal_page();
2983- if (!signal_page)
2984- return -ENOMEM;
2985
2986 down_write(&mm->mmap_sem);
2987- hint = sigpage_addr(mm, 1);
2988- addr = get_unmapped_area(NULL, hint, PAGE_SIZE, 0, 0);
2989- if (IS_ERR_VALUE(addr)) {
2990- ret = addr;
2991- goto up_fail;
2992- }
2993-
2994- vma = _install_special_mapping(mm, addr, PAGE_SIZE,
2995- VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2996- &sigpage_mapping);
2997-
2998- if (IS_ERR(vma)) {
2999- ret = PTR_ERR(vma);
3000- goto up_fail;
3001- }
3002-
3003- mm->context.sigpage = addr;
3004-
3005- up_fail:
3006+ mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
3007 up_write(&mm->mmap_sem);
3008- return ret;
3009+ return 0;
3010 }
3011 #endif
3012diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
3013index f73891b..cf3004e 100644
3014--- a/arch/arm/kernel/psci.c
3015+++ b/arch/arm/kernel/psci.c
3016@@ -28,7 +28,7 @@
3017 #include <asm/psci.h>
3018 #include <asm/system_misc.h>
3019
3020-struct psci_operations psci_ops;
3021+struct psci_operations psci_ops __read_only;
3022
3023 static int (*invoke_psci_fn)(u32, u32, u32, u32);
3024 typedef int (*psci_initcall_t)(const struct device_node *);
3025diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
3026index ef9119f..31995a3 100644
3027--- a/arch/arm/kernel/ptrace.c
3028+++ b/arch/arm/kernel/ptrace.c
3029@@ -928,10 +928,19 @@ static void tracehook_report_syscall(struct pt_regs *regs,
3030 regs->ARM_ip = ip;
3031 }
3032
3033+#ifdef CONFIG_GRKERNSEC_SETXID
3034+extern void gr_delayed_cred_worker(void);
3035+#endif
3036+
3037 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
3038 {
3039 current_thread_info()->syscall = scno;
3040
3041+#ifdef CONFIG_GRKERNSEC_SETXID
3042+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3043+ gr_delayed_cred_worker();
3044+#endif
3045+
3046 /* Do the secure computing check first; failures should be fast. */
3047 #ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
3048 if (secure_computing() == -1)
3049diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
3050index c031063..e277ab8 100644
3051--- a/arch/arm/kernel/setup.c
3052+++ b/arch/arm/kernel/setup.c
3053@@ -104,21 +104,23 @@ EXPORT_SYMBOL(elf_hwcap);
3054 unsigned int elf_hwcap2 __read_mostly;
3055 EXPORT_SYMBOL(elf_hwcap2);
3056
3057+pteval_t __supported_pte_mask __read_only;
3058+pmdval_t __supported_pmd_mask __read_only;
3059
3060 #ifdef MULTI_CPU
3061-struct processor processor __read_mostly;
3062+struct processor processor __read_only;
3063 #endif
3064 #ifdef MULTI_TLB
3065-struct cpu_tlb_fns cpu_tlb __read_mostly;
3066+struct cpu_tlb_fns cpu_tlb __read_only;
3067 #endif
3068 #ifdef MULTI_USER
3069-struct cpu_user_fns cpu_user __read_mostly;
3070+struct cpu_user_fns cpu_user __read_only;
3071 #endif
3072 #ifdef MULTI_CACHE
3073-struct cpu_cache_fns cpu_cache __read_mostly;
3074+struct cpu_cache_fns cpu_cache __read_only;
3075 #endif
3076 #ifdef CONFIG_OUTER_CACHE
3077-struct outer_cache_fns outer_cache __read_mostly;
3078+struct outer_cache_fns outer_cache __read_only;
3079 EXPORT_SYMBOL(outer_cache);
3080 #endif
3081
3082@@ -252,9 +254,13 @@ static int __get_cpu_architecture(void)
3083 asm("mrc p15, 0, %0, c0, c1, 4"
3084 : "=r" (mmfr0));
3085 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3086- (mmfr0 & 0x000000f0) >= 0x00000030)
3087+ (mmfr0 & 0x000000f0) >= 0x00000030) {
3088 cpu_arch = CPU_ARCH_ARMv7;
3089- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3090+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3091+ __supported_pte_mask |= L_PTE_PXN;
3092+ __supported_pmd_mask |= PMD_PXNTABLE;
3093+ }
3094+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3095 (mmfr0 & 0x000000f0) == 0x00000020)
3096 cpu_arch = CPU_ARCH_ARMv6;
3097 else
3098diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3099index bd19834..e4d8c66 100644
3100--- a/arch/arm/kernel/signal.c
3101+++ b/arch/arm/kernel/signal.c
3102@@ -24,8 +24,6 @@
3103
3104 extern const unsigned long sigreturn_codes[7];
3105
3106-static unsigned long signal_return_offset;
3107-
3108 #ifdef CONFIG_CRUNCH
3109 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3110 {
3111@@ -396,8 +394,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3112 * except when the MPU has protected the vectors
3113 * page from PL0
3114 */
3115- retcode = mm->context.sigpage + signal_return_offset +
3116- (idx << 2) + thumb;
3117+ retcode = mm->context.sigpage + (idx << 2) + thumb;
3118 } else
3119 #endif
3120 {
3121@@ -604,33 +601,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3122 } while (thread_flags & _TIF_WORK_MASK);
3123 return 0;
3124 }
3125-
3126-struct page *get_signal_page(void)
3127-{
3128- unsigned long ptr;
3129- unsigned offset;
3130- struct page *page;
3131- void *addr;
3132-
3133- page = alloc_pages(GFP_KERNEL, 0);
3134-
3135- if (!page)
3136- return NULL;
3137-
3138- addr = page_address(page);
3139-
3140- /* Give the signal return code some randomness */
3141- offset = 0x200 + (get_random_int() & 0x7fc);
3142- signal_return_offset = offset;
3143-
3144- /*
3145- * Copy signal return handlers into the vector page, and
3146- * set sigreturn to be a pointer to these.
3147- */
3148- memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3149-
3150- ptr = (unsigned long)addr + offset;
3151- flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3152-
3153- return page;
3154-}
3155diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3156index 13396d3..589d615 100644
3157--- a/arch/arm/kernel/smp.c
3158+++ b/arch/arm/kernel/smp.c
3159@@ -76,7 +76,7 @@ enum ipi_msg_type {
3160
3161 static DECLARE_COMPLETION(cpu_running);
3162
3163-static struct smp_operations smp_ops;
3164+static struct smp_operations smp_ops __read_only;
3165
3166 void __init smp_set_ops(struct smp_operations *ops)
3167 {
3168diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
3169index 7a3be1d..b00c7de 100644
3170--- a/arch/arm/kernel/tcm.c
3171+++ b/arch/arm/kernel/tcm.c
3172@@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
3173 .virtual = ITCM_OFFSET,
3174 .pfn = __phys_to_pfn(ITCM_OFFSET),
3175 .length = 0,
3176- .type = MT_MEMORY_RWX_ITCM,
3177+ .type = MT_MEMORY_RX_ITCM,
3178 }
3179 };
3180
3181@@ -267,7 +267,9 @@ no_dtcm:
3182 start = &__sitcm_text;
3183 end = &__eitcm_text;
3184 ram = &__itcm_start;
3185+ pax_open_kernel();
3186 memcpy(start, ram, itcm_code_sz);
3187+ pax_close_kernel();
3188 pr_debug("CPU ITCM: copied code from %p - %p\n",
3189 start, end);
3190 itcm_present = true;
3191diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3192index 9f5d818..e013427 100644
3193--- a/arch/arm/kernel/traps.c
3194+++ b/arch/arm/kernel/traps.c
3195@@ -65,7 +65,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3196 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3197 {
3198 #ifdef CONFIG_KALLSYMS
3199- printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3200+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3201 #else
3202 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3203 #endif
3204@@ -267,6 +267,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3205 static int die_owner = -1;
3206 static unsigned int die_nest_count;
3207
3208+extern void gr_handle_kernel_exploit(void);
3209+
3210 static unsigned long oops_begin(void)
3211 {
3212 int cpu;
3213@@ -309,6 +311,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3214 panic("Fatal exception in interrupt");
3215 if (panic_on_oops)
3216 panic("Fatal exception");
3217+
3218+ gr_handle_kernel_exploit();
3219+
3220 if (signr)
3221 do_exit(signr);
3222 }
3223@@ -880,7 +885,11 @@ void __init early_trap_init(void *vectors_base)
3224 kuser_init(vectors_base);
3225
3226 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3227- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3228+
3229+#ifndef CONFIG_PAX_MEMORY_UDEREF
3230+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3231+#endif
3232+
3233 #else /* ifndef CONFIG_CPU_V7M */
3234 /*
3235 * on V7-M there is no need to copy the vector table to a dedicated
3236diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3237index 8e95aa4..595dfc8 100644
3238--- a/arch/arm/kernel/vmlinux.lds.S
3239+++ b/arch/arm/kernel/vmlinux.lds.S
3240@@ -8,7 +8,11 @@
3241 #include <asm/thread_info.h>
3242 #include <asm/memory.h>
3243 #include <asm/page.h>
3244-
3245+
3246+#ifdef CONFIG_PAX_KERNEXEC
3247+#include <asm/pgtable.h>
3248+#endif
3249+
3250 #define PROC_INFO \
3251 . = ALIGN(4); \
3252 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3253@@ -34,7 +38,7 @@
3254 #endif
3255
3256 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3257- defined(CONFIG_GENERIC_BUG)
3258+ defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3259 #define ARM_EXIT_KEEP(x) x
3260 #define ARM_EXIT_DISCARD(x)
3261 #else
3262@@ -90,6 +94,11 @@ SECTIONS
3263 _text = .;
3264 HEAD_TEXT
3265 }
3266+
3267+#ifdef CONFIG_PAX_KERNEXEC
3268+ . = ALIGN(1<<SECTION_SHIFT);
3269+#endif
3270+
3271 .text : { /* Real text segment */
3272 _stext = .; /* Text and read-only data */
3273 __exception_text_start = .;
3274@@ -112,6 +121,8 @@ SECTIONS
3275 ARM_CPU_KEEP(PROC_INFO)
3276 }
3277
3278+ _etext = .; /* End of text section */
3279+
3280 RO_DATA(PAGE_SIZE)
3281
3282 . = ALIGN(4);
3283@@ -142,7 +153,9 @@ SECTIONS
3284
3285 NOTES
3286
3287- _etext = .; /* End of text and rodata section */
3288+#ifdef CONFIG_PAX_KERNEXEC
3289+ . = ALIGN(1<<SECTION_SHIFT);
3290+#endif
3291
3292 #ifndef CONFIG_XIP_KERNEL
3293 . = ALIGN(PAGE_SIZE);
3294@@ -221,6 +234,11 @@ SECTIONS
3295 #else
3296 . = ALIGN(THREAD_SIZE);
3297 __init_end = .;
3298+
3299+#ifdef CONFIG_PAX_KERNEXEC
3300+ . = ALIGN(1<<SECTION_SHIFT);
3301+#endif
3302+
3303 __data_loc = .;
3304 #endif
3305
3306diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3307index 9e193c8..3560fe6 100644
3308--- a/arch/arm/kvm/arm.c
3309+++ b/arch/arm/kvm/arm.c
3310@@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
3311 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3312
3313 /* The VMID used in the VTTBR */
3314-static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3315+static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3316 static u8 kvm_next_vmid;
3317 static DEFINE_SPINLOCK(kvm_vmid_lock);
3318
3319@@ -354,7 +354,7 @@ void force_vm_exit(const cpumask_t *mask)
3320 */
3321 static bool need_new_vmid_gen(struct kvm *kvm)
3322 {
3323- return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3324+ return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3325 }
3326
3327 /**
3328@@ -387,7 +387,7 @@ static void update_vttbr(struct kvm *kvm)
3329
3330 /* First user of a new VMID generation? */
3331 if (unlikely(kvm_next_vmid == 0)) {
3332- atomic64_inc(&kvm_vmid_gen);
3333+ atomic64_inc_unchecked(&kvm_vmid_gen);
3334 kvm_next_vmid = 1;
3335
3336 /*
3337@@ -404,7 +404,7 @@ static void update_vttbr(struct kvm *kvm)
3338 kvm_call_hyp(__kvm_flush_vm_context);
3339 }
3340
3341- kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3342+ kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3343 kvm->arch.vmid = kvm_next_vmid;
3344 kvm_next_vmid++;
3345
3346@@ -980,7 +980,7 @@ static void check_kvm_target_cpu(void *ret)
3347 /**
3348 * Initialize Hyp-mode and memory mappings on all CPUs.
3349 */
3350-int kvm_arch_init(void *opaque)
3351+int kvm_arch_init(const void *opaque)
3352 {
3353 int err;
3354 int ret, cpu;
3355diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3356index 14a0d98..7771a7d 100644
3357--- a/arch/arm/lib/clear_user.S
3358+++ b/arch/arm/lib/clear_user.S
3359@@ -12,14 +12,14 @@
3360
3361 .text
3362
3363-/* Prototype: int __clear_user(void *addr, size_t sz)
3364+/* Prototype: int ___clear_user(void *addr, size_t sz)
3365 * Purpose : clear some user memory
3366 * Params : addr - user memory address to clear
3367 * : sz - number of bytes to clear
3368 * Returns : number of bytes NOT cleared
3369 */
3370 ENTRY(__clear_user_std)
3371-WEAK(__clear_user)
3372+WEAK(___clear_user)
3373 stmfd sp!, {r1, lr}
3374 mov r2, #0
3375 cmp r1, #4
3376@@ -44,7 +44,7 @@ WEAK(__clear_user)
3377 USER( strnebt r2, [r0])
3378 mov r0, #0
3379 ldmfd sp!, {r1, pc}
3380-ENDPROC(__clear_user)
3381+ENDPROC(___clear_user)
3382 ENDPROC(__clear_user_std)
3383
3384 .pushsection .fixup,"ax"
3385diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3386index 66a477a..bee61d3 100644
3387--- a/arch/arm/lib/copy_from_user.S
3388+++ b/arch/arm/lib/copy_from_user.S
3389@@ -16,7 +16,7 @@
3390 /*
3391 * Prototype:
3392 *
3393- * size_t __copy_from_user(void *to, const void *from, size_t n)
3394+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3395 *
3396 * Purpose:
3397 *
3398@@ -84,11 +84,11 @@
3399
3400 .text
3401
3402-ENTRY(__copy_from_user)
3403+ENTRY(___copy_from_user)
3404
3405 #include "copy_template.S"
3406
3407-ENDPROC(__copy_from_user)
3408+ENDPROC(___copy_from_user)
3409
3410 .pushsection .fixup,"ax"
3411 .align 0
3412diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3413index 6ee2f67..d1cce76 100644
3414--- a/arch/arm/lib/copy_page.S
3415+++ b/arch/arm/lib/copy_page.S
3416@@ -10,6 +10,7 @@
3417 * ASM optimised string functions
3418 */
3419 #include <linux/linkage.h>
3420+#include <linux/const.h>
3421 #include <asm/assembler.h>
3422 #include <asm/asm-offsets.h>
3423 #include <asm/cache.h>
3424diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3425index d066df6..df28194 100644
3426--- a/arch/arm/lib/copy_to_user.S
3427+++ b/arch/arm/lib/copy_to_user.S
3428@@ -16,7 +16,7 @@
3429 /*
3430 * Prototype:
3431 *
3432- * size_t __copy_to_user(void *to, const void *from, size_t n)
3433+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3434 *
3435 * Purpose:
3436 *
3437@@ -88,11 +88,11 @@
3438 .text
3439
3440 ENTRY(__copy_to_user_std)
3441-WEAK(__copy_to_user)
3442+WEAK(___copy_to_user)
3443
3444 #include "copy_template.S"
3445
3446-ENDPROC(__copy_to_user)
3447+ENDPROC(___copy_to_user)
3448 ENDPROC(__copy_to_user_std)
3449
3450 .pushsection .fixup,"ax"
3451diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3452index 7d08b43..f7ca7ea 100644
3453--- a/arch/arm/lib/csumpartialcopyuser.S
3454+++ b/arch/arm/lib/csumpartialcopyuser.S
3455@@ -57,8 +57,8 @@
3456 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3457 */
3458
3459-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3460-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3461+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3462+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3463
3464 #include "csumpartialcopygeneric.S"
3465
3466diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3467index 312d43e..21d2322 100644
3468--- a/arch/arm/lib/delay.c
3469+++ b/arch/arm/lib/delay.c
3470@@ -29,7 +29,7 @@
3471 /*
3472 * Default to the loop-based delay implementation.
3473 */
3474-struct arm_delay_ops arm_delay_ops = {
3475+struct arm_delay_ops arm_delay_ops __read_only = {
3476 .delay = __loop_delay,
3477 .const_udelay = __loop_const_udelay,
3478 .udelay = __loop_udelay,
3479diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3480index 3e58d71..029817c 100644
3481--- a/arch/arm/lib/uaccess_with_memcpy.c
3482+++ b/arch/arm/lib/uaccess_with_memcpy.c
3483@@ -136,7 +136,7 @@ out:
3484 }
3485
3486 unsigned long
3487-__copy_to_user(void __user *to, const void *from, unsigned long n)
3488+___copy_to_user(void __user *to, const void *from, unsigned long n)
3489 {
3490 /*
3491 * This test is stubbed out of the main function above to keep
3492@@ -190,7 +190,7 @@ out:
3493 return n;
3494 }
3495
3496-unsigned long __clear_user(void __user *addr, unsigned long n)
3497+unsigned long ___clear_user(void __user *addr, unsigned long n)
3498 {
3499 /* See rational for this in __copy_to_user() above. */
3500 if (n < 64)
3501diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
3502index 9610792..4dfb851 100644
3503--- a/arch/arm/mach-at91/setup.c
3504+++ b/arch/arm/mach-at91/setup.c
3505@@ -83,7 +83,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
3506
3507 desc->pfn = __phys_to_pfn(base);
3508 desc->length = length;
3509- desc->type = MT_MEMORY_RWX_NONCACHED;
3510+ desc->type = MT_MEMORY_RW_NONCACHED;
3511
3512 pr_info("sram at 0x%lx of 0x%x mapped at 0x%lx\n",
3513 base, length, desc->virtual);
3514diff --git a/arch/arm/mach-keystone/keystone.c b/arch/arm/mach-keystone/keystone.c
3515index 7f352de..6dc0929 100644
3516--- a/arch/arm/mach-keystone/keystone.c
3517+++ b/arch/arm/mach-keystone/keystone.c
3518@@ -27,7 +27,7 @@
3519
3520 #include "keystone.h"
3521
3522-static struct notifier_block platform_nb;
3523+static notifier_block_no_const platform_nb;
3524 static unsigned long keystone_dma_pfn_offset __read_mostly;
3525
3526 static int keystone_platform_notifier(struct notifier_block *nb,
3527diff --git a/arch/arm/mach-mvebu/coherency.c b/arch/arm/mach-mvebu/coherency.c
3528index 044b511..afd1da8 100644
3529--- a/arch/arm/mach-mvebu/coherency.c
3530+++ b/arch/arm/mach-mvebu/coherency.c
3531@@ -316,7 +316,7 @@ static void __init armada_370_coherency_init(struct device_node *np)
3532
3533 /*
3534 * This ioremap hook is used on Armada 375/38x to ensure that PCIe
3535- * memory areas are mapped as MT_UNCACHED instead of MT_DEVICE. This
3536+ * memory areas are mapped as MT_UNCACHED_RW instead of MT_DEVICE. This
3537 * is needed as a workaround for a deadlock issue between the PCIe
3538 * interface and the cache controller.
3539 */
3540@@ -329,7 +329,7 @@ armada_pcie_wa_ioremap_caller(phys_addr_t phys_addr, size_t size,
3541 mvebu_mbus_get_pcie_mem_aperture(&pcie_mem);
3542
3543 if (pcie_mem.start <= phys_addr && (phys_addr + size) <= pcie_mem.end)
3544- mtype = MT_UNCACHED;
3545+ mtype = MT_UNCACHED_RW;
3546
3547 return __arm_ioremap_caller(phys_addr, size, mtype, caller);
3548 }
3549diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3550index 97767a2..9233746 100644
3551--- a/arch/arm/mach-omap2/board-n8x0.c
3552+++ b/arch/arm/mach-omap2/board-n8x0.c
3553@@ -569,7 +569,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3554 }
3555 #endif
3556
3557-struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3558+struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3559 .late_init = n8x0_menelaus_late_init,
3560 };
3561
3562diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3563index 5fa3755..1e8c247 100644
3564--- a/arch/arm/mach-omap2/gpmc.c
3565+++ b/arch/arm/mach-omap2/gpmc.c
3566@@ -151,7 +151,6 @@ struct omap3_gpmc_regs {
3567 };
3568
3569 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3570-static struct irq_chip gpmc_irq_chip;
3571 static int gpmc_irq_start;
3572
3573 static struct resource gpmc_mem_root;
3574@@ -736,6 +735,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3575
3576 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3577
3578+static struct irq_chip gpmc_irq_chip = {
3579+ .name = "gpmc",
3580+ .irq_startup = gpmc_irq_noop_ret,
3581+ .irq_enable = gpmc_irq_enable,
3582+ .irq_disable = gpmc_irq_disable,
3583+ .irq_shutdown = gpmc_irq_noop,
3584+ .irq_ack = gpmc_irq_noop,
3585+ .irq_mask = gpmc_irq_noop,
3586+ .irq_unmask = gpmc_irq_noop,
3587+
3588+};
3589+
3590 static int gpmc_setup_irq(void)
3591 {
3592 int i;
3593@@ -750,15 +761,6 @@ static int gpmc_setup_irq(void)
3594 return gpmc_irq_start;
3595 }
3596
3597- gpmc_irq_chip.name = "gpmc";
3598- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3599- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3600- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3601- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3602- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3603- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3604- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3605-
3606 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3607 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3608
3609diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3610index 6944ae3..bc587ca 100644
3611--- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3612+++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3613@@ -86,7 +86,7 @@ struct cpu_pm_ops {
3614 void (*resume)(void);
3615 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3616 void (*hotplug_restart)(void);
3617-};
3618+} __no_const;
3619
3620 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3621 static struct powerdomain *mpuss_pd;
3622@@ -105,7 +105,7 @@ static void dummy_cpu_resume(void)
3623 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3624 {}
3625
3626-struct cpu_pm_ops omap_pm_ops = {
3627+static struct cpu_pm_ops omap_pm_ops __read_only = {
3628 .finish_suspend = default_finish_suspend,
3629 .resume = dummy_cpu_resume,
3630 .scu_prepare = dummy_scu_prepare,
3631diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3632index f961c46..4a453dc 100644
3633--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3634+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3635@@ -344,7 +344,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3636 return NOTIFY_OK;
3637 }
3638
3639-static struct notifier_block __refdata irq_hotplug_notifier = {
3640+static struct notifier_block irq_hotplug_notifier = {
3641 .notifier_call = irq_cpu_hotplug_notify,
3642 };
3643
3644diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3645index 8c58b71..95b655f 100644
3646--- a/arch/arm/mach-omap2/omap_device.c
3647+++ b/arch/arm/mach-omap2/omap_device.c
3648@@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
3649 struct platform_device __init *omap_device_build(const char *pdev_name,
3650 int pdev_id,
3651 struct omap_hwmod *oh,
3652- void *pdata, int pdata_len)
3653+ const void *pdata, int pdata_len)
3654 {
3655 struct omap_hwmod *ohs[] = { oh };
3656
3657@@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3658 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3659 int pdev_id,
3660 struct omap_hwmod **ohs,
3661- int oh_cnt, void *pdata,
3662+ int oh_cnt, const void *pdata,
3663 int pdata_len)
3664 {
3665 int ret = -ENOMEM;
3666diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3667index 78c02b3..c94109a 100644
3668--- a/arch/arm/mach-omap2/omap_device.h
3669+++ b/arch/arm/mach-omap2/omap_device.h
3670@@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3671 /* Core code interface */
3672
3673 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3674- struct omap_hwmod *oh, void *pdata,
3675+ struct omap_hwmod *oh, const void *pdata,
3676 int pdata_len);
3677
3678 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3679 struct omap_hwmod **oh, int oh_cnt,
3680- void *pdata, int pdata_len);
3681+ const void *pdata, int pdata_len);
3682
3683 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3684 struct omap_hwmod **ohs, int oh_cnt);
3685diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3686index 716247e..8df346d 100644
3687--- a/arch/arm/mach-omap2/omap_hwmod.c
3688+++ b/arch/arm/mach-omap2/omap_hwmod.c
3689@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3690 int (*init_clkdm)(struct omap_hwmod *oh);
3691 void (*update_context_lost)(struct omap_hwmod *oh);
3692 int (*get_context_lost)(struct omap_hwmod *oh);
3693-};
3694+} __no_const;
3695
3696 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3697-static struct omap_hwmod_soc_ops soc_ops;
3698+static struct omap_hwmod_soc_ops soc_ops __read_only;
3699
3700 /* omap_hwmod_list contains all registered struct omap_hwmods */
3701 static LIST_HEAD(omap_hwmod_list);
3702diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3703index 95fee54..cfa9cf1 100644
3704--- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3705+++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3706@@ -10,6 +10,7 @@
3707
3708 #include <linux/kernel.h>
3709 #include <linux/init.h>
3710+#include <asm/pgtable.h>
3711
3712 #include "powerdomain.h"
3713
3714@@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3715
3716 void __init am43xx_powerdomains_init(void)
3717 {
3718- omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3719+ pax_open_kernel();
3720+ *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3721+ pax_close_kernel();
3722 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3723 pwrdm_register_pwrdms(powerdomains_am43xx);
3724 pwrdm_complete_init();
3725diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3726index ff0a68c..b312aa0 100644
3727--- a/arch/arm/mach-omap2/wd_timer.c
3728+++ b/arch/arm/mach-omap2/wd_timer.c
3729@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3730 struct omap_hwmod *oh;
3731 char *oh_name = "wd_timer2";
3732 char *dev_name = "omap_wdt";
3733- struct omap_wd_timer_platform_data pdata;
3734+ static struct omap_wd_timer_platform_data pdata = {
3735+ .read_reset_sources = prm_read_reset_sources
3736+ };
3737
3738 if (!cpu_class_is_omap2() || of_have_populated_dt())
3739 return 0;
3740@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3741 return -EINVAL;
3742 }
3743
3744- pdata.read_reset_sources = prm_read_reset_sources;
3745-
3746 pdev = omap_device_build(dev_name, id, oh, &pdata,
3747 sizeof(struct omap_wd_timer_platform_data));
3748 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3749diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3750index b30bf5c..d0825bf 100644
3751--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3752+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3753@@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3754 bool entered_lp2 = false;
3755
3756 if (tegra_pending_sgi())
3757- ACCESS_ONCE(abort_flag) = true;
3758+ ACCESS_ONCE_RW(abort_flag) = true;
3759
3760 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3761
3762diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3763index 2dea8b5..6499da2 100644
3764--- a/arch/arm/mach-ux500/setup.h
3765+++ b/arch/arm/mach-ux500/setup.h
3766@@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
3767 .type = MT_DEVICE, \
3768 }
3769
3770-#define __MEM_DEV_DESC(x, sz) { \
3771- .virtual = IO_ADDRESS(x), \
3772- .pfn = __phys_to_pfn(x), \
3773- .length = sz, \
3774- .type = MT_MEMORY_RWX, \
3775-}
3776-
3777 extern struct smp_operations ux500_smp_ops;
3778 extern void ux500_cpu_die(unsigned int cpu);
3779
3780diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3781index 7eb94e6..799ad3e 100644
3782--- a/arch/arm/mm/Kconfig
3783+++ b/arch/arm/mm/Kconfig
3784@@ -446,6 +446,7 @@ config CPU_32v5
3785
3786 config CPU_32v6
3787 bool
3788+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3789 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3790
3791 config CPU_32v6K
3792@@ -600,6 +601,7 @@ config CPU_CP15_MPU
3793
3794 config CPU_USE_DOMAINS
3795 bool
3796+ depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3797 help
3798 This option enables or disables the use of domain switching
3799 via the set_fs() function.
3800@@ -798,7 +800,7 @@ config NEED_KUSER_HELPERS
3801
3802 config KUSER_HELPERS
3803 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3804- depends on MMU
3805+ depends on MMU && (!(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND)
3806 default y
3807 help
3808 Warning: disabling this option may break user programs.
3809@@ -812,7 +814,7 @@ config KUSER_HELPERS
3810 See Documentation/arm/kernel_user_helpers.txt for details.
3811
3812 However, the fixed address nature of these helpers can be used
3813- by ROP (return orientated programming) authors when creating
3814+ by ROP (Return Oriented Programming) authors when creating
3815 exploits.
3816
3817 If all of the binaries and libraries which run on your platform
3818diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3819index 83792f4..c25d36b 100644
3820--- a/arch/arm/mm/alignment.c
3821+++ b/arch/arm/mm/alignment.c
3822@@ -216,10 +216,12 @@ union offset_union {
3823 #define __get16_unaligned_check(ins,val,addr) \
3824 do { \
3825 unsigned int err = 0, v, a = addr; \
3826+ pax_open_userland(); \
3827 __get8_unaligned_check(ins,v,a,err); \
3828 val = v << ((BE) ? 8 : 0); \
3829 __get8_unaligned_check(ins,v,a,err); \
3830 val |= v << ((BE) ? 0 : 8); \
3831+ pax_close_userland(); \
3832 if (err) \
3833 goto fault; \
3834 } while (0)
3835@@ -233,6 +235,7 @@ union offset_union {
3836 #define __get32_unaligned_check(ins,val,addr) \
3837 do { \
3838 unsigned int err = 0, v, a = addr; \
3839+ pax_open_userland(); \
3840 __get8_unaligned_check(ins,v,a,err); \
3841 val = v << ((BE) ? 24 : 0); \
3842 __get8_unaligned_check(ins,v,a,err); \
3843@@ -241,6 +244,7 @@ union offset_union {
3844 val |= v << ((BE) ? 8 : 16); \
3845 __get8_unaligned_check(ins,v,a,err); \
3846 val |= v << ((BE) ? 0 : 24); \
3847+ pax_close_userland(); \
3848 if (err) \
3849 goto fault; \
3850 } while (0)
3851@@ -254,6 +258,7 @@ union offset_union {
3852 #define __put16_unaligned_check(ins,val,addr) \
3853 do { \
3854 unsigned int err = 0, v = val, a = addr; \
3855+ pax_open_userland(); \
3856 __asm__( FIRST_BYTE_16 \
3857 ARM( "1: "ins" %1, [%2], #1\n" ) \
3858 THUMB( "1: "ins" %1, [%2]\n" ) \
3859@@ -273,6 +278,7 @@ union offset_union {
3860 " .popsection\n" \
3861 : "=r" (err), "=&r" (v), "=&r" (a) \
3862 : "0" (err), "1" (v), "2" (a)); \
3863+ pax_close_userland(); \
3864 if (err) \
3865 goto fault; \
3866 } while (0)
3867@@ -286,6 +292,7 @@ union offset_union {
3868 #define __put32_unaligned_check(ins,val,addr) \
3869 do { \
3870 unsigned int err = 0, v = val, a = addr; \
3871+ pax_open_userland(); \
3872 __asm__( FIRST_BYTE_32 \
3873 ARM( "1: "ins" %1, [%2], #1\n" ) \
3874 THUMB( "1: "ins" %1, [%2]\n" ) \
3875@@ -315,6 +322,7 @@ union offset_union {
3876 " .popsection\n" \
3877 : "=r" (err), "=&r" (v), "=&r" (a) \
3878 : "0" (err), "1" (v), "2" (a)); \
3879+ pax_close_userland(); \
3880 if (err) \
3881 goto fault; \
3882 } while (0)
3883diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3884index 5e65ca8..879e7b3 100644
3885--- a/arch/arm/mm/cache-l2x0.c
3886+++ b/arch/arm/mm/cache-l2x0.c
3887@@ -42,7 +42,7 @@ struct l2c_init_data {
3888 void (*fixup)(void __iomem *, u32, struct outer_cache_fns *);
3889 void (*save)(void __iomem *);
3890 struct outer_cache_fns outer_cache;
3891-};
3892+} __do_const;
3893
3894 #define CACHE_LINE_SIZE 32
3895
3896diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3897index 6eb97b3..ac509f6 100644
3898--- a/arch/arm/mm/context.c
3899+++ b/arch/arm/mm/context.c
3900@@ -43,7 +43,7 @@
3901 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3902
3903 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3904-static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3905+static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3906 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3907
3908 static DEFINE_PER_CPU(atomic64_t, active_asids);
3909@@ -182,7 +182,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3910 {
3911 static u32 cur_idx = 1;
3912 u64 asid = atomic64_read(&mm->context.id);
3913- u64 generation = atomic64_read(&asid_generation);
3914+ u64 generation = atomic64_read_unchecked(&asid_generation);
3915
3916 if (asid != 0 && is_reserved_asid(asid)) {
3917 /*
3918@@ -203,7 +203,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3919 */
3920 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
3921 if (asid == NUM_USER_ASIDS) {
3922- generation = atomic64_add_return(ASID_FIRST_VERSION,
3923+ generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3924 &asid_generation);
3925 flush_context(cpu);
3926 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3927@@ -234,14 +234,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3928 cpu_set_reserved_ttbr0();
3929
3930 asid = atomic64_read(&mm->context.id);
3931- if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3932+ if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3933 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3934 goto switch_mm_fastpath;
3935
3936 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3937 /* Check that our ASID belongs to the current generation. */
3938 asid = atomic64_read(&mm->context.id);
3939- if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3940+ if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3941 asid = new_context(mm, cpu);
3942 atomic64_set(&mm->context.id, asid);
3943 }
3944diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3945index eb8830a..e8ff52e 100644
3946--- a/arch/arm/mm/fault.c
3947+++ b/arch/arm/mm/fault.c
3948@@ -25,6 +25,7 @@
3949 #include <asm/system_misc.h>
3950 #include <asm/system_info.h>
3951 #include <asm/tlbflush.h>
3952+#include <asm/sections.h>
3953
3954 #include "fault.h"
3955
3956@@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3957 if (fixup_exception(regs))
3958 return;
3959
3960+#ifdef CONFIG_PAX_MEMORY_UDEREF
3961+ if (addr < TASK_SIZE) {
3962+ if (current->signal->curr_ip)
3963+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3964+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3965+ else
3966+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3967+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3968+ }
3969+#endif
3970+
3971+#ifdef CONFIG_PAX_KERNEXEC
3972+ if ((fsr & FSR_WRITE) &&
3973+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3974+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3975+ {
3976+ if (current->signal->curr_ip)
3977+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3978+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3979+ else
3980+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3981+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3982+ }
3983+#endif
3984+
3985 /*
3986 * No handler, we'll have to terminate things with extreme prejudice.
3987 */
3988@@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3989 }
3990 #endif
3991
3992+#ifdef CONFIG_PAX_PAGEEXEC
3993+ if (fsr & FSR_LNX_PF) {
3994+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3995+ do_group_exit(SIGKILL);
3996+ }
3997+#endif
3998+
3999 tsk->thread.address = addr;
4000 tsk->thread.error_code = fsr;
4001 tsk->thread.trap_no = 14;
4002@@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4003 }
4004 #endif /* CONFIG_MMU */
4005
4006+#ifdef CONFIG_PAX_PAGEEXEC
4007+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4008+{
4009+ long i;
4010+
4011+ printk(KERN_ERR "PAX: bytes at PC: ");
4012+ for (i = 0; i < 20; i++) {
4013+ unsigned char c;
4014+ if (get_user(c, (__force unsigned char __user *)pc+i))
4015+ printk(KERN_CONT "?? ");
4016+ else
4017+ printk(KERN_CONT "%02x ", c);
4018+ }
4019+ printk("\n");
4020+
4021+ printk(KERN_ERR "PAX: bytes at SP-4: ");
4022+ for (i = -1; i < 20; i++) {
4023+ unsigned long c;
4024+ if (get_user(c, (__force unsigned long __user *)sp+i))
4025+ printk(KERN_CONT "???????? ");
4026+ else
4027+ printk(KERN_CONT "%08lx ", c);
4028+ }
4029+ printk("\n");
4030+}
4031+#endif
4032+
4033 /*
4034 * First Level Translation Fault Handler
4035 *
4036@@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4037 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
4038 struct siginfo info;
4039
4040+#ifdef CONFIG_PAX_MEMORY_UDEREF
4041+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
4042+ if (current->signal->curr_ip)
4043+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4044+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4045+ else
4046+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4047+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4048+ goto die;
4049+ }
4050+#endif
4051+
4052 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
4053 return;
4054
4055+die:
4056 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
4057 inf->name, fsr, addr);
4058
4059@@ -574,15 +647,104 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
4060 ifsr_info[nr].name = name;
4061 }
4062
4063+asmlinkage int sys_sigreturn(struct pt_regs *regs);
4064+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
4065+
4066 asmlinkage void __exception
4067 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
4068 {
4069 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
4070 struct siginfo info;
4071+ unsigned long pc = instruction_pointer(regs);
4072+
4073+ if (user_mode(regs)) {
4074+ unsigned long sigpage = current->mm->context.sigpage;
4075+
4076+ if (sigpage <= pc && pc < sigpage + 7*4) {
4077+ if (pc < sigpage + 3*4)
4078+ sys_sigreturn(regs);
4079+ else
4080+ sys_rt_sigreturn(regs);
4081+ return;
4082+ }
4083+ if (pc == 0xffff0f60UL) {
4084+ /*
4085+ * PaX: __kuser_cmpxchg64 emulation
4086+ */
4087+ // TODO
4088+ //regs->ARM_pc = regs->ARM_lr;
4089+ //return;
4090+ }
4091+ if (pc == 0xffff0fa0UL) {
4092+ /*
4093+ * PaX: __kuser_memory_barrier emulation
4094+ */
4095+ // dmb(); implied by the exception
4096+ regs->ARM_pc = regs->ARM_lr;
4097+ return;
4098+ }
4099+ if (pc == 0xffff0fc0UL) {
4100+ /*
4101+ * PaX: __kuser_cmpxchg emulation
4102+ */
4103+ // TODO
4104+ //long new;
4105+ //int op;
4106+
4107+ //op = FUTEX_OP_SET << 28;
4108+ //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4109+ //regs->ARM_r0 = old != new;
4110+ //regs->ARM_pc = regs->ARM_lr;
4111+ //return;
4112+ }
4113+ if (pc == 0xffff0fe0UL) {
4114+ /*
4115+ * PaX: __kuser_get_tls emulation
4116+ */
4117+ regs->ARM_r0 = current_thread_info()->tp_value[0];
4118+ regs->ARM_pc = regs->ARM_lr;
4119+ return;
4120+ }
4121+ }
4122+
4123+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4124+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4125+ if (current->signal->curr_ip)
4126+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4127+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4128+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4129+ else
4130+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4131+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4132+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4133+ goto die;
4134+ }
4135+#endif
4136+
4137+#ifdef CONFIG_PAX_REFCOUNT
4138+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4139+#ifdef CONFIG_THUMB2_KERNEL
4140+ unsigned short bkpt;
4141+
4142+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le16(bkpt) == 0xbef1) {
4143+#else
4144+ unsigned int bkpt;
4145+
4146+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4147+#endif
4148+ current->thread.error_code = ifsr;
4149+ current->thread.trap_no = 0;
4150+ pax_report_refcount_overflow(regs);
4151+ fixup_exception(regs);
4152+ return;
4153+ }
4154+ }
4155+#endif
4156
4157 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4158 return;
4159
4160+die:
4161 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4162 inf->name, ifsr, addr);
4163
4164diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4165index cf08bdf..772656c 100644
4166--- a/arch/arm/mm/fault.h
4167+++ b/arch/arm/mm/fault.h
4168@@ -3,6 +3,7 @@
4169
4170 /*
4171 * Fault status register encodings. We steal bit 31 for our own purposes.
4172+ * Set when the FSR value is from an instruction fault.
4173 */
4174 #define FSR_LNX_PF (1 << 31)
4175 #define FSR_WRITE (1 << 11)
4176@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4177 }
4178 #endif
4179
4180+/* valid for LPAE and !LPAE */
4181+static inline int is_xn_fault(unsigned int fsr)
4182+{
4183+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
4184+}
4185+
4186+static inline int is_domain_fault(unsigned int fsr)
4187+{
4188+ return ((fsr_fs(fsr) & 0xD) == 0x9);
4189+}
4190+
4191 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4192 unsigned long search_exception_table(unsigned long addr);
4193
4194diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4195index 9481f85..6dae261 100644
4196--- a/arch/arm/mm/init.c
4197+++ b/arch/arm/mm/init.c
4198@@ -31,6 +31,8 @@
4199 #include <asm/setup.h>
4200 #include <asm/tlb.h>
4201 #include <asm/fixmap.h>
4202+#include <asm/system_info.h>
4203+#include <asm/cp15.h>
4204
4205 #include <asm/mach/arch.h>
4206 #include <asm/mach/map.h>
4207@@ -619,7 +621,46 @@ void free_initmem(void)
4208 {
4209 #ifdef CONFIG_HAVE_TCM
4210 extern char __tcm_start, __tcm_end;
4211+#endif
4212
4213+#ifdef CONFIG_PAX_KERNEXEC
4214+ unsigned long addr;
4215+ pgd_t *pgd;
4216+ pud_t *pud;
4217+ pmd_t *pmd;
4218+ int cpu_arch = cpu_architecture();
4219+ unsigned int cr = get_cr();
4220+
4221+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4222+ /* make pages tables, etc before .text NX */
4223+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4224+ pgd = pgd_offset_k(addr);
4225+ pud = pud_offset(pgd, addr);
4226+ pmd = pmd_offset(pud, addr);
4227+ __section_update(pmd, addr, PMD_SECT_XN);
4228+ }
4229+ /* make init NX */
4230+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4231+ pgd = pgd_offset_k(addr);
4232+ pud = pud_offset(pgd, addr);
4233+ pmd = pmd_offset(pud, addr);
4234+ __section_update(pmd, addr, PMD_SECT_XN);
4235+ }
4236+ /* make kernel code/rodata RX */
4237+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4238+ pgd = pgd_offset_k(addr);
4239+ pud = pud_offset(pgd, addr);
4240+ pmd = pmd_offset(pud, addr);
4241+#ifdef CONFIG_ARM_LPAE
4242+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4243+#else
4244+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4245+#endif
4246+ }
4247+ }
4248+#endif
4249+
4250+#ifdef CONFIG_HAVE_TCM
4251 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4252 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4253 #endif
4254diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4255index d1e5ad7..84dcbf2 100644
4256--- a/arch/arm/mm/ioremap.c
4257+++ b/arch/arm/mm/ioremap.c
4258@@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4259 unsigned int mtype;
4260
4261 if (cached)
4262- mtype = MT_MEMORY_RWX;
4263+ mtype = MT_MEMORY_RX;
4264 else
4265- mtype = MT_MEMORY_RWX_NONCACHED;
4266+ mtype = MT_MEMORY_RX_NONCACHED;
4267
4268 return __arm_ioremap_caller(phys_addr, size, mtype,
4269 __builtin_return_address(0));
4270diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4271index 5e85ed3..b10a7ed 100644
4272--- a/arch/arm/mm/mmap.c
4273+++ b/arch/arm/mm/mmap.c
4274@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4275 struct vm_area_struct *vma;
4276 int do_align = 0;
4277 int aliasing = cache_is_vipt_aliasing();
4278+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4279 struct vm_unmapped_area_info info;
4280
4281 /*
4282@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4283 if (len > TASK_SIZE)
4284 return -ENOMEM;
4285
4286+#ifdef CONFIG_PAX_RANDMMAP
4287+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4288+#endif
4289+
4290 if (addr) {
4291 if (do_align)
4292 addr = COLOUR_ALIGN(addr, pgoff);
4293@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4294 addr = PAGE_ALIGN(addr);
4295
4296 vma = find_vma(mm, addr);
4297- if (TASK_SIZE - len >= addr &&
4298- (!vma || addr + len <= vma->vm_start))
4299+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4300 return addr;
4301 }
4302
4303@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4304 info.high_limit = TASK_SIZE;
4305 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4306 info.align_offset = pgoff << PAGE_SHIFT;
4307+ info.threadstack_offset = offset;
4308 return vm_unmapped_area(&info);
4309 }
4310
4311@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4312 unsigned long addr = addr0;
4313 int do_align = 0;
4314 int aliasing = cache_is_vipt_aliasing();
4315+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4316 struct vm_unmapped_area_info info;
4317
4318 /*
4319@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4320 return addr;
4321 }
4322
4323+#ifdef CONFIG_PAX_RANDMMAP
4324+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4325+#endif
4326+
4327 /* requesting a specific address */
4328 if (addr) {
4329 if (do_align)
4330@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4331 else
4332 addr = PAGE_ALIGN(addr);
4333 vma = find_vma(mm, addr);
4334- if (TASK_SIZE - len >= addr &&
4335- (!vma || addr + len <= vma->vm_start))
4336+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4337 return addr;
4338 }
4339
4340@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4341 info.high_limit = mm->mmap_base;
4342 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4343 info.align_offset = pgoff << PAGE_SHIFT;
4344+ info.threadstack_offset = offset;
4345 addr = vm_unmapped_area(&info);
4346
4347 /*
4348@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4349 {
4350 unsigned long random_factor = 0UL;
4351
4352+#ifdef CONFIG_PAX_RANDMMAP
4353+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4354+#endif
4355+
4356 /* 8 bits of randomness in 20 address space bits */
4357 if ((current->flags & PF_RANDOMIZE) &&
4358 !(current->personality & ADDR_NO_RANDOMIZE))
4359@@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4360
4361 if (mmap_is_legacy()) {
4362 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4363+
4364+#ifdef CONFIG_PAX_RANDMMAP
4365+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4366+ mm->mmap_base += mm->delta_mmap;
4367+#endif
4368+
4369 mm->get_unmapped_area = arch_get_unmapped_area;
4370 } else {
4371 mm->mmap_base = mmap_base(random_factor);
4372+
4373+#ifdef CONFIG_PAX_RANDMMAP
4374+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4375+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4376+#endif
4377+
4378 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4379 }
4380 }
4381diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4382index 9f98cec..115fcb6 100644
4383--- a/arch/arm/mm/mmu.c
4384+++ b/arch/arm/mm/mmu.c
4385@@ -40,6 +40,22 @@
4386 #include "mm.h"
4387 #include "tcm.h"
4388
4389+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4390+void modify_domain(unsigned int dom, unsigned int type)
4391+{
4392+ struct thread_info *thread = current_thread_info();
4393+ unsigned int domain = thread->cpu_domain;
4394+ /*
4395+ * DOMAIN_MANAGER might be defined to some other value,
4396+ * use the arch-defined constant
4397+ */
4398+ domain &= ~domain_val(dom, 3);
4399+ thread->cpu_domain = domain | domain_val(dom, type);
4400+ set_domain(thread->cpu_domain);
4401+}
4402+EXPORT_SYMBOL(modify_domain);
4403+#endif
4404+
4405 /*
4406 * empty_zero_page is a special page that is used for
4407 * zero-initialized data and COW.
4408@@ -239,7 +255,15 @@ __setup("noalign", noalign_setup);
4409 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4410 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4411
4412-static struct mem_type mem_types[] = {
4413+#ifdef CONFIG_PAX_KERNEXEC
4414+#define L_PTE_KERNEXEC L_PTE_RDONLY
4415+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4416+#else
4417+#define L_PTE_KERNEXEC L_PTE_DIRTY
4418+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4419+#endif
4420+
4421+static struct mem_type mem_types[] __read_only = {
4422 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4423 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4424 L_PTE_SHARED,
4425@@ -268,19 +292,19 @@ static struct mem_type mem_types[] = {
4426 .prot_sect = PROT_SECT_DEVICE,
4427 .domain = DOMAIN_IO,
4428 },
4429- [MT_UNCACHED] = {
4430+ [MT_UNCACHED_RW] = {
4431 .prot_pte = PROT_PTE_DEVICE,
4432 .prot_l1 = PMD_TYPE_TABLE,
4433 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4434 .domain = DOMAIN_IO,
4435 },
4436- [MT_CACHECLEAN] = {
4437- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4438+ [MT_CACHECLEAN_RO] = {
4439+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4440 .domain = DOMAIN_KERNEL,
4441 },
4442 #ifndef CONFIG_ARM_LPAE
4443- [MT_MINICLEAN] = {
4444- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4445+ [MT_MINICLEAN_RO] = {
4446+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4447 .domain = DOMAIN_KERNEL,
4448 },
4449 #endif
4450@@ -288,15 +312,15 @@ static struct mem_type mem_types[] = {
4451 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4452 L_PTE_RDONLY,
4453 .prot_l1 = PMD_TYPE_TABLE,
4454- .domain = DOMAIN_USER,
4455+ .domain = DOMAIN_VECTORS,
4456 },
4457 [MT_HIGH_VECTORS] = {
4458 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4459 L_PTE_USER | L_PTE_RDONLY,
4460 .prot_l1 = PMD_TYPE_TABLE,
4461- .domain = DOMAIN_USER,
4462+ .domain = DOMAIN_VECTORS,
4463 },
4464- [MT_MEMORY_RWX] = {
4465+ [__MT_MEMORY_RWX] = {
4466 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4467 .prot_l1 = PMD_TYPE_TABLE,
4468 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4469@@ -309,17 +333,30 @@ static struct mem_type mem_types[] = {
4470 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4471 .domain = DOMAIN_KERNEL,
4472 },
4473- [MT_ROM] = {
4474- .prot_sect = PMD_TYPE_SECT,
4475+ [MT_MEMORY_RX] = {
4476+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4477+ .prot_l1 = PMD_TYPE_TABLE,
4478+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4479+ .domain = DOMAIN_KERNEL,
4480+ },
4481+ [MT_ROM_RX] = {
4482+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4483 .domain = DOMAIN_KERNEL,
4484 },
4485- [MT_MEMORY_RWX_NONCACHED] = {
4486+ [MT_MEMORY_RW_NONCACHED] = {
4487 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4488 L_PTE_MT_BUFFERABLE,
4489 .prot_l1 = PMD_TYPE_TABLE,
4490 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4491 .domain = DOMAIN_KERNEL,
4492 },
4493+ [MT_MEMORY_RX_NONCACHED] = {
4494+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4495+ L_PTE_MT_BUFFERABLE,
4496+ .prot_l1 = PMD_TYPE_TABLE,
4497+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4498+ .domain = DOMAIN_KERNEL,
4499+ },
4500 [MT_MEMORY_RW_DTCM] = {
4501 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4502 L_PTE_XN,
4503@@ -327,9 +364,10 @@ static struct mem_type mem_types[] = {
4504 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4505 .domain = DOMAIN_KERNEL,
4506 },
4507- [MT_MEMORY_RWX_ITCM] = {
4508- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4509+ [MT_MEMORY_RX_ITCM] = {
4510+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4511 .prot_l1 = PMD_TYPE_TABLE,
4512+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4513 .domain = DOMAIN_KERNEL,
4514 },
4515 [MT_MEMORY_RW_SO] = {
4516@@ -547,9 +585,14 @@ static void __init build_mem_type_table(void)
4517 * Mark cache clean areas and XIP ROM read only
4518 * from SVC mode and no access from userspace.
4519 */
4520- mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4521- mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4522- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4523+ mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4524+#ifdef CONFIG_PAX_KERNEXEC
4525+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4526+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4527+ mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4528+#endif
4529+ mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4530+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4531 #endif
4532
4533 /*
4534@@ -566,13 +609,17 @@ static void __init build_mem_type_table(void)
4535 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4536 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4537 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4538- mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4539- mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4540+ mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4541+ mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4542 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4543 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4544+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4545+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4546 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4547- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
4548- mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
4549+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
4550+ mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
4551+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
4552+ mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
4553 }
4554 }
4555
4556@@ -583,15 +630,20 @@ static void __init build_mem_type_table(void)
4557 if (cpu_arch >= CPU_ARCH_ARMv6) {
4558 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4559 /* Non-cacheable Normal is XCB = 001 */
4560- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4561+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4562+ PMD_SECT_BUFFERED;
4563+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4564 PMD_SECT_BUFFERED;
4565 } else {
4566 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4567- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4568+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4569+ PMD_SECT_TEX(1);
4570+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4571 PMD_SECT_TEX(1);
4572 }
4573 } else {
4574- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4575+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4576+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4577 }
4578
4579 #ifdef CONFIG_ARM_LPAE
4580@@ -607,6 +659,8 @@ static void __init build_mem_type_table(void)
4581 vecs_pgprot |= PTE_EXT_AF;
4582 #endif
4583
4584+ user_pgprot |= __supported_pte_mask;
4585+
4586 for (i = 0; i < 16; i++) {
4587 pteval_t v = pgprot_val(protection_map[i]);
4588 protection_map[i] = __pgprot(v | user_pgprot);
4589@@ -624,21 +678,24 @@ static void __init build_mem_type_table(void)
4590
4591 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4592 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4593- mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4594- mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4595+ mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4596+ mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4597 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4598 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4599+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4600+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4601 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4602- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
4603- mem_types[MT_ROM].prot_sect |= cp->pmd;
4604+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
4605+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
4606+ mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
4607
4608 switch (cp->pmd) {
4609 case PMD_SECT_WT:
4610- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
4611+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
4612 break;
4613 case PMD_SECT_WB:
4614 case PMD_SECT_WBWA:
4615- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
4616+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
4617 break;
4618 }
4619 pr_info("Memory policy: %sData cache %s\n",
4620@@ -856,7 +913,7 @@ static void __init create_mapping(struct map_desc *md)
4621 return;
4622 }
4623
4624- if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
4625+ if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
4626 md->virtual >= PAGE_OFFSET &&
4627 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
4628 printk(KERN_WARNING "BUG: mapping for 0x%08llx"
4629@@ -1224,18 +1281,15 @@ void __init arm_mm_memblock_reserve(void)
4630 * called function. This means you can't use any function or debugging
4631 * method which may touch any device, otherwise the kernel _will_ crash.
4632 */
4633+
4634+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4635+
4636 static void __init devicemaps_init(const struct machine_desc *mdesc)
4637 {
4638 struct map_desc map;
4639 unsigned long addr;
4640- void *vectors;
4641
4642- /*
4643- * Allocate the vector page early.
4644- */
4645- vectors = early_alloc(PAGE_SIZE * 2);
4646-
4647- early_trap_init(vectors);
4648+ early_trap_init(&vectors);
4649
4650 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4651 pmd_clear(pmd_off_k(addr));
4652@@ -1248,7 +1302,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4653 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
4654 map.virtual = MODULES_VADDR;
4655 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
4656- map.type = MT_ROM;
4657+ map.type = MT_ROM_RX;
4658 create_mapping(&map);
4659 #endif
4660
4661@@ -1259,14 +1313,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4662 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
4663 map.virtual = FLUSH_BASE;
4664 map.length = SZ_1M;
4665- map.type = MT_CACHECLEAN;
4666+ map.type = MT_CACHECLEAN_RO;
4667 create_mapping(&map);
4668 #endif
4669 #ifdef FLUSH_BASE_MINICACHE
4670 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
4671 map.virtual = FLUSH_BASE_MINICACHE;
4672 map.length = SZ_1M;
4673- map.type = MT_MINICLEAN;
4674+ map.type = MT_MINICLEAN_RO;
4675 create_mapping(&map);
4676 #endif
4677
4678@@ -1275,7 +1329,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4679 * location (0xffff0000). If we aren't using high-vectors, also
4680 * create a mapping at the low-vectors virtual address.
4681 */
4682- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4683+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4684 map.virtual = 0xffff0000;
4685 map.length = PAGE_SIZE;
4686 #ifdef CONFIG_KUSER_HELPERS
4687@@ -1335,8 +1389,10 @@ static void __init kmap_init(void)
4688 static void __init map_lowmem(void)
4689 {
4690 struct memblock_region *reg;
4691+#ifndef CONFIG_PAX_KERNEXEC
4692 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
4693 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
4694+#endif
4695
4696 /* Map all the lowmem memory banks. */
4697 for_each_memblock(memory, reg) {
4698@@ -1349,11 +1405,48 @@ static void __init map_lowmem(void)
4699 if (start >= end)
4700 break;
4701
4702+#ifdef CONFIG_PAX_KERNEXEC
4703+ map.pfn = __phys_to_pfn(start);
4704+ map.virtual = __phys_to_virt(start);
4705+ map.length = end - start;
4706+
4707+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4708+ struct map_desc kernel;
4709+ struct map_desc initmap;
4710+
4711+ /* when freeing initmem we will make this RW */
4712+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4713+ initmap.virtual = (unsigned long)__init_begin;
4714+ initmap.length = _sdata - __init_begin;
4715+ initmap.type = __MT_MEMORY_RWX;
4716+ create_mapping(&initmap);
4717+
4718+ /* when freeing initmem we will make this RX */
4719+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4720+ kernel.virtual = (unsigned long)_stext;
4721+ kernel.length = __init_begin - _stext;
4722+ kernel.type = __MT_MEMORY_RWX;
4723+ create_mapping(&kernel);
4724+
4725+ if (map.virtual < (unsigned long)_stext) {
4726+ map.length = (unsigned long)_stext - map.virtual;
4727+ map.type = __MT_MEMORY_RWX;
4728+ create_mapping(&map);
4729+ }
4730+
4731+ map.pfn = __phys_to_pfn(__pa(_sdata));
4732+ map.virtual = (unsigned long)_sdata;
4733+ map.length = end - __pa(_sdata);
4734+ }
4735+
4736+ map.type = MT_MEMORY_RW;
4737+ create_mapping(&map);
4738+#else
4739 if (end < kernel_x_start || start >= kernel_x_end) {
4740 map.pfn = __phys_to_pfn(start);
4741 map.virtual = __phys_to_virt(start);
4742 map.length = end - start;
4743- map.type = MT_MEMORY_RWX;
4744+ map.type = __MT_MEMORY_RWX;
4745
4746 create_mapping(&map);
4747 } else {
4748@@ -1370,7 +1463,7 @@ static void __init map_lowmem(void)
4749 map.pfn = __phys_to_pfn(kernel_x_start);
4750 map.virtual = __phys_to_virt(kernel_x_start);
4751 map.length = kernel_x_end - kernel_x_start;
4752- map.type = MT_MEMORY_RWX;
4753+ map.type = __MT_MEMORY_RWX;
4754
4755 create_mapping(&map);
4756
4757@@ -1383,6 +1476,7 @@ static void __init map_lowmem(void)
4758 create_mapping(&map);
4759 }
4760 }
4761+#endif
4762 }
4763 }
4764
4765diff --git a/arch/arm/net/bpf_jit_32.c b/arch/arm/net/bpf_jit_32.c
4766index e1268f9..a9755a7 100644
4767--- a/arch/arm/net/bpf_jit_32.c
4768+++ b/arch/arm/net/bpf_jit_32.c
4769@@ -20,6 +20,7 @@
4770 #include <asm/cacheflush.h>
4771 #include <asm/hwcap.h>
4772 #include <asm/opcodes.h>
4773+#include <asm/pgtable.h>
4774
4775 #include "bpf_jit_32.h"
4776
4777@@ -71,7 +72,11 @@ struct jit_ctx {
4778 #endif
4779 };
4780
4781+#ifdef CONFIG_GRKERNSEC_BPF_HARDEN
4782+int bpf_jit_enable __read_only;
4783+#else
4784 int bpf_jit_enable __read_mostly;
4785+#endif
4786
4787 static u64 jit_get_skb_b(struct sk_buff *skb, unsigned offset)
4788 {
4789@@ -178,8 +183,10 @@ static void jit_fill_hole(void *area, unsigned int size)
4790 {
4791 u32 *ptr;
4792 /* We are guaranteed to have aligned memory. */
4793+ pax_open_kernel();
4794 for (ptr = area; size >= sizeof(u32); size -= sizeof(u32))
4795 *ptr++ = __opcode_to_mem_arm(ARM_INST_UDF);
4796+ pax_close_kernel();
4797 }
4798
4799 static void build_prologue(struct jit_ctx *ctx)
4800diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
4801index 5b217f4..c23f40e 100644
4802--- a/arch/arm/plat-iop/setup.c
4803+++ b/arch/arm/plat-iop/setup.c
4804@@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
4805 .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
4806 .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
4807 .length = IOP3XX_PERIPHERAL_SIZE,
4808- .type = MT_UNCACHED,
4809+ .type = MT_UNCACHED_RW,
4810 },
4811 };
4812
4813diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4814index a5bc92d..0bb4730 100644
4815--- a/arch/arm/plat-omap/sram.c
4816+++ b/arch/arm/plat-omap/sram.c
4817@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4818 * Looks like we need to preserve some bootloader code at the
4819 * beginning of SRAM for jumping to flash for reboot to work...
4820 */
4821+ pax_open_kernel();
4822 memset_io(omap_sram_base + omap_sram_skip, 0,
4823 omap_sram_size - omap_sram_skip);
4824+ pax_close_kernel();
4825 }
4826diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4827index ce6d763..cfea917 100644
4828--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4829+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4830@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4831 int (*started)(unsigned ch);
4832 int (*flush)(unsigned ch);
4833 int (*stop)(unsigned ch);
4834-};
4835+} __no_const;
4836
4837 extern void *samsung_dmadev_get_ops(void);
4838 extern void *s3c_dma_get_ops(void);
4839diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h
4840index 6389d60..b5d3bdd 100644
4841--- a/arch/arm64/include/asm/barrier.h
4842+++ b/arch/arm64/include/asm/barrier.h
4843@@ -41,7 +41,7 @@
4844 do { \
4845 compiletime_assert_atomic_type(*p); \
4846 barrier(); \
4847- ACCESS_ONCE(*p) = (v); \
4848+ ACCESS_ONCE_RW(*p) = (v); \
4849 } while (0)
4850
4851 #define smp_load_acquire(p) \
4852diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4853index 3bf8f4e..5dd5491 100644
4854--- a/arch/arm64/include/asm/uaccess.h
4855+++ b/arch/arm64/include/asm/uaccess.h
4856@@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4857 flag; \
4858 })
4859
4860+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4861 #define access_ok(type, addr, size) __range_ok(addr, size)
4862 #define user_addr_max get_fs
4863
4864diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4865index c3a58a1..78fbf54 100644
4866--- a/arch/avr32/include/asm/cache.h
4867+++ b/arch/avr32/include/asm/cache.h
4868@@ -1,8 +1,10 @@
4869 #ifndef __ASM_AVR32_CACHE_H
4870 #define __ASM_AVR32_CACHE_H
4871
4872+#include <linux/const.h>
4873+
4874 #define L1_CACHE_SHIFT 5
4875-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4876+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4877
4878 /*
4879 * Memory returned by kmalloc() may be used for DMA, so we must make
4880diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4881index d232888..87c8df1 100644
4882--- a/arch/avr32/include/asm/elf.h
4883+++ b/arch/avr32/include/asm/elf.h
4884@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4885 the loader. We need to make sure that it is out of the way of the program
4886 that it will "exec", and that there is sufficient room for the brk. */
4887
4888-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4889+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4890
4891+#ifdef CONFIG_PAX_ASLR
4892+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4893+
4894+#define PAX_DELTA_MMAP_LEN 15
4895+#define PAX_DELTA_STACK_LEN 15
4896+#endif
4897
4898 /* This yields a mask that user programs can use to figure out what
4899 instruction set this CPU supports. This could be done in user space,
4900diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4901index 479330b..53717a8 100644
4902--- a/arch/avr32/include/asm/kmap_types.h
4903+++ b/arch/avr32/include/asm/kmap_types.h
4904@@ -2,9 +2,9 @@
4905 #define __ASM_AVR32_KMAP_TYPES_H
4906
4907 #ifdef CONFIG_DEBUG_HIGHMEM
4908-# define KM_TYPE_NR 29
4909+# define KM_TYPE_NR 30
4910 #else
4911-# define KM_TYPE_NR 14
4912+# define KM_TYPE_NR 15
4913 #endif
4914
4915 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4916diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4917index 0eca933..eb78c7b 100644
4918--- a/arch/avr32/mm/fault.c
4919+++ b/arch/avr32/mm/fault.c
4920@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4921
4922 int exception_trace = 1;
4923
4924+#ifdef CONFIG_PAX_PAGEEXEC
4925+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4926+{
4927+ unsigned long i;
4928+
4929+ printk(KERN_ERR "PAX: bytes at PC: ");
4930+ for (i = 0; i < 20; i++) {
4931+ unsigned char c;
4932+ if (get_user(c, (unsigned char *)pc+i))
4933+ printk(KERN_CONT "???????? ");
4934+ else
4935+ printk(KERN_CONT "%02x ", c);
4936+ }
4937+ printk("\n");
4938+}
4939+#endif
4940+
4941 /*
4942 * This routine handles page faults. It determines the address and the
4943 * problem, and then passes it off to one of the appropriate routines.
4944@@ -176,6 +193,16 @@ bad_area:
4945 up_read(&mm->mmap_sem);
4946
4947 if (user_mode(regs)) {
4948+
4949+#ifdef CONFIG_PAX_PAGEEXEC
4950+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4951+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4952+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4953+ do_group_exit(SIGKILL);
4954+ }
4955+ }
4956+#endif
4957+
4958 if (exception_trace && printk_ratelimit())
4959 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4960 "sp %08lx ecr %lu\n",
4961diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4962index 568885a..f8008df 100644
4963--- a/arch/blackfin/include/asm/cache.h
4964+++ b/arch/blackfin/include/asm/cache.h
4965@@ -7,6 +7,7 @@
4966 #ifndef __ARCH_BLACKFIN_CACHE_H
4967 #define __ARCH_BLACKFIN_CACHE_H
4968
4969+#include <linux/const.h>
4970 #include <linux/linkage.h> /* for asmlinkage */
4971
4972 /*
4973@@ -14,7 +15,7 @@
4974 * Blackfin loads 32 bytes for cache
4975 */
4976 #define L1_CACHE_SHIFT 5
4977-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4978+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4979 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4980
4981 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4982diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4983index aea2718..3639a60 100644
4984--- a/arch/cris/include/arch-v10/arch/cache.h
4985+++ b/arch/cris/include/arch-v10/arch/cache.h
4986@@ -1,8 +1,9 @@
4987 #ifndef _ASM_ARCH_CACHE_H
4988 #define _ASM_ARCH_CACHE_H
4989
4990+#include <linux/const.h>
4991 /* Etrax 100LX have 32-byte cache-lines. */
4992-#define L1_CACHE_BYTES 32
4993 #define L1_CACHE_SHIFT 5
4994+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4995
4996 #endif /* _ASM_ARCH_CACHE_H */
4997diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4998index 7caf25d..ee65ac5 100644
4999--- a/arch/cris/include/arch-v32/arch/cache.h
5000+++ b/arch/cris/include/arch-v32/arch/cache.h
5001@@ -1,11 +1,12 @@
5002 #ifndef _ASM_CRIS_ARCH_CACHE_H
5003 #define _ASM_CRIS_ARCH_CACHE_H
5004
5005+#include <linux/const.h>
5006 #include <arch/hwregs/dma.h>
5007
5008 /* A cache-line is 32 bytes. */
5009-#define L1_CACHE_BYTES 32
5010 #define L1_CACHE_SHIFT 5
5011+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5012
5013 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5014
5015diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
5016index 102190a..5334cea 100644
5017--- a/arch/frv/include/asm/atomic.h
5018+++ b/arch/frv/include/asm/atomic.h
5019@@ -181,6 +181,16 @@ static inline void atomic64_dec(atomic64_t *v)
5020 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
5021 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
5022
5023+#define atomic64_read_unchecked(v) atomic64_read(v)
5024+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5025+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5026+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5027+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5028+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5029+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5030+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5031+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5032+
5033 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5034 {
5035 int c, old;
5036diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
5037index 2797163..c2a401df9 100644
5038--- a/arch/frv/include/asm/cache.h
5039+++ b/arch/frv/include/asm/cache.h
5040@@ -12,10 +12,11 @@
5041 #ifndef __ASM_CACHE_H
5042 #define __ASM_CACHE_H
5043
5044+#include <linux/const.h>
5045
5046 /* bytes per L1 cache line */
5047 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
5048-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5049+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5050
5051 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5052 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5053diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
5054index 43901f2..0d8b865 100644
5055--- a/arch/frv/include/asm/kmap_types.h
5056+++ b/arch/frv/include/asm/kmap_types.h
5057@@ -2,6 +2,6 @@
5058 #ifndef _ASM_KMAP_TYPES_H
5059 #define _ASM_KMAP_TYPES_H
5060
5061-#define KM_TYPE_NR 17
5062+#define KM_TYPE_NR 18
5063
5064 #endif
5065diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
5066index 836f147..4cf23f5 100644
5067--- a/arch/frv/mm/elf-fdpic.c
5068+++ b/arch/frv/mm/elf-fdpic.c
5069@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5070 {
5071 struct vm_area_struct *vma;
5072 struct vm_unmapped_area_info info;
5073+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5074
5075 if (len > TASK_SIZE)
5076 return -ENOMEM;
5077@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5078 if (addr) {
5079 addr = PAGE_ALIGN(addr);
5080 vma = find_vma(current->mm, addr);
5081- if (TASK_SIZE - len >= addr &&
5082- (!vma || addr + len <= vma->vm_start))
5083+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
5084 goto success;
5085 }
5086
5087@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5088 info.high_limit = (current->mm->start_stack - 0x00200000);
5089 info.align_mask = 0;
5090 info.align_offset = 0;
5091+ info.threadstack_offset = offset;
5092 addr = vm_unmapped_area(&info);
5093 if (!(addr & ~PAGE_MASK))
5094 goto success;
5095diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
5096index 2635117..fa223cb 100644
5097--- a/arch/hexagon/include/asm/cache.h
5098+++ b/arch/hexagon/include/asm/cache.h
5099@@ -21,9 +21,11 @@
5100 #ifndef __ASM_CACHE_H
5101 #define __ASM_CACHE_H
5102
5103+#include <linux/const.h>
5104+
5105 /* Bytes per L1 cache line */
5106-#define L1_CACHE_SHIFT (5)
5107-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5108+#define L1_CACHE_SHIFT 5
5109+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5110
5111 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
5112 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
5113diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
5114index c84c88b..2a6e1ba 100644
5115--- a/arch/ia64/Kconfig
5116+++ b/arch/ia64/Kconfig
5117@@ -549,6 +549,7 @@ source "drivers/sn/Kconfig"
5118 config KEXEC
5119 bool "kexec system call"
5120 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
5121+ depends on !GRKERNSEC_KMEM
5122 help
5123 kexec is a system call that implements the ability to shutdown your
5124 current kernel, and to start another kernel. It is like a reboot
5125diff --git a/arch/ia64/Makefile b/arch/ia64/Makefile
5126index 5441b14..039a446 100644
5127--- a/arch/ia64/Makefile
5128+++ b/arch/ia64/Makefile
5129@@ -99,5 +99,6 @@ endef
5130 archprepare: make_nr_irqs_h FORCE
5131 PHONY += make_nr_irqs_h FORCE
5132
5133+make_nr_irqs_h: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
5134 make_nr_irqs_h: FORCE
5135 $(Q)$(MAKE) $(build)=arch/ia64/kernel include/generated/nr-irqs.h
5136diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
5137index 0bf0350..2ad1957 100644
5138--- a/arch/ia64/include/asm/atomic.h
5139+++ b/arch/ia64/include/asm/atomic.h
5140@@ -193,4 +193,14 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
5141 #define atomic64_inc(v) atomic64_add(1, (v))
5142 #define atomic64_dec(v) atomic64_sub(1, (v))
5143
5144+#define atomic64_read_unchecked(v) atomic64_read(v)
5145+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5146+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5147+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5148+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5149+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5150+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5151+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5152+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5153+
5154 #endif /* _ASM_IA64_ATOMIC_H */
5155diff --git a/arch/ia64/include/asm/barrier.h b/arch/ia64/include/asm/barrier.h
5156index a48957c..e097b56 100644
5157--- a/arch/ia64/include/asm/barrier.h
5158+++ b/arch/ia64/include/asm/barrier.h
5159@@ -67,7 +67,7 @@
5160 do { \
5161 compiletime_assert_atomic_type(*p); \
5162 barrier(); \
5163- ACCESS_ONCE(*p) = (v); \
5164+ ACCESS_ONCE_RW(*p) = (v); \
5165 } while (0)
5166
5167 #define smp_load_acquire(p) \
5168diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
5169index 988254a..e1ee885 100644
5170--- a/arch/ia64/include/asm/cache.h
5171+++ b/arch/ia64/include/asm/cache.h
5172@@ -1,6 +1,7 @@
5173 #ifndef _ASM_IA64_CACHE_H
5174 #define _ASM_IA64_CACHE_H
5175
5176+#include <linux/const.h>
5177
5178 /*
5179 * Copyright (C) 1998-2000 Hewlett-Packard Co
5180@@ -9,7 +10,7 @@
5181
5182 /* Bytes per L1 (data) cache line. */
5183 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
5184-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5185+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5186
5187 #ifdef CONFIG_SMP
5188 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5189diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
5190index 5a83c5c..4d7f553 100644
5191--- a/arch/ia64/include/asm/elf.h
5192+++ b/arch/ia64/include/asm/elf.h
5193@@ -42,6 +42,13 @@
5194 */
5195 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5196
5197+#ifdef CONFIG_PAX_ASLR
5198+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5199+
5200+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5201+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5202+#endif
5203+
5204 #define PT_IA_64_UNWIND 0x70000001
5205
5206 /* IA-64 relocations: */
5207diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5208index 5767cdf..7462574 100644
5209--- a/arch/ia64/include/asm/pgalloc.h
5210+++ b/arch/ia64/include/asm/pgalloc.h
5211@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5212 pgd_val(*pgd_entry) = __pa(pud);
5213 }
5214
5215+static inline void
5216+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5217+{
5218+ pgd_populate(mm, pgd_entry, pud);
5219+}
5220+
5221 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5222 {
5223 return quicklist_alloc(0, GFP_KERNEL, NULL);
5224@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5225 pud_val(*pud_entry) = __pa(pmd);
5226 }
5227
5228+static inline void
5229+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5230+{
5231+ pud_populate(mm, pud_entry, pmd);
5232+}
5233+
5234 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5235 {
5236 return quicklist_alloc(0, GFP_KERNEL, NULL);
5237diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5238index 7935115..c0eca6a 100644
5239--- a/arch/ia64/include/asm/pgtable.h
5240+++ b/arch/ia64/include/asm/pgtable.h
5241@@ -12,7 +12,7 @@
5242 * David Mosberger-Tang <davidm@hpl.hp.com>
5243 */
5244
5245-
5246+#include <linux/const.h>
5247 #include <asm/mman.h>
5248 #include <asm/page.h>
5249 #include <asm/processor.h>
5250@@ -142,6 +142,17 @@
5251 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5252 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5253 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5254+
5255+#ifdef CONFIG_PAX_PAGEEXEC
5256+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5257+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5258+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5259+#else
5260+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5261+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5262+# define PAGE_COPY_NOEXEC PAGE_COPY
5263+#endif
5264+
5265 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5266 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5267 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5268diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5269index 45698cd..e8e2dbc 100644
5270--- a/arch/ia64/include/asm/spinlock.h
5271+++ b/arch/ia64/include/asm/spinlock.h
5272@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5273 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5274
5275 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5276- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5277+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5278 }
5279
5280 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5281diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5282index 449c8c0..3d4b1e9 100644
5283--- a/arch/ia64/include/asm/uaccess.h
5284+++ b/arch/ia64/include/asm/uaccess.h
5285@@ -70,6 +70,7 @@
5286 && ((segment).seg == KERNEL_DS.seg \
5287 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5288 })
5289+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5290 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5291
5292 /*
5293@@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5294 static inline unsigned long
5295 __copy_to_user (void __user *to, const void *from, unsigned long count)
5296 {
5297+ if (count > INT_MAX)
5298+ return count;
5299+
5300+ if (!__builtin_constant_p(count))
5301+ check_object_size(from, count, true);
5302+
5303 return __copy_user(to, (__force void __user *) from, count);
5304 }
5305
5306 static inline unsigned long
5307 __copy_from_user (void *to, const void __user *from, unsigned long count)
5308 {
5309+ if (count > INT_MAX)
5310+ return count;
5311+
5312+ if (!__builtin_constant_p(count))
5313+ check_object_size(to, count, false);
5314+
5315 return __copy_user((__force void __user *) to, from, count);
5316 }
5317
5318@@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5319 ({ \
5320 void __user *__cu_to = (to); \
5321 const void *__cu_from = (from); \
5322- long __cu_len = (n); \
5323+ unsigned long __cu_len = (n); \
5324 \
5325- if (__access_ok(__cu_to, __cu_len, get_fs())) \
5326+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5327+ if (!__builtin_constant_p(n)) \
5328+ check_object_size(__cu_from, __cu_len, true); \
5329 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5330+ } \
5331 __cu_len; \
5332 })
5333
5334@@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5335 ({ \
5336 void *__cu_to = (to); \
5337 const void __user *__cu_from = (from); \
5338- long __cu_len = (n); \
5339+ unsigned long __cu_len = (n); \
5340 \
5341 __chk_user_ptr(__cu_from); \
5342- if (__access_ok(__cu_from, __cu_len, get_fs())) \
5343+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5344+ if (!__builtin_constant_p(n)) \
5345+ check_object_size(__cu_to, __cu_len, false); \
5346 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5347+ } \
5348 __cu_len; \
5349 })
5350
5351diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5352index 24603be..948052d 100644
5353--- a/arch/ia64/kernel/module.c
5354+++ b/arch/ia64/kernel/module.c
5355@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5356 void
5357 module_free (struct module *mod, void *module_region)
5358 {
5359- if (mod && mod->arch.init_unw_table &&
5360- module_region == mod->module_init) {
5361+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5362 unw_remove_unwind_table(mod->arch.init_unw_table);
5363 mod->arch.init_unw_table = NULL;
5364 }
5365@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5366 }
5367
5368 static inline int
5369+in_init_rx (const struct module *mod, uint64_t addr)
5370+{
5371+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5372+}
5373+
5374+static inline int
5375+in_init_rw (const struct module *mod, uint64_t addr)
5376+{
5377+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5378+}
5379+
5380+static inline int
5381 in_init (const struct module *mod, uint64_t addr)
5382 {
5383- return addr - (uint64_t) mod->module_init < mod->init_size;
5384+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5385+}
5386+
5387+static inline int
5388+in_core_rx (const struct module *mod, uint64_t addr)
5389+{
5390+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5391+}
5392+
5393+static inline int
5394+in_core_rw (const struct module *mod, uint64_t addr)
5395+{
5396+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5397 }
5398
5399 static inline int
5400 in_core (const struct module *mod, uint64_t addr)
5401 {
5402- return addr - (uint64_t) mod->module_core < mod->core_size;
5403+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5404 }
5405
5406 static inline int
5407@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5408 break;
5409
5410 case RV_BDREL:
5411- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5412+ if (in_init_rx(mod, val))
5413+ val -= (uint64_t) mod->module_init_rx;
5414+ else if (in_init_rw(mod, val))
5415+ val -= (uint64_t) mod->module_init_rw;
5416+ else if (in_core_rx(mod, val))
5417+ val -= (uint64_t) mod->module_core_rx;
5418+ else if (in_core_rw(mod, val))
5419+ val -= (uint64_t) mod->module_core_rw;
5420 break;
5421
5422 case RV_LTV:
5423@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5424 * addresses have been selected...
5425 */
5426 uint64_t gp;
5427- if (mod->core_size > MAX_LTOFF)
5428+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5429 /*
5430 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5431 * at the end of the module.
5432 */
5433- gp = mod->core_size - MAX_LTOFF / 2;
5434+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5435 else
5436- gp = mod->core_size / 2;
5437- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5438+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5439+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5440 mod->arch.gp = gp;
5441 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5442 }
5443diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5444index c39c3cd..3c77738 100644
5445--- a/arch/ia64/kernel/palinfo.c
5446+++ b/arch/ia64/kernel/palinfo.c
5447@@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5448 return NOTIFY_OK;
5449 }
5450
5451-static struct notifier_block __refdata palinfo_cpu_notifier =
5452+static struct notifier_block palinfo_cpu_notifier =
5453 {
5454 .notifier_call = palinfo_cpu_callback,
5455 .priority = 0,
5456diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5457index 41e33f8..65180b2a 100644
5458--- a/arch/ia64/kernel/sys_ia64.c
5459+++ b/arch/ia64/kernel/sys_ia64.c
5460@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5461 unsigned long align_mask = 0;
5462 struct mm_struct *mm = current->mm;
5463 struct vm_unmapped_area_info info;
5464+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5465
5466 if (len > RGN_MAP_LIMIT)
5467 return -ENOMEM;
5468@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5469 if (REGION_NUMBER(addr) == RGN_HPAGE)
5470 addr = 0;
5471 #endif
5472+
5473+#ifdef CONFIG_PAX_RANDMMAP
5474+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5475+ addr = mm->free_area_cache;
5476+ else
5477+#endif
5478+
5479 if (!addr)
5480 addr = TASK_UNMAPPED_BASE;
5481
5482@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5483 info.high_limit = TASK_SIZE;
5484 info.align_mask = align_mask;
5485 info.align_offset = 0;
5486+ info.threadstack_offset = offset;
5487 return vm_unmapped_area(&info);
5488 }
5489
5490diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5491index 84f8a52..7c76178 100644
5492--- a/arch/ia64/kernel/vmlinux.lds.S
5493+++ b/arch/ia64/kernel/vmlinux.lds.S
5494@@ -192,7 +192,7 @@ SECTIONS {
5495 /* Per-cpu data: */
5496 . = ALIGN(PERCPU_PAGE_SIZE);
5497 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5498- __phys_per_cpu_start = __per_cpu_load;
5499+ __phys_per_cpu_start = per_cpu_load;
5500 /*
5501 * ensure percpu data fits
5502 * into percpu page size
5503diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5504index 7225dad..2a7c8256 100644
5505--- a/arch/ia64/mm/fault.c
5506+++ b/arch/ia64/mm/fault.c
5507@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5508 return pte_present(pte);
5509 }
5510
5511+#ifdef CONFIG_PAX_PAGEEXEC
5512+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5513+{
5514+ unsigned long i;
5515+
5516+ printk(KERN_ERR "PAX: bytes at PC: ");
5517+ for (i = 0; i < 8; i++) {
5518+ unsigned int c;
5519+ if (get_user(c, (unsigned int *)pc+i))
5520+ printk(KERN_CONT "???????? ");
5521+ else
5522+ printk(KERN_CONT "%08x ", c);
5523+ }
5524+ printk("\n");
5525+}
5526+#endif
5527+
5528 # define VM_READ_BIT 0
5529 # define VM_WRITE_BIT 1
5530 # define VM_EXEC_BIT 2
5531@@ -151,8 +168,21 @@ retry:
5532 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5533 goto bad_area;
5534
5535- if ((vma->vm_flags & mask) != mask)
5536+ if ((vma->vm_flags & mask) != mask) {
5537+
5538+#ifdef CONFIG_PAX_PAGEEXEC
5539+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5540+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5541+ goto bad_area;
5542+
5543+ up_read(&mm->mmap_sem);
5544+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5545+ do_group_exit(SIGKILL);
5546+ }
5547+#endif
5548+
5549 goto bad_area;
5550+ }
5551
5552 /*
5553 * If for any reason at all we couldn't handle the fault, make
5554diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5555index 76069c1..c2aa816 100644
5556--- a/arch/ia64/mm/hugetlbpage.c
5557+++ b/arch/ia64/mm/hugetlbpage.c
5558@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5559 unsigned long pgoff, unsigned long flags)
5560 {
5561 struct vm_unmapped_area_info info;
5562+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5563
5564 if (len > RGN_MAP_LIMIT)
5565 return -ENOMEM;
5566@@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5567 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5568 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5569 info.align_offset = 0;
5570+ info.threadstack_offset = offset;
5571 return vm_unmapped_area(&info);
5572 }
5573
5574diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5575index 6b33457..88b5124 100644
5576--- a/arch/ia64/mm/init.c
5577+++ b/arch/ia64/mm/init.c
5578@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5579 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5580 vma->vm_end = vma->vm_start + PAGE_SIZE;
5581 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5582+
5583+#ifdef CONFIG_PAX_PAGEEXEC
5584+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5585+ vma->vm_flags &= ~VM_EXEC;
5586+
5587+#ifdef CONFIG_PAX_MPROTECT
5588+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5589+ vma->vm_flags &= ~VM_MAYEXEC;
5590+#endif
5591+
5592+ }
5593+#endif
5594+
5595 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5596 down_write(&current->mm->mmap_sem);
5597 if (insert_vm_struct(current->mm, vma)) {
5598@@ -286,7 +299,7 @@ static int __init gate_vma_init(void)
5599 gate_vma.vm_start = FIXADDR_USER_START;
5600 gate_vma.vm_end = FIXADDR_USER_END;
5601 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
5602- gate_vma.vm_page_prot = __P101;
5603+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
5604
5605 return 0;
5606 }
5607diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5608index 40b3ee9..8c2c112 100644
5609--- a/arch/m32r/include/asm/cache.h
5610+++ b/arch/m32r/include/asm/cache.h
5611@@ -1,8 +1,10 @@
5612 #ifndef _ASM_M32R_CACHE_H
5613 #define _ASM_M32R_CACHE_H
5614
5615+#include <linux/const.h>
5616+
5617 /* L1 cache line size */
5618 #define L1_CACHE_SHIFT 4
5619-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5620+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5621
5622 #endif /* _ASM_M32R_CACHE_H */
5623diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5624index 82abd15..d95ae5d 100644
5625--- a/arch/m32r/lib/usercopy.c
5626+++ b/arch/m32r/lib/usercopy.c
5627@@ -14,6 +14,9 @@
5628 unsigned long
5629 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5630 {
5631+ if ((long)n < 0)
5632+ return n;
5633+
5634 prefetch(from);
5635 if (access_ok(VERIFY_WRITE, to, n))
5636 __copy_user(to,from,n);
5637@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5638 unsigned long
5639 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5640 {
5641+ if ((long)n < 0)
5642+ return n;
5643+
5644 prefetchw(to);
5645 if (access_ok(VERIFY_READ, from, n))
5646 __copy_user_zeroing(to,from,n);
5647diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5648index 0395c51..5f26031 100644
5649--- a/arch/m68k/include/asm/cache.h
5650+++ b/arch/m68k/include/asm/cache.h
5651@@ -4,9 +4,11 @@
5652 #ifndef __ARCH_M68K_CACHE_H
5653 #define __ARCH_M68K_CACHE_H
5654
5655+#include <linux/const.h>
5656+
5657 /* bytes per L1 cache line */
5658 #define L1_CACHE_SHIFT 4
5659-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5660+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5661
5662 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5663
5664diff --git a/arch/metag/include/asm/barrier.h b/arch/metag/include/asm/barrier.h
5665index c7591e8..ecef036 100644
5666--- a/arch/metag/include/asm/barrier.h
5667+++ b/arch/metag/include/asm/barrier.h
5668@@ -89,7 +89,7 @@ static inline void fence(void)
5669 do { \
5670 compiletime_assert_atomic_type(*p); \
5671 smp_mb(); \
5672- ACCESS_ONCE(*p) = (v); \
5673+ ACCESS_ONCE_RW(*p) = (v); \
5674 } while (0)
5675
5676 #define smp_load_acquire(p) \
5677diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5678index 3c32075..ae0ae75 100644
5679--- a/arch/metag/mm/hugetlbpage.c
5680+++ b/arch/metag/mm/hugetlbpage.c
5681@@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5682 info.high_limit = TASK_SIZE;
5683 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5684 info.align_offset = 0;
5685+ info.threadstack_offset = 0;
5686 return vm_unmapped_area(&info);
5687 }
5688
5689diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5690index 4efe96a..60e8699 100644
5691--- a/arch/microblaze/include/asm/cache.h
5692+++ b/arch/microblaze/include/asm/cache.h
5693@@ -13,11 +13,12 @@
5694 #ifndef _ASM_MICROBLAZE_CACHE_H
5695 #define _ASM_MICROBLAZE_CACHE_H
5696
5697+#include <linux/const.h>
5698 #include <asm/registers.h>
5699
5700 #define L1_CACHE_SHIFT 5
5701 /* word-granular cache in microblaze */
5702-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5703+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5704
5705 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5706
5707diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5708index 9536ef9..9333776 100644
5709--- a/arch/mips/Kconfig
5710+++ b/arch/mips/Kconfig
5711@@ -2413,6 +2413,7 @@ source "kernel/Kconfig.preempt"
5712
5713 config KEXEC
5714 bool "Kexec system call"
5715+ depends on !GRKERNSEC_KMEM
5716 help
5717 kexec is a system call that implements the ability to shutdown your
5718 current kernel, and to start another kernel. It is like a reboot
5719diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5720index 02f2444..506969c 100644
5721--- a/arch/mips/cavium-octeon/dma-octeon.c
5722+++ b/arch/mips/cavium-octeon/dma-octeon.c
5723@@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5724 if (dma_release_from_coherent(dev, order, vaddr))
5725 return;
5726
5727- swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5728+ swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5729 }
5730
5731 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5732diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5733index 6dd6bfc..903b0d6 100644
5734--- a/arch/mips/include/asm/atomic.h
5735+++ b/arch/mips/include/asm/atomic.h
5736@@ -21,15 +21,39 @@
5737 #include <asm/cmpxchg.h>
5738 #include <asm/war.h>
5739
5740+#ifdef CONFIG_GENERIC_ATOMIC64
5741+#include <asm-generic/atomic64.h>
5742+#endif
5743+
5744 #define ATOMIC_INIT(i) { (i) }
5745
5746+#ifdef CONFIG_64BIT
5747+#define _ASM_EXTABLE(from, to) \
5748+" .section __ex_table,\"a\"\n" \
5749+" .dword " #from ", " #to"\n" \
5750+" .previous\n"
5751+#else
5752+#define _ASM_EXTABLE(from, to) \
5753+" .section __ex_table,\"a\"\n" \
5754+" .word " #from ", " #to"\n" \
5755+" .previous\n"
5756+#endif
5757+
5758 /*
5759 * atomic_read - read atomic variable
5760 * @v: pointer of type atomic_t
5761 *
5762 * Atomically reads the value of @v.
5763 */
5764-#define atomic_read(v) ACCESS_ONCE((v)->counter)
5765+static inline int atomic_read(const atomic_t *v)
5766+{
5767+ return ACCESS_ONCE(v->counter);
5768+}
5769+
5770+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5771+{
5772+ return ACCESS_ONCE(v->counter);
5773+}
5774
5775 /*
5776 * atomic_set - set atomic variable
5777@@ -38,47 +62,77 @@
5778 *
5779 * Atomically sets the value of @v to @i.
5780 */
5781-#define atomic_set(v, i) ((v)->counter = (i))
5782+static inline void atomic_set(atomic_t *v, int i)
5783+{
5784+ v->counter = i;
5785+}
5786
5787-#define ATOMIC_OP(op, c_op, asm_op) \
5788-static __inline__ void atomic_##op(int i, atomic_t * v) \
5789+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5790+{
5791+ v->counter = i;
5792+}
5793+
5794+#ifdef CONFIG_PAX_REFCOUNT
5795+#define __OVERFLOW_POST \
5796+ " b 4f \n" \
5797+ " .set noreorder \n" \
5798+ "3: b 5f \n" \
5799+ " move %0, %1 \n" \
5800+ " .set reorder \n"
5801+#define __OVERFLOW_EXTABLE \
5802+ "3:\n" \
5803+ _ASM_EXTABLE(2b, 3b)
5804+#else
5805+#define __OVERFLOW_POST
5806+#define __OVERFLOW_EXTABLE
5807+#endif
5808+
5809+#define __ATOMIC_OP(op, suffix, asm_op, extable) \
5810+static inline void atomic_##op##suffix(int i, atomic##suffix##_t * v) \
5811 { \
5812 if (kernel_uses_llsc && R10000_LLSC_WAR) { \
5813 int temp; \
5814 \
5815 __asm__ __volatile__( \
5816- " .set arch=r4000 \n" \
5817- "1: ll %0, %1 # atomic_" #op " \n" \
5818- " " #asm_op " %0, %2 \n" \
5819+ " .set mips3 \n" \
5820+ "1: ll %0, %1 # atomic_" #op #suffix "\n" \
5821+ "2: " #asm_op " %0, %2 \n" \
5822 " sc %0, %1 \n" \
5823 " beqzl %0, 1b \n" \
5824+ extable \
5825 " .set mips0 \n" \
5826 : "=&r" (temp), "+m" (v->counter) \
5827 : "Ir" (i)); \
5828 } else if (kernel_uses_llsc) { \
5829 int temp; \
5830 \
5831- do { \
5832- __asm__ __volatile__( \
5833- " .set arch=r4000 \n" \
5834- " ll %0, %1 # atomic_" #op "\n" \
5835- " " #asm_op " %0, %2 \n" \
5836- " sc %0, %1 \n" \
5837- " .set mips0 \n" \
5838- : "=&r" (temp), "+m" (v->counter) \
5839- : "Ir" (i)); \
5840- } while (unlikely(!temp)); \
5841+ __asm__ __volatile__( \
5842+ " .set mips3 \n" \
5843+ " ll %0, %1 # atomic_" #op #suffix "\n" \
5844+ "2: " #asm_op " %0, %2 \n" \
5845+ " sc %0, %1 \n" \
5846+ " beqz %0, 1b \n" \
5847+ extable \
5848+ " .set mips0 \n" \
5849+ : "=&r" (temp), "+m" (v->counter) \
5850+ : "Ir" (i)); \
5851 } else { \
5852 unsigned long flags; \
5853 \
5854 raw_local_irq_save(flags); \
5855- v->counter c_op i; \
5856+ __asm__ __volatile__( \
5857+ "2: " #asm_op " %0, %1 \n" \
5858+ extable \
5859+ : "+r" (v->counter) : "Ir" (i)); \
5860 raw_local_irq_restore(flags); \
5861 } \
5862 } \
5863
5864-#define ATOMIC_OP_RETURN(op, c_op, asm_op) \
5865-static __inline__ int atomic_##op##_return(int i, atomic_t * v) \
5866+#define ATOMIC_OP(op, asm_op) __ATOMIC_OP(op, , asm_op##u) \
5867+ __ATOMIC_OP(op, _unchecked, asm_op)
5868+
5869+#define __ATOMIC_OP_RETURN(op, suffix, asm_op, post_op, extable) \
5870+static inline int atomic_##op##_return##suffix(int i, atomic##suffix##_t * v) \
5871 { \
5872 int result; \
5873 \
5874@@ -88,37 +142,47 @@ static __inline__ int atomic_##op##_return(int i, atomic_t * v) \
5875 int temp; \
5876 \
5877 __asm__ __volatile__( \
5878- " .set arch=r4000 \n" \
5879- "1: ll %1, %2 # atomic_" #op "_return \n" \
5880- " " #asm_op " %0, %1, %3 \n" \
5881+ " .set mips3 \n" \
5882+ "1: ll %1, %2 # atomic_" #op "_return" #suffix "\n" \
5883+ "2: " #asm_op " %0, %1, %3 \n" \
5884 " sc %0, %2 \n" \
5885 " beqzl %0, 1b \n" \
5886- " " #asm_op " %0, %1, %3 \n" \
5887+ post_op \
5888+ extable \
5889+ "4: " #asm_op " %0, %1, %3 \n" \
5890+ "5: \n" \
5891 " .set mips0 \n" \
5892 : "=&r" (result), "=&r" (temp), "+m" (v->counter) \
5893 : "Ir" (i)); \
5894 } else if (kernel_uses_llsc) { \
5895 int temp; \
5896 \
5897- do { \
5898- __asm__ __volatile__( \
5899- " .set arch=r4000 \n" \
5900- " ll %1, %2 # atomic_" #op "_return \n" \
5901- " " #asm_op " %0, %1, %3 \n" \
5902- " sc %0, %2 \n" \
5903- " .set mips0 \n" \
5904- : "=&r" (result), "=&r" (temp), "+m" (v->counter) \
5905- : "Ir" (i)); \
5906- } while (unlikely(!result)); \
5907+ __asm__ __volatile__( \
5908+ " .set mips3 \n" \
5909+ "1: ll %1, %2 # atomic_" #op "_return" #suffix "\n" \
5910+ "2: " #asm_op " %0, %1, %3 \n" \
5911+ " sc %0, %2 \n" \
5912+ " beqz %0, 1b \n" \
5913+ post_op \
5914+ extable \
5915+ "4: " #asm_op " %0, %1, %3 \n" \
5916+ "5: \n" \
5917+ " .set mips0 \n" \
5918+ : "=&r" (result), "=&r" (temp), "+m" (v->counter) \
5919+ : "Ir" (i)); \
5920 \
5921 result = temp; result c_op i; \
5922 } else { \
5923 unsigned long flags; \
5924 \
5925 raw_local_irq_save(flags); \
5926- result = v->counter; \
5927- result c_op i; \
5928- v->counter = result; \
5929+ __asm__ __volatile__( \
5930+ " lw %0, %1 \n" \
5931+ "2: " #asm_op " %0, %1, %2 \n" \
5932+ " sw %0, %1 \n" \
5933+ "3: \n" \
5934+ extable \
5935+ : "=&r" (result), "+m" (v->counter) : "Ir" (i)); \
5936 raw_local_irq_restore(flags); \
5937 } \
5938 \
5939@@ -127,16 +191,21 @@ static __inline__ int atomic_##op##_return(int i, atomic_t * v) \
5940 return result; \
5941 }
5942
5943-#define ATOMIC_OPS(op, c_op, asm_op) \
5944- ATOMIC_OP(op, c_op, asm_op) \
5945- ATOMIC_OP_RETURN(op, c_op, asm_op)
5946+#define ATOMIC_OP_RETURN(op, asm_op) __ATOMIC_OP_RETURN(op, , asm_op##u, , __OVERFLOW_EXTABLE) \
5947+ __ATOMIC_OP_RETURN(op, _unchecked, asm_op, __OVERFLOW_POST, __OVERFLOW_EXTABLE)
5948
5949-ATOMIC_OPS(add, +=, addu)
5950-ATOMIC_OPS(sub, -=, subu)
5951+#define ATOMIC_OPS(op, asm_op) \
5952+ ATOMIC_OP(op, asm_op) \
5953+ ATOMIC_OP_RETURN(op, asm_op)
5954+
5955+ATOMIC_OPS(add, add)
5956+ATOMIC_OPS(sub, sub)
5957
5958 #undef ATOMIC_OPS
5959 #undef ATOMIC_OP_RETURN
5960+#undef __ATOMIC_OP_RETURN
5961 #undef ATOMIC_OP
5962+#undef __ATOMIC_OP
5963
5964 /*
5965 * atomic_sub_if_positive - conditionally subtract integer from atomic variable
5966@@ -146,7 +215,7 @@ ATOMIC_OPS(sub, -=, subu)
5967 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5968 * The function returns the old value of @v minus @i.
5969 */
5970-static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5971+static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5972 {
5973 int result;
5974
5975@@ -203,8 +272,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5976 return result;
5977 }
5978
5979-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5980-#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5981+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5982+{
5983+ return cmpxchg(&v->counter, old, new);
5984+}
5985+
5986+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5987+ int new)
5988+{
5989+ return cmpxchg(&(v->counter), old, new);
5990+}
5991+
5992+static inline int atomic_xchg(atomic_t *v, int new)
5993+{
5994+ return xchg(&v->counter, new);
5995+}
5996+
5997+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5998+{
5999+ return xchg(&(v->counter), new);
6000+}
6001
6002 /**
6003 * __atomic_add_unless - add unless the number is a given value
6004@@ -232,6 +319,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6005
6006 #define atomic_dec_return(v) atomic_sub_return(1, (v))
6007 #define atomic_inc_return(v) atomic_add_return(1, (v))
6008+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6009+{
6010+ return atomic_add_return_unchecked(1, v);
6011+}
6012
6013 /*
6014 * atomic_sub_and_test - subtract value from variable and test result
6015@@ -253,6 +344,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6016 * other cases.
6017 */
6018 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
6019+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6020+{
6021+ return atomic_add_return_unchecked(1, v) == 0;
6022+}
6023
6024 /*
6025 * atomic_dec_and_test - decrement by 1 and test
6026@@ -277,6 +372,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6027 * Atomically increments @v by 1.
6028 */
6029 #define atomic_inc(v) atomic_add(1, (v))
6030+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
6031+{
6032+ atomic_add_unchecked(1, v);
6033+}
6034
6035 /*
6036 * atomic_dec - decrement and test
6037@@ -285,6 +384,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6038 * Atomically decrements @v by 1.
6039 */
6040 #define atomic_dec(v) atomic_sub(1, (v))
6041+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
6042+{
6043+ atomic_sub_unchecked(1, v);
6044+}
6045
6046 /*
6047 * atomic_add_negative - add and test if negative
6048@@ -306,54 +409,77 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6049 * @v: pointer of type atomic64_t
6050 *
6051 */
6052-#define atomic64_read(v) ACCESS_ONCE((v)->counter)
6053+static inline long atomic64_read(const atomic64_t *v)
6054+{
6055+ return ACCESS_ONCE(v->counter);
6056+}
6057+
6058+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6059+{
6060+ return ACCESS_ONCE(v->counter);
6061+}
6062
6063 /*
6064 * atomic64_set - set atomic variable
6065 * @v: pointer of type atomic64_t
6066 * @i: required value
6067 */
6068-#define atomic64_set(v, i) ((v)->counter = (i))
6069+static inline void atomic64_set(atomic64_t *v, long i)
6070+{
6071+ v->counter = i;
6072+}
6073
6074-#define ATOMIC64_OP(op, c_op, asm_op) \
6075-static __inline__ void atomic64_##op(long i, atomic64_t * v) \
6076+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6077+{
6078+ v->counter = i;
6079+}
6080+
6081+#define __ATOMIC64_OP(op, suffix, asm_op, extable) \
6082+static inline void atomic64_##op##suffix(long i, atomic64##suffix##_t * v) \
6083 { \
6084 if (kernel_uses_llsc && R10000_LLSC_WAR) { \
6085 long temp; \
6086 \
6087 __asm__ __volatile__( \
6088- " .set arch=r4000 \n" \
6089- "1: lld %0, %1 # atomic64_" #op " \n" \
6090- " " #asm_op " %0, %2 \n" \
6091+ " .set mips3 \n" \
6092+ "1: lld %0, %1 # atomic64_" #op #suffix "\n" \
6093+ "2: " #asm_op " %0, %2 \n" \
6094 " scd %0, %1 \n" \
6095 " beqzl %0, 1b \n" \
6096+ extable \
6097 " .set mips0 \n" \
6098 : "=&r" (temp), "+m" (v->counter) \
6099 : "Ir" (i)); \
6100 } else if (kernel_uses_llsc) { \
6101 long temp; \
6102 \
6103- do { \
6104- __asm__ __volatile__( \
6105- " .set arch=r4000 \n" \
6106- " lld %0, %1 # atomic64_" #op "\n" \
6107- " " #asm_op " %0, %2 \n" \
6108- " scd %0, %1 \n" \
6109- " .set mips0 \n" \
6110- : "=&r" (temp), "+m" (v->counter) \
6111- : "Ir" (i)); \
6112- } while (unlikely(!temp)); \
6113+ __asm__ __volatile__( \
6114+ " .set mips3 \n" \
6115+ " lld %0, %1 # atomic64_" #op #suffix "\n" \
6116+ "2: " #asm_op " %0, %2 \n" \
6117+ " scd %0, %1 \n" \
6118+ " beqz %0, 1b \n" \
6119+ extable \
6120+ " .set mips0 \n" \
6121+ : "=&r" (temp), "+m" (v->counter) \
6122+ : "Ir" (i)); \
6123 } else { \
6124 unsigned long flags; \
6125 \
6126 raw_local_irq_save(flags); \
6127- v->counter c_op i; \
6128+ __asm__ __volatile__( \
6129+ "2: " #asm_op " %0, %1 \n" \
6130+ extable \
6131+ : "+r" (v->counter) : "Ir" (i)); \
6132 raw_local_irq_restore(flags); \
6133 } \
6134 } \
6135
6136-#define ATOMIC64_OP_RETURN(op, c_op, asm_op) \
6137-static __inline__ long atomic64_##op##_return(long i, atomic64_t * v) \
6138+#define ATOMIC64_OP(op, asm_op) __ATOMIC64_OP(op, , asm_op##u) \
6139+ __ATOMIC64_OP(op, _unchecked, asm_op)
6140+
6141+#define __ATOMIC64_OP_RETURN(op, suffix, asm_op, post_op, extable) \
6142+static inline long atomic64_##op##_return##suffix(long i, atomic64##suffix##_t * v)\
6143 { \
6144 long result; \
6145 \
6146@@ -363,38 +489,48 @@ static __inline__ long atomic64_##op##_return(long i, atomic64_t * v) \
6147 long temp; \
6148 \
6149 __asm__ __volatile__( \
6150- " .set arch=r4000 \n" \
6151+ " .set mips3 \n" \
6152 "1: lld %1, %2 # atomic64_" #op "_return\n" \
6153- " " #asm_op " %0, %1, %3 \n" \
6154+ "2: " #asm_op " %0, %1, %3 \n" \
6155 " scd %0, %2 \n" \
6156 " beqzl %0, 1b \n" \
6157- " " #asm_op " %0, %1, %3 \n" \
6158+ post_op \
6159+ extable \
6160+ "4: " #asm_op " %0, %1, %3 \n" \
6161+ "5: \n" \
6162 " .set mips0 \n" \
6163 : "=&r" (result), "=&r" (temp), "+m" (v->counter) \
6164 : "Ir" (i)); \
6165 } else if (kernel_uses_llsc) { \
6166 long temp; \
6167 \
6168- do { \
6169- __asm__ __volatile__( \
6170- " .set arch=r4000 \n" \
6171- " lld %1, %2 # atomic64_" #op "_return\n" \
6172- " " #asm_op " %0, %1, %3 \n" \
6173- " scd %0, %2 \n" \
6174- " .set mips0 \n" \
6175- : "=&r" (result), "=&r" (temp), "=m" (v->counter) \
6176- : "Ir" (i), "m" (v->counter) \
6177- : "memory"); \
6178- } while (unlikely(!result)); \
6179+ __asm__ __volatile__( \
6180+ " .set mips3 \n" \
6181+ "1: lld %1, %2 # atomic64_" #op "_return" #suffix "\n" \
6182+ "2: " #asm_op " %0, %1, %3 \n" \
6183+ " scd %0, %2 \n" \
6184+ " beqz %0, 1b \n" \
6185+ post_op \
6186+ extable \
6187+ "4: " #asm_op " %0, %1, %3 \n" \
6188+ "5: \n" \
6189+ " .set mips0 \n" \
6190+ : "=&r" (result), "=&r" (temp), "=m" (v->counter) \
6191+ : "Ir" (i), "m" (v->counter) \
6192+ : "memory"); \
6193 \
6194 result = temp; result c_op i; \
6195 } else { \
6196 unsigned long flags; \
6197 \
6198 raw_local_irq_save(flags); \
6199- result = v->counter; \
6200- result c_op i; \
6201- v->counter = result; \
6202+ __asm__ __volatile__( \
6203+ " ld %0, %1 \n" \
6204+ "2: " #asm_op " %0, %1, %2 \n" \
6205+ " sd %0, %1 \n" \
6206+ "3: \n" \
6207+ extable \
6208+ : "=&r" (result), "+m" (v->counter) : "Ir" (i)); \
6209 raw_local_irq_restore(flags); \
6210 } \
6211 \
6212@@ -403,16 +539,23 @@ static __inline__ long atomic64_##op##_return(long i, atomic64_t * v) \
6213 return result; \
6214 }
6215
6216-#define ATOMIC64_OPS(op, c_op, asm_op) \
6217- ATOMIC64_OP(op, c_op, asm_op) \
6218- ATOMIC64_OP_RETURN(op, c_op, asm_op)
6219+#define ATOMIC64_OP_RETURN(op, asm_op) __ATOMIC64_OP_RETURN(op, , asm_op##u, , __OVERFLOW_EXTABLE) \
6220+ __ATOMIC64_OP_RETURN(op, _unchecked, asm_op, __OVERFLOW_POST, __OVERFLOW_EXTABLE)
6221
6222-ATOMIC64_OPS(add, +=, daddu)
6223-ATOMIC64_OPS(sub, -=, dsubu)
6224+#define ATOMIC64_OPS(op, asm_op) \
6225+ ATOMIC64_OP(op, asm_op) \
6226+ ATOMIC64_OP_RETURN(op, asm_op)
6227+
6228+ATOMIC64_OPS(add, dadd)
6229+ATOMIC64_OPS(sub, dsub)
6230
6231 #undef ATOMIC64_OPS
6232 #undef ATOMIC64_OP_RETURN
6233+#undef __ATOMIC64_OP_RETURN
6234 #undef ATOMIC64_OP
6235+#undef __ATOMIC64_OP
6236+#undef __OVERFLOW_EXTABLE
6237+#undef __OVERFLOW_POST
6238
6239 /*
6240 * atomic64_sub_if_positive - conditionally subtract integer from atomic variable
6241@@ -422,7 +565,7 @@ ATOMIC64_OPS(sub, -=, dsubu)
6242 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6243 * The function returns the old value of @v minus @i.
6244 */
6245-static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6246+static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6247 {
6248 long result;
6249
6250@@ -479,9 +622,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6251 return result;
6252 }
6253
6254-#define atomic64_cmpxchg(v, o, n) \
6255- ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6256-#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6257+static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6258+{
6259+ return cmpxchg(&v->counter, old, new);
6260+}
6261+
6262+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6263+ long new)
6264+{
6265+ return cmpxchg(&(v->counter), old, new);
6266+}
6267+
6268+static inline long atomic64_xchg(atomic64_t *v, long new)
6269+{
6270+ return xchg(&v->counter, new);
6271+}
6272+
6273+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6274+{
6275+ return xchg(&(v->counter), new);
6276+}
6277
6278 /**
6279 * atomic64_add_unless - add unless the number is a given value
6280@@ -511,6 +671,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6281
6282 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6283 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6284+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6285
6286 /*
6287 * atomic64_sub_and_test - subtract value from variable and test result
6288@@ -532,6 +693,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6289 * other cases.
6290 */
6291 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6292+#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6293
6294 /*
6295 * atomic64_dec_and_test - decrement by 1 and test
6296@@ -556,6 +718,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6297 * Atomically increments @v by 1.
6298 */
6299 #define atomic64_inc(v) atomic64_add(1, (v))
6300+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6301
6302 /*
6303 * atomic64_dec - decrement and test
6304@@ -564,6 +727,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6305 * Atomically decrements @v by 1.
6306 */
6307 #define atomic64_dec(v) atomic64_sub(1, (v))
6308+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6309
6310 /*
6311 * atomic64_add_negative - add and test if negative
6312diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h
6313index d0101dd..266982c 100644
6314--- a/arch/mips/include/asm/barrier.h
6315+++ b/arch/mips/include/asm/barrier.h
6316@@ -184,7 +184,7 @@
6317 do { \
6318 compiletime_assert_atomic_type(*p); \
6319 smp_mb(); \
6320- ACCESS_ONCE(*p) = (v); \
6321+ ACCESS_ONCE_RW(*p) = (v); \
6322 } while (0)
6323
6324 #define smp_load_acquire(p) \
6325diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6326index b4db69f..8f3b093 100644
6327--- a/arch/mips/include/asm/cache.h
6328+++ b/arch/mips/include/asm/cache.h
6329@@ -9,10 +9,11 @@
6330 #ifndef _ASM_CACHE_H
6331 #define _ASM_CACHE_H
6332
6333+#include <linux/const.h>
6334 #include <kmalloc.h>
6335
6336 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6337-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6338+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6339
6340 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6341 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6342diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6343index 1d38fe0..9beabc9 100644
6344--- a/arch/mips/include/asm/elf.h
6345+++ b/arch/mips/include/asm/elf.h
6346@@ -381,13 +381,16 @@ extern const char *__elf_platform;
6347 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6348 #endif
6349
6350+#ifdef CONFIG_PAX_ASLR
6351+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6352+
6353+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6354+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6355+#endif
6356+
6357 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6358 struct linux_binprm;
6359 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6360 int uses_interp);
6361
6362-struct mm_struct;
6363-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6364-#define arch_randomize_brk arch_randomize_brk
6365-
6366 #endif /* _ASM_ELF_H */
6367diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6368index c1f6afa..38cc6e9 100644
6369--- a/arch/mips/include/asm/exec.h
6370+++ b/arch/mips/include/asm/exec.h
6371@@ -12,6 +12,6 @@
6372 #ifndef _ASM_EXEC_H
6373 #define _ASM_EXEC_H
6374
6375-extern unsigned long arch_align_stack(unsigned long sp);
6376+#define arch_align_stack(x) ((x) & ~0xfUL)
6377
6378 #endif /* _ASM_EXEC_H */
6379diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6380index 9e8ef59..1139d6b 100644
6381--- a/arch/mips/include/asm/hw_irq.h
6382+++ b/arch/mips/include/asm/hw_irq.h
6383@@ -10,7 +10,7 @@
6384
6385 #include <linux/atomic.h>
6386
6387-extern atomic_t irq_err_count;
6388+extern atomic_unchecked_t irq_err_count;
6389
6390 /*
6391 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6392diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6393index 46dfc3c..a16b13a 100644
6394--- a/arch/mips/include/asm/local.h
6395+++ b/arch/mips/include/asm/local.h
6396@@ -12,15 +12,25 @@ typedef struct
6397 atomic_long_t a;
6398 } local_t;
6399
6400+typedef struct {
6401+ atomic_long_unchecked_t a;
6402+} local_unchecked_t;
6403+
6404 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6405
6406 #define local_read(l) atomic_long_read(&(l)->a)
6407+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6408 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6409+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6410
6411 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6412+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6413 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6414+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6415 #define local_inc(l) atomic_long_inc(&(l)->a)
6416+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6417 #define local_dec(l) atomic_long_dec(&(l)->a)
6418+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6419
6420 /*
6421 * Same as above, but return the result value
6422@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6423 return result;
6424 }
6425
6426+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6427+{
6428+ unsigned long result;
6429+
6430+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6431+ unsigned long temp;
6432+
6433+ __asm__ __volatile__(
6434+ " .set mips3 \n"
6435+ "1:" __LL "%1, %2 # local_add_return \n"
6436+ " addu %0, %1, %3 \n"
6437+ __SC "%0, %2 \n"
6438+ " beqzl %0, 1b \n"
6439+ " addu %0, %1, %3 \n"
6440+ " .set mips0 \n"
6441+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6442+ : "Ir" (i), "m" (l->a.counter)
6443+ : "memory");
6444+ } else if (kernel_uses_llsc) {
6445+ unsigned long temp;
6446+
6447+ __asm__ __volatile__(
6448+ " .set mips3 \n"
6449+ "1:" __LL "%1, %2 # local_add_return \n"
6450+ " addu %0, %1, %3 \n"
6451+ __SC "%0, %2 \n"
6452+ " beqz %0, 1b \n"
6453+ " addu %0, %1, %3 \n"
6454+ " .set mips0 \n"
6455+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6456+ : "Ir" (i), "m" (l->a.counter)
6457+ : "memory");
6458+ } else {
6459+ unsigned long flags;
6460+
6461+ local_irq_save(flags);
6462+ result = l->a.counter;
6463+ result += i;
6464+ l->a.counter = result;
6465+ local_irq_restore(flags);
6466+ }
6467+
6468+ return result;
6469+}
6470+
6471 static __inline__ long local_sub_return(long i, local_t * l)
6472 {
6473 unsigned long result;
6474@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6475
6476 #define local_cmpxchg(l, o, n) \
6477 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6478+#define local_cmpxchg_unchecked(l, o, n) \
6479+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6480 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6481
6482 /**
6483diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6484index 3be8180..c4798d5 100644
6485--- a/arch/mips/include/asm/page.h
6486+++ b/arch/mips/include/asm/page.h
6487@@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6488 #ifdef CONFIG_CPU_MIPS32
6489 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6490 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6491- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6492+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6493 #else
6494 typedef struct { unsigned long long pte; } pte_t;
6495 #define pte_val(x) ((x).pte)
6496diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6497index b336037..5b874cc 100644
6498--- a/arch/mips/include/asm/pgalloc.h
6499+++ b/arch/mips/include/asm/pgalloc.h
6500@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6501 {
6502 set_pud(pud, __pud((unsigned long)pmd));
6503 }
6504+
6505+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6506+{
6507+ pud_populate(mm, pud, pmd);
6508+}
6509 #endif
6510
6511 /*
6512diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6513index d6d1928..ce4f822 100644
6514--- a/arch/mips/include/asm/pgtable.h
6515+++ b/arch/mips/include/asm/pgtable.h
6516@@ -20,6 +20,9 @@
6517 #include <asm/io.h>
6518 #include <asm/pgtable-bits.h>
6519
6520+#define ktla_ktva(addr) (addr)
6521+#define ktva_ktla(addr) (addr)
6522+
6523 struct mm_struct;
6524 struct vm_area_struct;
6525
6526diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6527index 7de8658..c109224 100644
6528--- a/arch/mips/include/asm/thread_info.h
6529+++ b/arch/mips/include/asm/thread_info.h
6530@@ -105,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6531 #define TIF_SECCOMP 4 /* secure computing */
6532 #define TIF_NOTIFY_RESUME 5 /* callback before returning to user */
6533 #define TIF_RESTORE_SIGMASK 9 /* restore signal mask in do_signal() */
6534+/* li takes a 32bit immediate */
6535+#define TIF_GRSEC_SETXID 10 /* update credentials on syscall entry/exit */
6536+
6537 #define TIF_USEDFPU 16 /* FPU was used by this task this quantum (SMP) */
6538 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
6539 #define TIF_NOHZ 19 /* in adaptive nohz mode */
6540@@ -138,14 +141,16 @@ static inline struct thread_info *current_thread_info(void)
6541 #define _TIF_USEDMSA (1<<TIF_USEDMSA)
6542 #define _TIF_MSA_CTX_LIVE (1<<TIF_MSA_CTX_LIVE)
6543 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6544+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6545
6546 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6547 _TIF_SYSCALL_AUDIT | \
6548- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
6549+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \
6550+ _TIF_GRSEC_SETXID)
6551
6552 /* work to do in syscall_trace_leave() */
6553 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6554- _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6555+ _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6556
6557 /* work to do on interrupt/exception return */
6558 #define _TIF_WORK_MASK \
6559@@ -153,7 +158,7 @@ static inline struct thread_info *current_thread_info(void)
6560 /* work to do on any return to u-space */
6561 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6562 _TIF_WORK_SYSCALL_EXIT | \
6563- _TIF_SYSCALL_TRACEPOINT)
6564+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6565
6566 /*
6567 * We stash processor id into a COP0 register to retrieve it fast
6568diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6569index 22a5624..7c96295 100644
6570--- a/arch/mips/include/asm/uaccess.h
6571+++ b/arch/mips/include/asm/uaccess.h
6572@@ -130,6 +130,7 @@ extern u64 __ua_limit;
6573 __ok == 0; \
6574 })
6575
6576+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6577 #define access_ok(type, addr, size) \
6578 likely(__access_ok((addr), (size), __access_mask))
6579
6580diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6581index 1188e00..41cf144 100644
6582--- a/arch/mips/kernel/binfmt_elfn32.c
6583+++ b/arch/mips/kernel/binfmt_elfn32.c
6584@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6585 #undef ELF_ET_DYN_BASE
6586 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6587
6588+#ifdef CONFIG_PAX_ASLR
6589+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6590+
6591+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6592+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6593+#endif
6594+
6595 #include <asm/processor.h>
6596 #include <linux/module.h>
6597 #include <linux/elfcore.h>
6598diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6599index 9287678..f870e47 100644
6600--- a/arch/mips/kernel/binfmt_elfo32.c
6601+++ b/arch/mips/kernel/binfmt_elfo32.c
6602@@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6603 #undef ELF_ET_DYN_BASE
6604 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6605
6606+#ifdef CONFIG_PAX_ASLR
6607+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6608+
6609+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6610+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6611+#endif
6612+
6613 #include <asm/processor.h>
6614
6615 #include <linux/module.h>
6616diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
6617index 50b3648..c2f3cec 100644
6618--- a/arch/mips/kernel/i8259.c
6619+++ b/arch/mips/kernel/i8259.c
6620@@ -201,7 +201,7 @@ spurious_8259A_irq:
6621 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
6622 spurious_irq_mask |= irqmask;
6623 }
6624- atomic_inc(&irq_err_count);
6625+ atomic_inc_unchecked(&irq_err_count);
6626 /*
6627 * Theoretically we do not have to handle this IRQ,
6628 * but in Linux this does not cause problems and is
6629diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
6630index 44a1f79..2bd6aa3 100644
6631--- a/arch/mips/kernel/irq-gt641xx.c
6632+++ b/arch/mips/kernel/irq-gt641xx.c
6633@@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
6634 }
6635 }
6636
6637- atomic_inc(&irq_err_count);
6638+ atomic_inc_unchecked(&irq_err_count);
6639 }
6640
6641 void __init gt641xx_irq_init(void)
6642diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6643index d2bfbc2..a8eacd2 100644
6644--- a/arch/mips/kernel/irq.c
6645+++ b/arch/mips/kernel/irq.c
6646@@ -76,17 +76,17 @@ void ack_bad_irq(unsigned int irq)
6647 printk("unexpected IRQ # %d\n", irq);
6648 }
6649
6650-atomic_t irq_err_count;
6651+atomic_unchecked_t irq_err_count;
6652
6653 int arch_show_interrupts(struct seq_file *p, int prec)
6654 {
6655- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6656+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6657 return 0;
6658 }
6659
6660 asmlinkage void spurious_interrupt(void)
6661 {
6662- atomic_inc(&irq_err_count);
6663+ atomic_inc_unchecked(&irq_err_count);
6664 }
6665
6666 void __init init_IRQ(void)
6667@@ -109,7 +109,10 @@ void __init init_IRQ(void)
6668 #endif
6669 }
6670
6671+
6672 #ifdef DEBUG_STACKOVERFLOW
6673+extern void gr_handle_kernel_exploit(void);
6674+
6675 static inline void check_stack_overflow(void)
6676 {
6677 unsigned long sp;
6678@@ -125,6 +128,7 @@ static inline void check_stack_overflow(void)
6679 printk("do_IRQ: stack overflow: %ld\n",
6680 sp - sizeof(struct thread_info));
6681 dump_stack();
6682+ gr_handle_kernel_exploit();
6683 }
6684 }
6685 #else
6686diff --git a/arch/mips/kernel/pm-cps.c b/arch/mips/kernel/pm-cps.c
6687index 0614717..002fa43 100644
6688--- a/arch/mips/kernel/pm-cps.c
6689+++ b/arch/mips/kernel/pm-cps.c
6690@@ -172,7 +172,7 @@ int cps_pm_enter_state(enum cps_pm_state state)
6691 nc_core_ready_count = nc_addr;
6692
6693 /* Ensure ready_count is zero-initialised before the assembly runs */
6694- ACCESS_ONCE(*nc_core_ready_count) = 0;
6695+ ACCESS_ONCE_RW(*nc_core_ready_count) = 0;
6696 coupled_barrier(&per_cpu(pm_barrier, core), online);
6697
6698 /* Run the generated entry code */
6699diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6700index 636b074..8fbb91f 100644
6701--- a/arch/mips/kernel/process.c
6702+++ b/arch/mips/kernel/process.c
6703@@ -520,15 +520,3 @@ unsigned long get_wchan(struct task_struct *task)
6704 out:
6705 return pc;
6706 }
6707-
6708-/*
6709- * Don't forget that the stack pointer must be aligned on a 8 bytes
6710- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6711- */
6712-unsigned long arch_align_stack(unsigned long sp)
6713-{
6714- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6715- sp -= get_random_int() & ~PAGE_MASK;
6716-
6717- return sp & ALMASK;
6718-}
6719diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6720index 9d1487d..10c5da5 100644
6721--- a/arch/mips/kernel/ptrace.c
6722+++ b/arch/mips/kernel/ptrace.c
6723@@ -761,6 +761,10 @@ long arch_ptrace(struct task_struct *child, long request,
6724 return ret;
6725 }
6726
6727+#ifdef CONFIG_GRKERNSEC_SETXID
6728+extern void gr_delayed_cred_worker(void);
6729+#endif
6730+
6731 /*
6732 * Notification of system call entry/exit
6733 * - triggered by current->work.syscall_trace
6734@@ -777,6 +781,11 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
6735 tracehook_report_syscall_entry(regs))
6736 ret = -1;
6737
6738+#ifdef CONFIG_GRKERNSEC_SETXID
6739+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6740+ gr_delayed_cred_worker();
6741+#endif
6742+
6743 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6744 trace_sys_enter(regs, regs->regs[2]);
6745
6746diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
6747index 07fc524..b9d7f28 100644
6748--- a/arch/mips/kernel/reset.c
6749+++ b/arch/mips/kernel/reset.c
6750@@ -13,6 +13,7 @@
6751 #include <linux/reboot.h>
6752
6753 #include <asm/reboot.h>
6754+#include <asm/bug.h>
6755
6756 /*
6757 * Urgs ... Too many MIPS machines to handle this in a generic way.
6758@@ -29,16 +30,19 @@ void machine_restart(char *command)
6759 {
6760 if (_machine_restart)
6761 _machine_restart(command);
6762+ BUG();
6763 }
6764
6765 void machine_halt(void)
6766 {
6767 if (_machine_halt)
6768 _machine_halt();
6769+ BUG();
6770 }
6771
6772 void machine_power_off(void)
6773 {
6774 if (pm_power_off)
6775 pm_power_off();
6776+ BUG();
6777 }
6778diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6779index 2242bdd..b284048 100644
6780--- a/arch/mips/kernel/sync-r4k.c
6781+++ b/arch/mips/kernel/sync-r4k.c
6782@@ -18,8 +18,8 @@
6783 #include <asm/mipsregs.h>
6784
6785 static atomic_t count_start_flag = ATOMIC_INIT(0);
6786-static atomic_t count_count_start = ATOMIC_INIT(0);
6787-static atomic_t count_count_stop = ATOMIC_INIT(0);
6788+static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6789+static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6790 static atomic_t count_reference = ATOMIC_INIT(0);
6791
6792 #define COUNTON 100
6793@@ -58,13 +58,13 @@ void synchronise_count_master(int cpu)
6794
6795 for (i = 0; i < NR_LOOPS; i++) {
6796 /* slaves loop on '!= 2' */
6797- while (atomic_read(&count_count_start) != 1)
6798+ while (atomic_read_unchecked(&count_count_start) != 1)
6799 mb();
6800- atomic_set(&count_count_stop, 0);
6801+ atomic_set_unchecked(&count_count_stop, 0);
6802 smp_wmb();
6803
6804 /* this lets the slaves write their count register */
6805- atomic_inc(&count_count_start);
6806+ atomic_inc_unchecked(&count_count_start);
6807
6808 /*
6809 * Everyone initialises count in the last loop:
6810@@ -75,11 +75,11 @@ void synchronise_count_master(int cpu)
6811 /*
6812 * Wait for all slaves to leave the synchronization point:
6813 */
6814- while (atomic_read(&count_count_stop) != 1)
6815+ while (atomic_read_unchecked(&count_count_stop) != 1)
6816 mb();
6817- atomic_set(&count_count_start, 0);
6818+ atomic_set_unchecked(&count_count_start, 0);
6819 smp_wmb();
6820- atomic_inc(&count_count_stop);
6821+ atomic_inc_unchecked(&count_count_stop);
6822 }
6823 /* Arrange for an interrupt in a short while */
6824 write_c0_compare(read_c0_count() + COUNTON);
6825@@ -112,8 +112,8 @@ void synchronise_count_slave(int cpu)
6826 initcount = atomic_read(&count_reference);
6827
6828 for (i = 0; i < NR_LOOPS; i++) {
6829- atomic_inc(&count_count_start);
6830- while (atomic_read(&count_count_start) != 2)
6831+ atomic_inc_unchecked(&count_count_start);
6832+ while (atomic_read_unchecked(&count_count_start) != 2)
6833 mb();
6834
6835 /*
6836@@ -122,8 +122,8 @@ void synchronise_count_slave(int cpu)
6837 if (i == NR_LOOPS-1)
6838 write_c0_count(initcount);
6839
6840- atomic_inc(&count_count_stop);
6841- while (atomic_read(&count_count_stop) != 2)
6842+ atomic_inc_unchecked(&count_count_stop);
6843+ while (atomic_read_unchecked(&count_count_stop) != 2)
6844 mb();
6845 }
6846 /* Arrange for an interrupt in a short while */
6847diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
6848index 22b19c2..c5cc8c4 100644
6849--- a/arch/mips/kernel/traps.c
6850+++ b/arch/mips/kernel/traps.c
6851@@ -688,7 +688,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
6852 siginfo_t info;
6853
6854 prev_state = exception_enter();
6855- die_if_kernel("Integer overflow", regs);
6856+ if (unlikely(!user_mode(regs))) {
6857+
6858+#ifdef CONFIG_PAX_REFCOUNT
6859+ if (fixup_exception(regs)) {
6860+ pax_report_refcount_overflow(regs);
6861+ exception_exit(prev_state);
6862+ return;
6863+ }
6864+#endif
6865+
6866+ die("Integer overflow", regs);
6867+ }
6868
6869 info.si_code = FPE_INTOVF;
6870 info.si_signo = SIGFPE;
6871diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c
6872index e3b21e5..ea5ff7c 100644
6873--- a/arch/mips/kvm/mips.c
6874+++ b/arch/mips/kvm/mips.c
6875@@ -805,7 +805,7 @@ long kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
6876 return r;
6877 }
6878
6879-int kvm_arch_init(void *opaque)
6880+int kvm_arch_init(const void *opaque)
6881 {
6882 if (kvm_mips_callbacks) {
6883 kvm_err("kvm: module already exists\n");
6884diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
6885index becc42b..9e43d4b 100644
6886--- a/arch/mips/mm/fault.c
6887+++ b/arch/mips/mm/fault.c
6888@@ -28,6 +28,23 @@
6889 #include <asm/highmem.h> /* For VMALLOC_END */
6890 #include <linux/kdebug.h>
6891
6892+#ifdef CONFIG_PAX_PAGEEXEC
6893+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6894+{
6895+ unsigned long i;
6896+
6897+ printk(KERN_ERR "PAX: bytes at PC: ");
6898+ for (i = 0; i < 5; i++) {
6899+ unsigned int c;
6900+ if (get_user(c, (unsigned int *)pc+i))
6901+ printk(KERN_CONT "???????? ");
6902+ else
6903+ printk(KERN_CONT "%08x ", c);
6904+ }
6905+ printk("\n");
6906+}
6907+#endif
6908+
6909 /*
6910 * This routine handles page faults. It determines the address,
6911 * and the problem, and then passes it off to one of the appropriate
6912@@ -199,6 +216,14 @@ bad_area:
6913 bad_area_nosemaphore:
6914 /* User mode accesses just cause a SIGSEGV */
6915 if (user_mode(regs)) {
6916+
6917+#ifdef CONFIG_PAX_PAGEEXEC
6918+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
6919+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
6920+ do_group_exit(SIGKILL);
6921+ }
6922+#endif
6923+
6924 tsk->thread.cp0_badvaddr = address;
6925 tsk->thread.error_code = write;
6926 #if 0
6927diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
6928index f1baadd..5472dca 100644
6929--- a/arch/mips/mm/mmap.c
6930+++ b/arch/mips/mm/mmap.c
6931@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6932 struct vm_area_struct *vma;
6933 unsigned long addr = addr0;
6934 int do_color_align;
6935+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6936 struct vm_unmapped_area_info info;
6937
6938 if (unlikely(len > TASK_SIZE))
6939@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6940 do_color_align = 1;
6941
6942 /* requesting a specific address */
6943+
6944+#ifdef CONFIG_PAX_RANDMMAP
6945+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
6946+#endif
6947+
6948 if (addr) {
6949 if (do_color_align)
6950 addr = COLOUR_ALIGN(addr, pgoff);
6951@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6952 addr = PAGE_ALIGN(addr);
6953
6954 vma = find_vma(mm, addr);
6955- if (TASK_SIZE - len >= addr &&
6956- (!vma || addr + len <= vma->vm_start))
6957+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6958 return addr;
6959 }
6960
6961 info.length = len;
6962 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
6963 info.align_offset = pgoff << PAGE_SHIFT;
6964+ info.threadstack_offset = offset;
6965
6966 if (dir == DOWN) {
6967 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
6968@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6969 {
6970 unsigned long random_factor = 0UL;
6971
6972+#ifdef CONFIG_PAX_RANDMMAP
6973+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6974+#endif
6975+
6976 if (current->flags & PF_RANDOMIZE) {
6977 random_factor = get_random_int();
6978 random_factor = random_factor << PAGE_SHIFT;
6979@@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6980
6981 if (mmap_is_legacy()) {
6982 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6983+
6984+#ifdef CONFIG_PAX_RANDMMAP
6985+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6986+ mm->mmap_base += mm->delta_mmap;
6987+#endif
6988+
6989 mm->get_unmapped_area = arch_get_unmapped_area;
6990 } else {
6991 mm->mmap_base = mmap_base(random_factor);
6992+
6993+#ifdef CONFIG_PAX_RANDMMAP
6994+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6995+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6996+#endif
6997+
6998 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6999 }
7000 }
7001
7002-static inline unsigned long brk_rnd(void)
7003-{
7004- unsigned long rnd = get_random_int();
7005-
7006- rnd = rnd << PAGE_SHIFT;
7007- /* 8MB for 32bit, 256MB for 64bit */
7008- if (TASK_IS_32BIT_ADDR)
7009- rnd = rnd & 0x7ffffful;
7010- else
7011- rnd = rnd & 0xffffffful;
7012-
7013- return rnd;
7014-}
7015-
7016-unsigned long arch_randomize_brk(struct mm_struct *mm)
7017-{
7018- unsigned long base = mm->brk;
7019- unsigned long ret;
7020-
7021- ret = PAGE_ALIGN(base + brk_rnd());
7022-
7023- if (ret < mm->brk)
7024- return mm->brk;
7025-
7026- return ret;
7027-}
7028-
7029 int __virt_addr_valid(const volatile void *kaddr)
7030 {
7031 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7032diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7033index 59cccd9..f39ac2f 100644
7034--- a/arch/mips/pci/pci-octeon.c
7035+++ b/arch/mips/pci/pci-octeon.c
7036@@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7037
7038
7039 static struct pci_ops octeon_pci_ops = {
7040- octeon_read_config,
7041- octeon_write_config,
7042+ .read = octeon_read_config,
7043+ .write = octeon_write_config,
7044 };
7045
7046 static struct resource octeon_pci_mem_resource = {
7047diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7048index 5e36c33..eb4a17b 100644
7049--- a/arch/mips/pci/pcie-octeon.c
7050+++ b/arch/mips/pci/pcie-octeon.c
7051@@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7052 }
7053
7054 static struct pci_ops octeon_pcie0_ops = {
7055- octeon_pcie0_read_config,
7056- octeon_pcie0_write_config,
7057+ .read = octeon_pcie0_read_config,
7058+ .write = octeon_pcie0_write_config,
7059 };
7060
7061 static struct resource octeon_pcie0_mem_resource = {
7062@@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7063 };
7064
7065 static struct pci_ops octeon_pcie1_ops = {
7066- octeon_pcie1_read_config,
7067- octeon_pcie1_write_config,
7068+ .read = octeon_pcie1_read_config,
7069+ .write = octeon_pcie1_write_config,
7070 };
7071
7072 static struct resource octeon_pcie1_mem_resource = {
7073@@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7074 };
7075
7076 static struct pci_ops octeon_dummy_ops = {
7077- octeon_dummy_read_config,
7078- octeon_dummy_write_config,
7079+ .read = octeon_dummy_read_config,
7080+ .write = octeon_dummy_write_config,
7081 };
7082
7083 static struct resource octeon_dummy_mem_resource = {
7084diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7085index a2358b4..7cead4f 100644
7086--- a/arch/mips/sgi-ip27/ip27-nmi.c
7087+++ b/arch/mips/sgi-ip27/ip27-nmi.c
7088@@ -187,9 +187,9 @@ void
7089 cont_nmi_dump(void)
7090 {
7091 #ifndef REAL_NMI_SIGNAL
7092- static atomic_t nmied_cpus = ATOMIC_INIT(0);
7093+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7094
7095- atomic_inc(&nmied_cpus);
7096+ atomic_inc_unchecked(&nmied_cpus);
7097 #endif
7098 /*
7099 * Only allow 1 cpu to proceed
7100@@ -233,7 +233,7 @@ cont_nmi_dump(void)
7101 udelay(10000);
7102 }
7103 #else
7104- while (atomic_read(&nmied_cpus) != num_online_cpus());
7105+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7106 #endif
7107
7108 /*
7109diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7110index a046b30..6799527 100644
7111--- a/arch/mips/sni/rm200.c
7112+++ b/arch/mips/sni/rm200.c
7113@@ -270,7 +270,7 @@ spurious_8259A_irq:
7114 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7115 spurious_irq_mask |= irqmask;
7116 }
7117- atomic_inc(&irq_err_count);
7118+ atomic_inc_unchecked(&irq_err_count);
7119 /*
7120 * Theoretically we do not have to handle this IRQ,
7121 * but in Linux this does not cause problems and is
7122diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7123index 41e873b..34d33a7 100644
7124--- a/arch/mips/vr41xx/common/icu.c
7125+++ b/arch/mips/vr41xx/common/icu.c
7126@@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7127
7128 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7129
7130- atomic_inc(&irq_err_count);
7131+ atomic_inc_unchecked(&irq_err_count);
7132
7133 return -1;
7134 }
7135diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7136index ae0e4ee..e8f0692 100644
7137--- a/arch/mips/vr41xx/common/irq.c
7138+++ b/arch/mips/vr41xx/common/irq.c
7139@@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7140 irq_cascade_t *cascade;
7141
7142 if (irq >= NR_IRQS) {
7143- atomic_inc(&irq_err_count);
7144+ atomic_inc_unchecked(&irq_err_count);
7145 return;
7146 }
7147
7148@@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7149 ret = cascade->get_irq(irq);
7150 irq = ret;
7151 if (ret < 0)
7152- atomic_inc(&irq_err_count);
7153+ atomic_inc_unchecked(&irq_err_count);
7154 else
7155 irq_dispatch(irq);
7156 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7157diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7158index 967d144..db12197 100644
7159--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7160+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7161@@ -11,12 +11,14 @@
7162 #ifndef _ASM_PROC_CACHE_H
7163 #define _ASM_PROC_CACHE_H
7164
7165+#include <linux/const.h>
7166+
7167 /* L1 cache */
7168
7169 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7170 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7171-#define L1_CACHE_BYTES 16 /* bytes per entry */
7172 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7173+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7174 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7175
7176 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7177diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7178index bcb5df2..84fabd2 100644
7179--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7180+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7181@@ -16,13 +16,15 @@
7182 #ifndef _ASM_PROC_CACHE_H
7183 #define _ASM_PROC_CACHE_H
7184
7185+#include <linux/const.h>
7186+
7187 /*
7188 * L1 cache
7189 */
7190 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7191 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7192-#define L1_CACHE_BYTES 32 /* bytes per entry */
7193 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7194+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7195 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7196
7197 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7198diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7199index 4ce7a01..449202a 100644
7200--- a/arch/openrisc/include/asm/cache.h
7201+++ b/arch/openrisc/include/asm/cache.h
7202@@ -19,11 +19,13 @@
7203 #ifndef __ASM_OPENRISC_CACHE_H
7204 #define __ASM_OPENRISC_CACHE_H
7205
7206+#include <linux/const.h>
7207+
7208 /* FIXME: How can we replace these with values from the CPU...
7209 * they shouldn't be hard-coded!
7210 */
7211
7212-#define L1_CACHE_BYTES 16
7213 #define L1_CACHE_SHIFT 4
7214+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7215
7216 #endif /* __ASM_OPENRISC_CACHE_H */
7217diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7218index 226f8ca..9d9b87d 100644
7219--- a/arch/parisc/include/asm/atomic.h
7220+++ b/arch/parisc/include/asm/atomic.h
7221@@ -273,6 +273,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7222 return dec;
7223 }
7224
7225+#define atomic64_read_unchecked(v) atomic64_read(v)
7226+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7227+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7228+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7229+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7230+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7231+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7232+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7233+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7234+
7235 #endif /* !CONFIG_64BIT */
7236
7237
7238diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7239index 47f11c7..3420df2 100644
7240--- a/arch/parisc/include/asm/cache.h
7241+++ b/arch/parisc/include/asm/cache.h
7242@@ -5,6 +5,7 @@
7243 #ifndef __ARCH_PARISC_CACHE_H
7244 #define __ARCH_PARISC_CACHE_H
7245
7246+#include <linux/const.h>
7247
7248 /*
7249 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7250@@ -15,13 +16,13 @@
7251 * just ruin performance.
7252 */
7253 #ifdef CONFIG_PA20
7254-#define L1_CACHE_BYTES 64
7255 #define L1_CACHE_SHIFT 6
7256 #else
7257-#define L1_CACHE_BYTES 32
7258 #define L1_CACHE_SHIFT 5
7259 #endif
7260
7261+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7262+
7263 #ifndef __ASSEMBLY__
7264
7265 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7266diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7267index 3391d06..c23a2cc 100644
7268--- a/arch/parisc/include/asm/elf.h
7269+++ b/arch/parisc/include/asm/elf.h
7270@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7271
7272 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7273
7274+#ifdef CONFIG_PAX_ASLR
7275+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7276+
7277+#define PAX_DELTA_MMAP_LEN 16
7278+#define PAX_DELTA_STACK_LEN 16
7279+#endif
7280+
7281 /* This yields a mask that user programs can use to figure out what
7282 instruction set this CPU supports. This could be done in user space,
7283 but it's not easy, and we've already done it here. */
7284diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7285index f213f5b..0af3e8e 100644
7286--- a/arch/parisc/include/asm/pgalloc.h
7287+++ b/arch/parisc/include/asm/pgalloc.h
7288@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7289 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7290 }
7291
7292+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7293+{
7294+ pgd_populate(mm, pgd, pmd);
7295+}
7296+
7297 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7298 {
7299 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7300@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7301 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7302 #define pmd_free(mm, x) do { } while (0)
7303 #define pgd_populate(mm, pmd, pte) BUG()
7304+#define pgd_populate_kernel(mm, pmd, pte) BUG()
7305
7306 #endif
7307
7308diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7309index 22b89d1..ce34230 100644
7310--- a/arch/parisc/include/asm/pgtable.h
7311+++ b/arch/parisc/include/asm/pgtable.h
7312@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7313 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7314 #define PAGE_COPY PAGE_EXECREAD
7315 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7316+
7317+#ifdef CONFIG_PAX_PAGEEXEC
7318+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7319+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7320+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7321+#else
7322+# define PAGE_SHARED_NOEXEC PAGE_SHARED
7323+# define PAGE_COPY_NOEXEC PAGE_COPY
7324+# define PAGE_READONLY_NOEXEC PAGE_READONLY
7325+#endif
7326+
7327 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7328 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7329 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7330diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7331index a5cb070..8604ddc 100644
7332--- a/arch/parisc/include/asm/uaccess.h
7333+++ b/arch/parisc/include/asm/uaccess.h
7334@@ -243,10 +243,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7335 const void __user *from,
7336 unsigned long n)
7337 {
7338- int sz = __compiletime_object_size(to);
7339+ size_t sz = __compiletime_object_size(to);
7340 int ret = -EFAULT;
7341
7342- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7343+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7344 ret = __copy_from_user(to, from, n);
7345 else
7346 copy_from_user_overflow();
7347diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7348index 50dfafc..b9fc230 100644
7349--- a/arch/parisc/kernel/module.c
7350+++ b/arch/parisc/kernel/module.c
7351@@ -98,16 +98,38 @@
7352
7353 /* three functions to determine where in the module core
7354 * or init pieces the location is */
7355+static inline int in_init_rx(struct module *me, void *loc)
7356+{
7357+ return (loc >= me->module_init_rx &&
7358+ loc < (me->module_init_rx + me->init_size_rx));
7359+}
7360+
7361+static inline int in_init_rw(struct module *me, void *loc)
7362+{
7363+ return (loc >= me->module_init_rw &&
7364+ loc < (me->module_init_rw + me->init_size_rw));
7365+}
7366+
7367 static inline int in_init(struct module *me, void *loc)
7368 {
7369- return (loc >= me->module_init &&
7370- loc <= (me->module_init + me->init_size));
7371+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7372+}
7373+
7374+static inline int in_core_rx(struct module *me, void *loc)
7375+{
7376+ return (loc >= me->module_core_rx &&
7377+ loc < (me->module_core_rx + me->core_size_rx));
7378+}
7379+
7380+static inline int in_core_rw(struct module *me, void *loc)
7381+{
7382+ return (loc >= me->module_core_rw &&
7383+ loc < (me->module_core_rw + me->core_size_rw));
7384 }
7385
7386 static inline int in_core(struct module *me, void *loc)
7387 {
7388- return (loc >= me->module_core &&
7389- loc <= (me->module_core + me->core_size));
7390+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7391 }
7392
7393 static inline int in_local(struct module *me, void *loc)
7394@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7395 }
7396
7397 /* align things a bit */
7398- me->core_size = ALIGN(me->core_size, 16);
7399- me->arch.got_offset = me->core_size;
7400- me->core_size += gots * sizeof(struct got_entry);
7401+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7402+ me->arch.got_offset = me->core_size_rw;
7403+ me->core_size_rw += gots * sizeof(struct got_entry);
7404
7405- me->core_size = ALIGN(me->core_size, 16);
7406- me->arch.fdesc_offset = me->core_size;
7407- me->core_size += fdescs * sizeof(Elf_Fdesc);
7408+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7409+ me->arch.fdesc_offset = me->core_size_rw;
7410+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7411
7412 me->arch.got_max = gots;
7413 me->arch.fdesc_max = fdescs;
7414@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7415
7416 BUG_ON(value == 0);
7417
7418- got = me->module_core + me->arch.got_offset;
7419+ got = me->module_core_rw + me->arch.got_offset;
7420 for (i = 0; got[i].addr; i++)
7421 if (got[i].addr == value)
7422 goto out;
7423@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7424 #ifdef CONFIG_64BIT
7425 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7426 {
7427- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7428+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7429
7430 if (!value) {
7431 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7432@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7433
7434 /* Create new one */
7435 fdesc->addr = value;
7436- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7437+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7438 return (Elf_Addr)fdesc;
7439 }
7440 #endif /* CONFIG_64BIT */
7441@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7442
7443 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7444 end = table + sechdrs[me->arch.unwind_section].sh_size;
7445- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7446+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7447
7448 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7449 me->arch.unwind_section, table, end, gp);
7450diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7451index e1ffea2..46ed66e 100644
7452--- a/arch/parisc/kernel/sys_parisc.c
7453+++ b/arch/parisc/kernel/sys_parisc.c
7454@@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7455 unsigned long task_size = TASK_SIZE;
7456 int do_color_align, last_mmap;
7457 struct vm_unmapped_area_info info;
7458+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7459
7460 if (len > task_size)
7461 return -ENOMEM;
7462@@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7463 goto found_addr;
7464 }
7465
7466+#ifdef CONFIG_PAX_RANDMMAP
7467+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7468+#endif
7469+
7470 if (addr) {
7471 if (do_color_align && last_mmap)
7472 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7473@@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7474 info.high_limit = mmap_upper_limit();
7475 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7476 info.align_offset = shared_align_offset(last_mmap, pgoff);
7477+ info.threadstack_offset = offset;
7478 addr = vm_unmapped_area(&info);
7479
7480 found_addr:
7481@@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7482 unsigned long addr = addr0;
7483 int do_color_align, last_mmap;
7484 struct vm_unmapped_area_info info;
7485+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7486
7487 #ifdef CONFIG_64BIT
7488 /* This should only ever run for 32-bit processes. */
7489@@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7490 }
7491
7492 /* requesting a specific address */
7493+#ifdef CONFIG_PAX_RANDMMAP
7494+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7495+#endif
7496+
7497 if (addr) {
7498 if (do_color_align && last_mmap)
7499 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7500@@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7501 info.high_limit = mm->mmap_base;
7502 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7503 info.align_offset = shared_align_offset(last_mmap, pgoff);
7504+ info.threadstack_offset = offset;
7505 addr = vm_unmapped_area(&info);
7506 if (!(addr & ~PAGE_MASK))
7507 goto found_addr;
7508@@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7509 mm->mmap_legacy_base = mmap_legacy_base();
7510 mm->mmap_base = mmap_upper_limit();
7511
7512+#ifdef CONFIG_PAX_RANDMMAP
7513+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
7514+ mm->mmap_legacy_base += mm->delta_mmap;
7515+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7516+ }
7517+#endif
7518+
7519 if (mmap_is_legacy()) {
7520 mm->mmap_base = mm->mmap_legacy_base;
7521 mm->get_unmapped_area = arch_get_unmapped_area;
7522diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7523index 47ee620..1107387 100644
7524--- a/arch/parisc/kernel/traps.c
7525+++ b/arch/parisc/kernel/traps.c
7526@@ -726,9 +726,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7527
7528 down_read(&current->mm->mmap_sem);
7529 vma = find_vma(current->mm,regs->iaoq[0]);
7530- if (vma && (regs->iaoq[0] >= vma->vm_start)
7531- && (vma->vm_flags & VM_EXEC)) {
7532-
7533+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7534 fault_address = regs->iaoq[0];
7535 fault_space = regs->iasq[0];
7536
7537diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7538index 3ca9c11..d163ef7 100644
7539--- a/arch/parisc/mm/fault.c
7540+++ b/arch/parisc/mm/fault.c
7541@@ -15,6 +15,7 @@
7542 #include <linux/sched.h>
7543 #include <linux/interrupt.h>
7544 #include <linux/module.h>
7545+#include <linux/unistd.h>
7546
7547 #include <asm/uaccess.h>
7548 #include <asm/traps.h>
7549@@ -50,7 +51,7 @@ int show_unhandled_signals = 1;
7550 static unsigned long
7551 parisc_acctyp(unsigned long code, unsigned int inst)
7552 {
7553- if (code == 6 || code == 16)
7554+ if (code == 6 || code == 7 || code == 16)
7555 return VM_EXEC;
7556
7557 switch (inst & 0xf0000000) {
7558@@ -136,6 +137,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7559 }
7560 #endif
7561
7562+#ifdef CONFIG_PAX_PAGEEXEC
7563+/*
7564+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7565+ *
7566+ * returns 1 when task should be killed
7567+ * 2 when rt_sigreturn trampoline was detected
7568+ * 3 when unpatched PLT trampoline was detected
7569+ */
7570+static int pax_handle_fetch_fault(struct pt_regs *regs)
7571+{
7572+
7573+#ifdef CONFIG_PAX_EMUPLT
7574+ int err;
7575+
7576+ do { /* PaX: unpatched PLT emulation */
7577+ unsigned int bl, depwi;
7578+
7579+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7580+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7581+
7582+ if (err)
7583+ break;
7584+
7585+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7586+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7587+
7588+ err = get_user(ldw, (unsigned int *)addr);
7589+ err |= get_user(bv, (unsigned int *)(addr+4));
7590+ err |= get_user(ldw2, (unsigned int *)(addr+8));
7591+
7592+ if (err)
7593+ break;
7594+
7595+ if (ldw == 0x0E801096U &&
7596+ bv == 0xEAC0C000U &&
7597+ ldw2 == 0x0E881095U)
7598+ {
7599+ unsigned int resolver, map;
7600+
7601+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7602+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7603+ if (err)
7604+ break;
7605+
7606+ regs->gr[20] = instruction_pointer(regs)+8;
7607+ regs->gr[21] = map;
7608+ regs->gr[22] = resolver;
7609+ regs->iaoq[0] = resolver | 3UL;
7610+ regs->iaoq[1] = regs->iaoq[0] + 4;
7611+ return 3;
7612+ }
7613+ }
7614+ } while (0);
7615+#endif
7616+
7617+#ifdef CONFIG_PAX_EMUTRAMP
7618+
7619+#ifndef CONFIG_PAX_EMUSIGRT
7620+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7621+ return 1;
7622+#endif
7623+
7624+ do { /* PaX: rt_sigreturn emulation */
7625+ unsigned int ldi1, ldi2, bel, nop;
7626+
7627+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7628+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7629+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7630+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7631+
7632+ if (err)
7633+ break;
7634+
7635+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7636+ ldi2 == 0x3414015AU &&
7637+ bel == 0xE4008200U &&
7638+ nop == 0x08000240U)
7639+ {
7640+ regs->gr[25] = (ldi1 & 2) >> 1;
7641+ regs->gr[20] = __NR_rt_sigreturn;
7642+ regs->gr[31] = regs->iaoq[1] + 16;
7643+ regs->sr[0] = regs->iasq[1];
7644+ regs->iaoq[0] = 0x100UL;
7645+ regs->iaoq[1] = regs->iaoq[0] + 4;
7646+ regs->iasq[0] = regs->sr[2];
7647+ regs->iasq[1] = regs->sr[2];
7648+ return 2;
7649+ }
7650+ } while (0);
7651+#endif
7652+
7653+ return 1;
7654+}
7655+
7656+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7657+{
7658+ unsigned long i;
7659+
7660+ printk(KERN_ERR "PAX: bytes at PC: ");
7661+ for (i = 0; i < 5; i++) {
7662+ unsigned int c;
7663+ if (get_user(c, (unsigned int *)pc+i))
7664+ printk(KERN_CONT "???????? ");
7665+ else
7666+ printk(KERN_CONT "%08x ", c);
7667+ }
7668+ printk("\n");
7669+}
7670+#endif
7671+
7672 int fixup_exception(struct pt_regs *regs)
7673 {
7674 const struct exception_table_entry *fix;
7675@@ -234,8 +345,33 @@ retry:
7676
7677 good_area:
7678
7679- if ((vma->vm_flags & acc_type) != acc_type)
7680+ if ((vma->vm_flags & acc_type) != acc_type) {
7681+
7682+#ifdef CONFIG_PAX_PAGEEXEC
7683+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7684+ (address & ~3UL) == instruction_pointer(regs))
7685+ {
7686+ up_read(&mm->mmap_sem);
7687+ switch (pax_handle_fetch_fault(regs)) {
7688+
7689+#ifdef CONFIG_PAX_EMUPLT
7690+ case 3:
7691+ return;
7692+#endif
7693+
7694+#ifdef CONFIG_PAX_EMUTRAMP
7695+ case 2:
7696+ return;
7697+#endif
7698+
7699+ }
7700+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7701+ do_group_exit(SIGKILL);
7702+ }
7703+#endif
7704+
7705 goto bad_area;
7706+ }
7707
7708 /*
7709 * If for any reason at all we couldn't handle the fault, make
7710diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7711index 88eace4..4ba2591 100644
7712--- a/arch/powerpc/Kconfig
7713+++ b/arch/powerpc/Kconfig
7714@@ -404,6 +404,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
7715 config KEXEC
7716 bool "kexec system call"
7717 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7718+ depends on !GRKERNSEC_KMEM
7719 help
7720 kexec is a system call that implements the ability to shutdown your
7721 current kernel, and to start another kernel. It is like a reboot
7722diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7723index 512d278..d31fadd 100644
7724--- a/arch/powerpc/include/asm/atomic.h
7725+++ b/arch/powerpc/include/asm/atomic.h
7726@@ -12,6 +12,11 @@
7727
7728 #define ATOMIC_INIT(i) { (i) }
7729
7730+#define _ASM_EXTABLE(from, to) \
7731+" .section __ex_table,\"a\"\n" \
7732+ PPC_LONG" " #from ", " #to"\n" \
7733+" .previous\n"
7734+
7735 static __inline__ int atomic_read(const atomic_t *v)
7736 {
7737 int t;
7738@@ -21,39 +26,80 @@ static __inline__ int atomic_read(const atomic_t *v)
7739 return t;
7740 }
7741
7742+static __inline__ int atomic_read_unchecked(const atomic_unchecked_t *v)
7743+{
7744+ int t;
7745+
7746+ __asm__ __volatile__("lwz%U1%X1 %0,%1" : "=r"(t) : "m"(v->counter));
7747+
7748+ return t;
7749+}
7750+
7751 static __inline__ void atomic_set(atomic_t *v, int i)
7752 {
7753 __asm__ __volatile__("stw%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
7754 }
7755
7756-#define ATOMIC_OP(op, asm_op) \
7757-static __inline__ void atomic_##op(int a, atomic_t *v) \
7758+static __inline__ void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7759+{
7760+ __asm__ __volatile__("stw%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
7761+}
7762+
7763+#ifdef CONFIG_PAX_REFCOUNT
7764+#define __REFCOUNT_OP(op) op##o.
7765+#define __OVERFLOW_PRE \
7766+ " mcrxr cr0\n"
7767+#define __OVERFLOW_POST \
7768+ " bf 4*cr0+so, 3f\n" \
7769+ "2: .long 0x00c00b00\n" \
7770+ "3:\n"
7771+#define __OVERFLOW_EXTABLE \
7772+ "\n4:\n"
7773+ _ASM_EXTABLE(2b, 4b)
7774+#else
7775+#define __REFCOUNT_OP(op) op
7776+#define __OVERFLOW_PRE
7777+#define __OVERFLOW_POST
7778+#define __OVERFLOW_EXTABLE
7779+#endif
7780+
7781+#define __ATOMIC_OP(op, suffix, pre_op, asm_op, post_op, extable) \
7782+static inline void atomic_##op##suffix(int a, atomic##suffix##_t *v) \
7783 { \
7784 int t; \
7785 \
7786 __asm__ __volatile__( \
7787-"1: lwarx %0,0,%3 # atomic_" #op "\n" \
7788+"1: lwarx %0,0,%3 # atomic_" #op #suffix "\n" \
7789+ pre_op \
7790 #asm_op " %0,%2,%0\n" \
7791+ post_op \
7792 PPC405_ERR77(0,%3) \
7793 " stwcx. %0,0,%3 \n" \
7794 " bne- 1b\n" \
7795+ extable \
7796 : "=&r" (t), "+m" (v->counter) \
7797 : "r" (a), "r" (&v->counter) \
7798 : "cc"); \
7799 } \
7800
7801-#define ATOMIC_OP_RETURN(op, asm_op) \
7802-static __inline__ int atomic_##op##_return(int a, atomic_t *v) \
7803+#define ATOMIC_OP(op, asm_op) __ATOMIC_OP(op, , , asm_op, , ) \
7804+ __ATOMIC_OP(op, _unchecked, __OVERFLOW_PRE, __REFCOUNT_OP(asm_op), __OVERFLOW_POST, __OVERFLOW_EXTABLE)
7805+
7806+#define __ATOMIC_OP_RETURN(op, suffix, pre_op, asm_op, post_op, extable)\
7807+static inline int atomic_##op##_return##suffix(int a, atomic##suffix##_t *v)\
7808 { \
7809 int t; \
7810 \
7811 __asm__ __volatile__( \
7812 PPC_ATOMIC_ENTRY_BARRIER \
7813-"1: lwarx %0,0,%2 # atomic_" #op "_return\n" \
7814+"1: lwarx %0,0,%2 # atomic_" #op "_return" #suffix "\n" \
7815+ pre_op \
7816 #asm_op " %0,%1,%0\n" \
7817+ post_op \
7818 PPC405_ERR77(0,%2) \
7819 " stwcx. %0,0,%2 \n" \
7820 " bne- 1b\n" \
7821+ extable \
7822 PPC_ATOMIC_EXIT_BARRIER \
7823 : "=&r" (t) \
7824 : "r" (a), "r" (&v->counter) \
7825@@ -62,6 +108,9 @@ static __inline__ int atomic_##op##_return(int a, atomic_t *v) \
7826 return t; \
7827 }
7828
7829+#define ATOMIC_OP_RETURN(op, asm_op) __ATOMIC_OP_RETURN(op, , , asm_op, , )\
7830+ __ATOMIC_OP_RETURN(op, _unchecked, __OVERFLOW_PRE, __REFCOUNT_OP(asm_op), __OVERFLOW_POST, __OVERFLOW_EXTABLE)
7831+
7832 #define ATOMIC_OPS(op, asm_op) ATOMIC_OP(op, asm_op) ATOMIC_OP_RETURN(op, asm_op)
7833
7834 ATOMIC_OPS(add, add)
7835@@ -69,42 +118,29 @@ ATOMIC_OPS(sub, subf)
7836
7837 #undef ATOMIC_OPS
7838 #undef ATOMIC_OP_RETURN
7839+#undef __ATOMIC_OP_RETURN
7840 #undef ATOMIC_OP
7841+#undef __ATOMIC_OP
7842
7843 #define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
7844
7845-static __inline__ void atomic_inc(atomic_t *v)
7846-{
7847- int t;
7848+/*
7849+ * atomic_inc - increment atomic variable
7850+ * @v: pointer of type atomic_t
7851+ *
7852+ * Automatically increments @v by 1
7853+ */
7854+#define atomic_inc(v) atomic_add(1, (v))
7855+#define atomic_inc_return(v) atomic_add_return(1, (v))
7856
7857- __asm__ __volatile__(
7858-"1: lwarx %0,0,%2 # atomic_inc\n\
7859- addic %0,%0,1\n"
7860- PPC405_ERR77(0,%2)
7861-" stwcx. %0,0,%2 \n\
7862- bne- 1b"
7863- : "=&r" (t), "+m" (v->counter)
7864- : "r" (&v->counter)
7865- : "cc", "xer");
7866+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7867+{
7868+ atomic_add_unchecked(1, v);
7869 }
7870
7871-static __inline__ int atomic_inc_return(atomic_t *v)
7872+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7873 {
7874- int t;
7875-
7876- __asm__ __volatile__(
7877- PPC_ATOMIC_ENTRY_BARRIER
7878-"1: lwarx %0,0,%1 # atomic_inc_return\n\
7879- addic %0,%0,1\n"
7880- PPC405_ERR77(0,%1)
7881-" stwcx. %0,0,%1 \n\
7882- bne- 1b"
7883- PPC_ATOMIC_EXIT_BARRIER
7884- : "=&r" (t)
7885- : "r" (&v->counter)
7886- : "cc", "xer", "memory");
7887-
7888- return t;
7889+ return atomic_add_return_unchecked(1, v);
7890 }
7891
7892 /*
7893@@ -117,43 +153,38 @@ static __inline__ int atomic_inc_return(atomic_t *v)
7894 */
7895 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
7896
7897-static __inline__ void atomic_dec(atomic_t *v)
7898+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7899 {
7900- int t;
7901-
7902- __asm__ __volatile__(
7903-"1: lwarx %0,0,%2 # atomic_dec\n\
7904- addic %0,%0,-1\n"
7905- PPC405_ERR77(0,%2)\
7906-" stwcx. %0,0,%2\n\
7907- bne- 1b"
7908- : "=&r" (t), "+m" (v->counter)
7909- : "r" (&v->counter)
7910- : "cc", "xer");
7911+ return atomic_add_return_unchecked(1, v) == 0;
7912 }
7913
7914-static __inline__ int atomic_dec_return(atomic_t *v)
7915+/*
7916+ * atomic_dec - decrement atomic variable
7917+ * @v: pointer of type atomic_t
7918+ *
7919+ * Atomically decrements @v by 1
7920+ */
7921+#define atomic_dec(v) atomic_sub(1, (v))
7922+#define atomic_dec_return(v) atomic_sub_return(1, (v))
7923+
7924+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
7925 {
7926- int t;
7927-
7928- __asm__ __volatile__(
7929- PPC_ATOMIC_ENTRY_BARRIER
7930-"1: lwarx %0,0,%1 # atomic_dec_return\n\
7931- addic %0,%0,-1\n"
7932- PPC405_ERR77(0,%1)
7933-" stwcx. %0,0,%1\n\
7934- bne- 1b"
7935- PPC_ATOMIC_EXIT_BARRIER
7936- : "=&r" (t)
7937- : "r" (&v->counter)
7938- : "cc", "xer", "memory");
7939-
7940- return t;
7941+ atomic_sub_unchecked(1, v);
7942 }
7943
7944 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
7945 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
7946
7947+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7948+{
7949+ return cmpxchg(&(v->counter), old, new);
7950+}
7951+
7952+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7953+{
7954+ return xchg(&(v->counter), new);
7955+}
7956+
7957 /**
7958 * __atomic_add_unless - add unless the number is a given value
7959 * @v: pointer of type atomic_t
7960@@ -171,11 +202,27 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
7961 PPC_ATOMIC_ENTRY_BARRIER
7962 "1: lwarx %0,0,%1 # __atomic_add_unless\n\
7963 cmpw 0,%0,%3 \n\
7964- beq- 2f \n\
7965- add %0,%2,%0 \n"
7966+ beq- 2f \n"
7967+
7968+#ifdef CONFIG_PAX_REFCOUNT
7969+" mcrxr cr0\n"
7970+" addo. %0,%2,%0\n"
7971+" bf 4*cr0+so, 4f\n"
7972+"3:.long " "0x00c00b00""\n"
7973+"4:\n"
7974+#else
7975+ "add %0,%2,%0 \n"
7976+#endif
7977+
7978 PPC405_ERR77(0,%2)
7979 " stwcx. %0,0,%1 \n\
7980 bne- 1b \n"
7981+"5:"
7982+
7983+#ifdef CONFIG_PAX_REFCOUNT
7984+ _ASM_EXTABLE(3b, 5b)
7985+#endif
7986+
7987 PPC_ATOMIC_EXIT_BARRIER
7988 " subf %0,%2,%0 \n\
7989 2:"
7990@@ -248,6 +295,11 @@ static __inline__ int atomic_dec_if_positive(atomic_t *v)
7991 }
7992 #define atomic_dec_if_positive atomic_dec_if_positive
7993
7994+#define smp_mb__before_atomic_dec() smp_mb()
7995+#define smp_mb__after_atomic_dec() smp_mb()
7996+#define smp_mb__before_atomic_inc() smp_mb()
7997+#define smp_mb__after_atomic_inc() smp_mb()
7998+
7999 #ifdef __powerpc64__
8000
8001 #define ATOMIC64_INIT(i) { (i) }
8002@@ -261,37 +313,60 @@ static __inline__ long atomic64_read(const atomic64_t *v)
8003 return t;
8004 }
8005
8006+static __inline__ long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8007+{
8008+ long t;
8009+
8010+ __asm__ __volatile__("ld%U1%X1 %0,%1" : "=r"(t) : "m"(v->counter));
8011+
8012+ return t;
8013+}
8014+
8015 static __inline__ void atomic64_set(atomic64_t *v, long i)
8016 {
8017 __asm__ __volatile__("std%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8018 }
8019
8020-#define ATOMIC64_OP(op, asm_op) \
8021-static __inline__ void atomic64_##op(long a, atomic64_t *v) \
8022+static __inline__ void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8023+{
8024+ __asm__ __volatile__("std%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8025+}
8026+
8027+#define __ATOMIC64_OP(op, suffix, pre_op, asm_op, post_op, extable) \
8028+static inline void atomic64_##op##suffix(long a, atomic64##suffix##_t *v)\
8029 { \
8030 long t; \
8031 \
8032 __asm__ __volatile__( \
8033 "1: ldarx %0,0,%3 # atomic64_" #op "\n" \
8034+ pre_op \
8035 #asm_op " %0,%2,%0\n" \
8036+ post_op \
8037 " stdcx. %0,0,%3 \n" \
8038 " bne- 1b\n" \
8039+ extable \
8040 : "=&r" (t), "+m" (v->counter) \
8041 : "r" (a), "r" (&v->counter) \
8042 : "cc"); \
8043 }
8044
8045-#define ATOMIC64_OP_RETURN(op, asm_op) \
8046-static __inline__ long atomic64_##op##_return(long a, atomic64_t *v) \
8047+#define ATOMIC64_OP(op, asm_op) __ATOMIC64_OP(op, , , asm_op, , ) \
8048+ __ATOMIC64_OP(op, _unchecked, __OVERFLOW_PRE, __REFCOUNT_OP(asm_op), __OVERFLOW_POST, __OVERFLOW_EXTABLE)
8049+
8050+#define __ATOMIC64_OP_RETURN(op, suffix, pre_op, asm_op, post_op, extable)\
8051+static inline long atomic64_##op##_return##suffix(long a, atomic64##suffix##_t *v)\
8052 { \
8053 long t; \
8054 \
8055 __asm__ __volatile__( \
8056 PPC_ATOMIC_ENTRY_BARRIER \
8057 "1: ldarx %0,0,%2 # atomic64_" #op "_return\n" \
8058+ pre_op \
8059 #asm_op " %0,%1,%0\n" \
8060+ post_op \
8061 " stdcx. %0,0,%2 \n" \
8062 " bne- 1b\n" \
8063+ extable \
8064 PPC_ATOMIC_EXIT_BARRIER \
8065 : "=&r" (t) \
8066 : "r" (a), "r" (&v->counter) \
8067@@ -300,6 +375,9 @@ static __inline__ long atomic64_##op##_return(long a, atomic64_t *v) \
8068 return t; \
8069 }
8070
8071+#define ATOMIC64_OP_RETURN(op, asm_op) __ATOMIC64_OP_RETURN(op, , , asm_op, , )\
8072+ __ATOMIC64_OP_RETURN(op, _unchecked, __OVERFLOW_PRE, __REFCOUNT_OP(asm_op), __OVERFLOW_POST, __OVERFLOW_EXTABLE)
8073+
8074 #define ATOMIC64_OPS(op, asm_op) ATOMIC64_OP(op, asm_op) ATOMIC64_OP_RETURN(op, asm_op)
8075
8076 ATOMIC64_OPS(add, add)
8077@@ -307,40 +385,33 @@ ATOMIC64_OPS(sub, subf)
8078
8079 #undef ATOMIC64_OPS
8080 #undef ATOMIC64_OP_RETURN
8081+#undef __ATOMIC64_OP_RETURN
8082 #undef ATOMIC64_OP
8083+#undef __ATOMIC64_OP
8084+#undef __OVERFLOW_EXTABLE
8085+#undef __OVERFLOW_POST
8086+#undef __OVERFLOW_PRE
8087+#undef __REFCOUNT_OP
8088
8089 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
8090
8091-static __inline__ void atomic64_inc(atomic64_t *v)
8092-{
8093- long t;
8094+/*
8095+ * atomic64_inc - increment atomic variable
8096+ * @v: pointer of type atomic64_t
8097+ *
8098+ * Automatically increments @v by 1
8099+ */
8100+#define atomic64_inc(v) atomic64_add(1, (v))
8101+#define atomic64_inc_return(v) atomic64_add_return(1, (v))
8102
8103- __asm__ __volatile__(
8104-"1: ldarx %0,0,%2 # atomic64_inc\n\
8105- addic %0,%0,1\n\
8106- stdcx. %0,0,%2 \n\
8107- bne- 1b"
8108- : "=&r" (t), "+m" (v->counter)
8109- : "r" (&v->counter)
8110- : "cc", "xer");
8111+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8112+{
8113+ atomic64_add_unchecked(1, v);
8114 }
8115
8116-static __inline__ long atomic64_inc_return(atomic64_t *v)
8117+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8118 {
8119- long t;
8120-
8121- __asm__ __volatile__(
8122- PPC_ATOMIC_ENTRY_BARRIER
8123-"1: ldarx %0,0,%1 # atomic64_inc_return\n\
8124- addic %0,%0,1\n\
8125- stdcx. %0,0,%1 \n\
8126- bne- 1b"
8127- PPC_ATOMIC_EXIT_BARRIER
8128- : "=&r" (t)
8129- : "r" (&v->counter)
8130- : "cc", "xer", "memory");
8131-
8132- return t;
8133+ return atomic64_add_return_unchecked(1, v);
8134 }
8135
8136 /*
8137@@ -353,36 +424,18 @@ static __inline__ long atomic64_inc_return(atomic64_t *v)
8138 */
8139 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
8140
8141-static __inline__ void atomic64_dec(atomic64_t *v)
8142+/*
8143+ * atomic64_dec - decrement atomic variable
8144+ * @v: pointer of type atomic64_t
8145+ *
8146+ * Atomically decrements @v by 1
8147+ */
8148+#define atomic64_dec(v) atomic64_sub(1, (v))
8149+#define atomic64_dec_return(v) atomic64_sub_return(1, (v))
8150+
8151+static __inline__ void atomic64_dec_unchecked(atomic64_unchecked_t *v)
8152 {
8153- long t;
8154-
8155- __asm__ __volatile__(
8156-"1: ldarx %0,0,%2 # atomic64_dec\n\
8157- addic %0,%0,-1\n\
8158- stdcx. %0,0,%2\n\
8159- bne- 1b"
8160- : "=&r" (t), "+m" (v->counter)
8161- : "r" (&v->counter)
8162- : "cc", "xer");
8163-}
8164-
8165-static __inline__ long atomic64_dec_return(atomic64_t *v)
8166-{
8167- long t;
8168-
8169- __asm__ __volatile__(
8170- PPC_ATOMIC_ENTRY_BARRIER
8171-"1: ldarx %0,0,%1 # atomic64_dec_return\n\
8172- addic %0,%0,-1\n\
8173- stdcx. %0,0,%1\n\
8174- bne- 1b"
8175- PPC_ATOMIC_EXIT_BARRIER
8176- : "=&r" (t)
8177- : "r" (&v->counter)
8178- : "cc", "xer", "memory");
8179-
8180- return t;
8181+ atomic64_sub_unchecked(1, v);
8182 }
8183
8184 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
8185@@ -415,6 +468,16 @@ static __inline__ long atomic64_dec_if_positive(atomic64_t *v)
8186 #define atomic64_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
8187 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
8188
8189+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
8190+{
8191+ return cmpxchg(&(v->counter), old, new);
8192+}
8193+
8194+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
8195+{
8196+ return xchg(&(v->counter), new);
8197+}
8198+
8199 /**
8200 * atomic64_add_unless - add unless the number is a given value
8201 * @v: pointer of type atomic64_t
8202@@ -430,13 +493,29 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
8203
8204 __asm__ __volatile__ (
8205 PPC_ATOMIC_ENTRY_BARRIER
8206-"1: ldarx %0,0,%1 # __atomic_add_unless\n\
8207+"1: ldarx %0,0,%1 # atomic64_add_unless\n\
8208 cmpd 0,%0,%3 \n\
8209- beq- 2f \n\
8210- add %0,%2,%0 \n"
8211+ beq- 2f \n"
8212+
8213+#ifdef CONFIG_PAX_REFCOUNT
8214+" mcrxr cr0\n"
8215+" addo. %0,%2,%0\n"
8216+" bf 4*cr0+so, 4f\n"
8217+"3:.long " "0x00c00b00""\n"
8218+"4:\n"
8219+#else
8220+ "add %0,%2,%0 \n"
8221+#endif
8222+
8223 " stdcx. %0,0,%1 \n\
8224 bne- 1b \n"
8225 PPC_ATOMIC_EXIT_BARRIER
8226+"5:"
8227+
8228+#ifdef CONFIG_PAX_REFCOUNT
8229+ _ASM_EXTABLE(3b, 5b)
8230+#endif
8231+
8232 " subf %0,%2,%0 \n\
8233 2:"
8234 : "=&r" (t)
8235diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
8236index bab79a1..4a3eabc 100644
8237--- a/arch/powerpc/include/asm/barrier.h
8238+++ b/arch/powerpc/include/asm/barrier.h
8239@@ -73,7 +73,7 @@
8240 do { \
8241 compiletime_assert_atomic_type(*p); \
8242 __lwsync(); \
8243- ACCESS_ONCE(*p) = (v); \
8244+ ACCESS_ONCE_RW(*p) = (v); \
8245 } while (0)
8246
8247 #define smp_load_acquire(p) \
8248diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
8249index 34a05a1..a1f2c67 100644
8250--- a/arch/powerpc/include/asm/cache.h
8251+++ b/arch/powerpc/include/asm/cache.h
8252@@ -4,6 +4,7 @@
8253 #ifdef __KERNEL__
8254
8255 #include <asm/reg.h>
8256+#include <linux/const.h>
8257
8258 /* bytes per L1 cache line */
8259 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
8260@@ -23,7 +24,7 @@
8261 #define L1_CACHE_SHIFT 7
8262 #endif
8263
8264-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8265+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8266
8267 #define SMP_CACHE_BYTES L1_CACHE_BYTES
8268
8269diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
8270index 888d8f3..66f581c 100644
8271--- a/arch/powerpc/include/asm/elf.h
8272+++ b/arch/powerpc/include/asm/elf.h
8273@@ -28,8 +28,19 @@
8274 the loader. We need to make sure that it is out of the way of the program
8275 that it will "exec", and that there is sufficient room for the brk. */
8276
8277-extern unsigned long randomize_et_dyn(unsigned long base);
8278-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
8279+#define ELF_ET_DYN_BASE (0x20000000)
8280+
8281+#ifdef CONFIG_PAX_ASLR
8282+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
8283+
8284+#ifdef __powerpc64__
8285+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
8286+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
8287+#else
8288+#define PAX_DELTA_MMAP_LEN 15
8289+#define PAX_DELTA_STACK_LEN 15
8290+#endif
8291+#endif
8292
8293 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
8294
8295@@ -129,10 +140,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
8296 (0x7ff >> (PAGE_SHIFT - 12)) : \
8297 (0x3ffff >> (PAGE_SHIFT - 12)))
8298
8299-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8300-#define arch_randomize_brk arch_randomize_brk
8301-
8302-
8303 #ifdef CONFIG_SPU_BASE
8304 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
8305 #define NT_SPU 1
8306diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
8307index 8196e9c..d83a9f3 100644
8308--- a/arch/powerpc/include/asm/exec.h
8309+++ b/arch/powerpc/include/asm/exec.h
8310@@ -4,6 +4,6 @@
8311 #ifndef _ASM_POWERPC_EXEC_H
8312 #define _ASM_POWERPC_EXEC_H
8313
8314-extern unsigned long arch_align_stack(unsigned long sp);
8315+#define arch_align_stack(x) ((x) & ~0xfUL)
8316
8317 #endif /* _ASM_POWERPC_EXEC_H */
8318diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
8319index 5acabbd..7ea14fa 100644
8320--- a/arch/powerpc/include/asm/kmap_types.h
8321+++ b/arch/powerpc/include/asm/kmap_types.h
8322@@ -10,7 +10,7 @@
8323 * 2 of the License, or (at your option) any later version.
8324 */
8325
8326-#define KM_TYPE_NR 16
8327+#define KM_TYPE_NR 17
8328
8329 #endif /* __KERNEL__ */
8330 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8331diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8332index b8da913..c02b593 100644
8333--- a/arch/powerpc/include/asm/local.h
8334+++ b/arch/powerpc/include/asm/local.h
8335@@ -9,21 +9,65 @@ typedef struct
8336 atomic_long_t a;
8337 } local_t;
8338
8339+typedef struct
8340+{
8341+ atomic_long_unchecked_t a;
8342+} local_unchecked_t;
8343+
8344 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8345
8346 #define local_read(l) atomic_long_read(&(l)->a)
8347+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8348 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8349+#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8350
8351 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8352+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8353 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8354+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8355 #define local_inc(l) atomic_long_inc(&(l)->a)
8356+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8357 #define local_dec(l) atomic_long_dec(&(l)->a)
8358+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8359
8360 static __inline__ long local_add_return(long a, local_t *l)
8361 {
8362 long t;
8363
8364 __asm__ __volatile__(
8365+"1:" PPC_LLARX(%0,0,%2,0) " # local_add_return\n"
8366+
8367+#ifdef CONFIG_PAX_REFCOUNT
8368+" mcrxr cr0\n"
8369+" addo. %0,%1,%0\n"
8370+" bf 4*cr0+so, 3f\n"
8371+"2:.long " "0x00c00b00""\n"
8372+#else
8373+" add %0,%1,%0\n"
8374+#endif
8375+
8376+"3:\n"
8377+ PPC405_ERR77(0,%2)
8378+ PPC_STLCX "%0,0,%2 \n\
8379+ bne- 1b"
8380+
8381+#ifdef CONFIG_PAX_REFCOUNT
8382+"\n4:\n"
8383+ _ASM_EXTABLE(2b, 4b)
8384+#endif
8385+
8386+ : "=&r" (t)
8387+ : "r" (a), "r" (&(l->a.counter))
8388+ : "cc", "memory");
8389+
8390+ return t;
8391+}
8392+
8393+static __inline__ long local_add_return_unchecked(long a, local_unchecked_t *l)
8394+{
8395+ long t;
8396+
8397+ __asm__ __volatile__(
8398 "1:" PPC_LLARX(%0,0,%2,0) " # local_add_return\n\
8399 add %0,%1,%0\n"
8400 PPC405_ERR77(0,%2)
8401@@ -101,6 +145,8 @@ static __inline__ long local_dec_return(local_t *l)
8402
8403 #define local_cmpxchg(l, o, n) \
8404 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8405+#define local_cmpxchg_unchecked(l, o, n) \
8406+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
8407 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8408
8409 /**
8410diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8411index 8565c25..2865190 100644
8412--- a/arch/powerpc/include/asm/mman.h
8413+++ b/arch/powerpc/include/asm/mman.h
8414@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8415 }
8416 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8417
8418-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8419+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8420 {
8421 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8422 }
8423diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8424index 26fe1ae..987ffc5 100644
8425--- a/arch/powerpc/include/asm/page.h
8426+++ b/arch/powerpc/include/asm/page.h
8427@@ -227,8 +227,9 @@ extern long long virt_phys_offset;
8428 * and needs to be executable. This means the whole heap ends
8429 * up being executable.
8430 */
8431-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8432- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8433+#define VM_DATA_DEFAULT_FLAGS32 \
8434+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8435+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8436
8437 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8438 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8439@@ -256,6 +257,9 @@ extern long long virt_phys_offset;
8440 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8441 #endif
8442
8443+#define ktla_ktva(addr) (addr)
8444+#define ktva_ktla(addr) (addr)
8445+
8446 #ifndef CONFIG_PPC_BOOK3S_64
8447 /*
8448 * Use the top bit of the higher-level page table entries to indicate whether
8449diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8450index d908a46..3753f71 100644
8451--- a/arch/powerpc/include/asm/page_64.h
8452+++ b/arch/powerpc/include/asm/page_64.h
8453@@ -172,15 +172,18 @@ do { \
8454 * stack by default, so in the absence of a PT_GNU_STACK program header
8455 * we turn execute permission off.
8456 */
8457-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8458- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8459+#define VM_STACK_DEFAULT_FLAGS32 \
8460+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8461+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8462
8463 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8464 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8465
8466+#ifndef CONFIG_PAX_PAGEEXEC
8467 #define VM_STACK_DEFAULT_FLAGS \
8468 (is_32bit_task() ? \
8469 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8470+#endif
8471
8472 #include <asm-generic/getorder.h>
8473
8474diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8475index 4b0be20..c15a27d 100644
8476--- a/arch/powerpc/include/asm/pgalloc-64.h
8477+++ b/arch/powerpc/include/asm/pgalloc-64.h
8478@@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8479 #ifndef CONFIG_PPC_64K_PAGES
8480
8481 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8482+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8483
8484 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8485 {
8486@@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8487 pud_set(pud, (unsigned long)pmd);
8488 }
8489
8490+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8491+{
8492+ pud_populate(mm, pud, pmd);
8493+}
8494+
8495 #define pmd_populate(mm, pmd, pte_page) \
8496 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8497 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8498@@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8499 #endif
8500
8501 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8502+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8503
8504 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8505 pte_t *pte)
8506diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8507index 316f9a5..ba05c77 100644
8508--- a/arch/powerpc/include/asm/pgtable.h
8509+++ b/arch/powerpc/include/asm/pgtable.h
8510@@ -2,6 +2,7 @@
8511 #define _ASM_POWERPC_PGTABLE_H
8512 #ifdef __KERNEL__
8513
8514+#include <linux/const.h>
8515 #ifndef __ASSEMBLY__
8516 #include <linux/mmdebug.h>
8517 #include <linux/mmzone.h>
8518diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8519index 4aad413..85d86bf 100644
8520--- a/arch/powerpc/include/asm/pte-hash32.h
8521+++ b/arch/powerpc/include/asm/pte-hash32.h
8522@@ -21,6 +21,7 @@
8523 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8524 #define _PAGE_USER 0x004 /* usermode access allowed */
8525 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8526+#define _PAGE_EXEC _PAGE_GUARDED
8527 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8528 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8529 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8530diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8531index c998279..d13a9f8 100644
8532--- a/arch/powerpc/include/asm/reg.h
8533+++ b/arch/powerpc/include/asm/reg.h
8534@@ -251,6 +251,7 @@
8535 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8536 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8537 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8538+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8539 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8540 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8541 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8542diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8543index 5a6614a..d89995d1 100644
8544--- a/arch/powerpc/include/asm/smp.h
8545+++ b/arch/powerpc/include/asm/smp.h
8546@@ -51,7 +51,7 @@ struct smp_ops_t {
8547 int (*cpu_disable)(void);
8548 void (*cpu_die)(unsigned int nr);
8549 int (*cpu_bootable)(unsigned int nr);
8550-};
8551+} __no_const;
8552
8553 extern void smp_send_debugger_break(void);
8554 extern void start_secondary_resume(void);
8555diff --git a/arch/powerpc/include/asm/spinlock.h b/arch/powerpc/include/asm/spinlock.h
8556index 4dbe072..b803275 100644
8557--- a/arch/powerpc/include/asm/spinlock.h
8558+++ b/arch/powerpc/include/asm/spinlock.h
8559@@ -204,13 +204,29 @@ static inline long __arch_read_trylock(arch_rwlock_t *rw)
8560 __asm__ __volatile__(
8561 "1: " PPC_LWARX(%0,0,%1,1) "\n"
8562 __DO_SIGN_EXTEND
8563-" addic. %0,%0,1\n\
8564- ble- 2f\n"
8565+
8566+#ifdef CONFIG_PAX_REFCOUNT
8567+" mcrxr cr0\n"
8568+" addico. %0,%0,1\n"
8569+" bf 4*cr0+so, 3f\n"
8570+"2:.long " "0x00c00b00""\n"
8571+#else
8572+" addic. %0,%0,1\n"
8573+#endif
8574+
8575+"3:\n"
8576+ "ble- 4f\n"
8577 PPC405_ERR77(0,%1)
8578 " stwcx. %0,0,%1\n\
8579 bne- 1b\n"
8580 PPC_ACQUIRE_BARRIER
8581-"2:" : "=&r" (tmp)
8582+"4:"
8583+
8584+#ifdef CONFIG_PAX_REFCOUNT
8585+ _ASM_EXTABLE(2b,4b)
8586+#endif
8587+
8588+ : "=&r" (tmp)
8589 : "r" (&rw->lock)
8590 : "cr0", "xer", "memory");
8591
8592@@ -286,11 +302,27 @@ static inline void arch_read_unlock(arch_rwlock_t *rw)
8593 __asm__ __volatile__(
8594 "# read_unlock\n\t"
8595 PPC_RELEASE_BARRIER
8596-"1: lwarx %0,0,%1\n\
8597- addic %0,%0,-1\n"
8598+"1: lwarx %0,0,%1\n"
8599+
8600+#ifdef CONFIG_PAX_REFCOUNT
8601+" mcrxr cr0\n"
8602+" addico. %0,%0,-1\n"
8603+" bf 4*cr0+so, 3f\n"
8604+"2:.long " "0x00c00b00""\n"
8605+#else
8606+" addic. %0,%0,-1\n"
8607+#endif
8608+
8609+"3:\n"
8610 PPC405_ERR77(0,%1)
8611 " stwcx. %0,0,%1\n\
8612 bne- 1b"
8613+
8614+#ifdef CONFIG_PAX_REFCOUNT
8615+"\n4:\n"
8616+ _ASM_EXTABLE(2b, 4b)
8617+#endif
8618+
8619 : "=&r"(tmp)
8620 : "r"(&rw->lock)
8621 : "cr0", "xer", "memory");
8622diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8623index b034ecd..af7e31f 100644
8624--- a/arch/powerpc/include/asm/thread_info.h
8625+++ b/arch/powerpc/include/asm/thread_info.h
8626@@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
8627 #if defined(CONFIG_PPC64)
8628 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8629 #endif
8630+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8631+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
8632
8633 /* as above, but as bit values */
8634 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8635@@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
8636 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8637 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8638 #define _TIF_NOHZ (1<<TIF_NOHZ)
8639+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8640 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8641 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8642- _TIF_NOHZ)
8643+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
8644
8645 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8646 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
8647diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8648index 9485b43..3bd3c16 100644
8649--- a/arch/powerpc/include/asm/uaccess.h
8650+++ b/arch/powerpc/include/asm/uaccess.h
8651@@ -58,6 +58,7 @@
8652
8653 #endif
8654
8655+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8656 #define access_ok(type, addr, size) \
8657 (__chk_user_ptr(addr), \
8658 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8659@@ -318,52 +319,6 @@ do { \
8660 extern unsigned long __copy_tofrom_user(void __user *to,
8661 const void __user *from, unsigned long size);
8662
8663-#ifndef __powerpc64__
8664-
8665-static inline unsigned long copy_from_user(void *to,
8666- const void __user *from, unsigned long n)
8667-{
8668- unsigned long over;
8669-
8670- if (access_ok(VERIFY_READ, from, n))
8671- return __copy_tofrom_user((__force void __user *)to, from, n);
8672- if ((unsigned long)from < TASK_SIZE) {
8673- over = (unsigned long)from + n - TASK_SIZE;
8674- return __copy_tofrom_user((__force void __user *)to, from,
8675- n - over) + over;
8676- }
8677- return n;
8678-}
8679-
8680-static inline unsigned long copy_to_user(void __user *to,
8681- const void *from, unsigned long n)
8682-{
8683- unsigned long over;
8684-
8685- if (access_ok(VERIFY_WRITE, to, n))
8686- return __copy_tofrom_user(to, (__force void __user *)from, n);
8687- if ((unsigned long)to < TASK_SIZE) {
8688- over = (unsigned long)to + n - TASK_SIZE;
8689- return __copy_tofrom_user(to, (__force void __user *)from,
8690- n - over) + over;
8691- }
8692- return n;
8693-}
8694-
8695-#else /* __powerpc64__ */
8696-
8697-#define __copy_in_user(to, from, size) \
8698- __copy_tofrom_user((to), (from), (size))
8699-
8700-extern unsigned long copy_from_user(void *to, const void __user *from,
8701- unsigned long n);
8702-extern unsigned long copy_to_user(void __user *to, const void *from,
8703- unsigned long n);
8704-extern unsigned long copy_in_user(void __user *to, const void __user *from,
8705- unsigned long n);
8706-
8707-#endif /* __powerpc64__ */
8708-
8709 static inline unsigned long __copy_from_user_inatomic(void *to,
8710 const void __user *from, unsigned long n)
8711 {
8712@@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8713 if (ret == 0)
8714 return 0;
8715 }
8716+
8717+ if (!__builtin_constant_p(n))
8718+ check_object_size(to, n, false);
8719+
8720 return __copy_tofrom_user((__force void __user *)to, from, n);
8721 }
8722
8723@@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8724 if (ret == 0)
8725 return 0;
8726 }
8727+
8728+ if (!__builtin_constant_p(n))
8729+ check_object_size(from, n, true);
8730+
8731 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8732 }
8733
8734@@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8735 return __copy_to_user_inatomic(to, from, size);
8736 }
8737
8738+#ifndef __powerpc64__
8739+
8740+static inline unsigned long __must_check copy_from_user(void *to,
8741+ const void __user *from, unsigned long n)
8742+{
8743+ unsigned long over;
8744+
8745+ if ((long)n < 0)
8746+ return n;
8747+
8748+ if (access_ok(VERIFY_READ, from, n)) {
8749+ if (!__builtin_constant_p(n))
8750+ check_object_size(to, n, false);
8751+ return __copy_tofrom_user((__force void __user *)to, from, n);
8752+ }
8753+ if ((unsigned long)from < TASK_SIZE) {
8754+ over = (unsigned long)from + n - TASK_SIZE;
8755+ if (!__builtin_constant_p(n - over))
8756+ check_object_size(to, n - over, false);
8757+ return __copy_tofrom_user((__force void __user *)to, from,
8758+ n - over) + over;
8759+ }
8760+ return n;
8761+}
8762+
8763+static inline unsigned long __must_check copy_to_user(void __user *to,
8764+ const void *from, unsigned long n)
8765+{
8766+ unsigned long over;
8767+
8768+ if ((long)n < 0)
8769+ return n;
8770+
8771+ if (access_ok(VERIFY_WRITE, to, n)) {
8772+ if (!__builtin_constant_p(n))
8773+ check_object_size(from, n, true);
8774+ return __copy_tofrom_user(to, (__force void __user *)from, n);
8775+ }
8776+ if ((unsigned long)to < TASK_SIZE) {
8777+ over = (unsigned long)to + n - TASK_SIZE;
8778+ if (!__builtin_constant_p(n))
8779+ check_object_size(from, n - over, true);
8780+ return __copy_tofrom_user(to, (__force void __user *)from,
8781+ n - over) + over;
8782+ }
8783+ return n;
8784+}
8785+
8786+#else /* __powerpc64__ */
8787+
8788+#define __copy_in_user(to, from, size) \
8789+ __copy_tofrom_user((to), (from), (size))
8790+
8791+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8792+{
8793+ if ((long)n < 0 || n > INT_MAX)
8794+ return n;
8795+
8796+ if (!__builtin_constant_p(n))
8797+ check_object_size(to, n, false);
8798+
8799+ if (likely(access_ok(VERIFY_READ, from, n)))
8800+ n = __copy_from_user(to, from, n);
8801+ else
8802+ memset(to, 0, n);
8803+ return n;
8804+}
8805+
8806+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8807+{
8808+ if ((long)n < 0 || n > INT_MAX)
8809+ return n;
8810+
8811+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
8812+ if (!__builtin_constant_p(n))
8813+ check_object_size(from, n, true);
8814+ n = __copy_to_user(to, from, n);
8815+ }
8816+ return n;
8817+}
8818+
8819+extern unsigned long copy_in_user(void __user *to, const void __user *from,
8820+ unsigned long n);
8821+
8822+#endif /* __powerpc64__ */
8823+
8824 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8825
8826 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8827diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8828index 502cf69..822e63b 100644
8829--- a/arch/powerpc/kernel/Makefile
8830+++ b/arch/powerpc/kernel/Makefile
8831@@ -27,6 +27,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8832 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8833 endif
8834
8835+CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8836+
8837 obj-y := cputable.o ptrace.o syscalls.o \
8838 irq.o align.o signal_32.o pmc.o vdso.o \
8839 process.o systbl.o idle.o \
8840diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8841index 3e68d1c..72a5ee6 100644
8842--- a/arch/powerpc/kernel/exceptions-64e.S
8843+++ b/arch/powerpc/kernel/exceptions-64e.S
8844@@ -1010,6 +1010,7 @@ storage_fault_common:
8845 std r14,_DAR(r1)
8846 std r15,_DSISR(r1)
8847 addi r3,r1,STACK_FRAME_OVERHEAD
8848+ bl save_nvgprs
8849 mr r4,r14
8850 mr r5,r15
8851 ld r14,PACA_EXGEN+EX_R14(r13)
8852@@ -1018,8 +1019,7 @@ storage_fault_common:
8853 cmpdi r3,0
8854 bne- 1f
8855 b ret_from_except_lite
8856-1: bl save_nvgprs
8857- mr r5,r3
8858+1: mr r5,r3
8859 addi r3,r1,STACK_FRAME_OVERHEAD
8860 ld r4,_DAR(r1)
8861 bl bad_page_fault
8862diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8863index 72e783e..fe058e2 100644
8864--- a/arch/powerpc/kernel/exceptions-64s.S
8865+++ b/arch/powerpc/kernel/exceptions-64s.S
8866@@ -1588,10 +1588,10 @@ handle_page_fault:
8867 11: ld r4,_DAR(r1)
8868 ld r5,_DSISR(r1)
8869 addi r3,r1,STACK_FRAME_OVERHEAD
8870+ bl save_nvgprs
8871 bl do_page_fault
8872 cmpdi r3,0
8873 beq+ 12f
8874- bl save_nvgprs
8875 mr r5,r3
8876 addi r3,r1,STACK_FRAME_OVERHEAD
8877 lwz r4,_DAR(r1)
8878diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
8879index c143835..5a9697f 100644
8880--- a/arch/powerpc/kernel/irq.c
8881+++ b/arch/powerpc/kernel/irq.c
8882@@ -461,6 +461,8 @@ void migrate_irqs(void)
8883 }
8884 #endif
8885
8886+extern void gr_handle_kernel_exploit(void);
8887+
8888 static inline void check_stack_overflow(void)
8889 {
8890 #ifdef CONFIG_DEBUG_STACKOVERFLOW
8891@@ -473,6 +475,7 @@ static inline void check_stack_overflow(void)
8892 pr_err("do_IRQ: stack overflow: %ld\n",
8893 sp - sizeof(struct thread_info));
8894 dump_stack();
8895+ gr_handle_kernel_exploit();
8896 }
8897 #endif
8898 }
8899diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8900index c94d2e0..992a9ce 100644
8901--- a/arch/powerpc/kernel/module_32.c
8902+++ b/arch/powerpc/kernel/module_32.c
8903@@ -158,7 +158,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8904 me->arch.core_plt_section = i;
8905 }
8906 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8907- pr_err("Module doesn't contain .plt or .init.plt sections.\n");
8908+ pr_err("Module $s doesn't contain .plt or .init.plt sections.\n", me->name);
8909 return -ENOEXEC;
8910 }
8911
8912@@ -188,11 +188,16 @@ static uint32_t do_plt_call(void *location,
8913
8914 pr_debug("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8915 /* Init, or core PLT? */
8916- if (location >= mod->module_core
8917- && location < mod->module_core + mod->core_size)
8918+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8919+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8920 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8921- else
8922+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8923+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8924 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8925+ else {
8926+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8927+ return ~0UL;
8928+ }
8929
8930 /* Find this entry, or if that fails, the next avail. entry */
8931 while (entry->jump[0]) {
8932@@ -296,7 +301,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8933 }
8934 #ifdef CONFIG_DYNAMIC_FTRACE
8935 module->arch.tramp =
8936- do_plt_call(module->module_core,
8937+ do_plt_call(module->module_core_rx,
8938 (unsigned long)ftrace_caller,
8939 sechdrs, module);
8940 #endif
8941diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8942index 923cd2d..ae782a9 100644
8943--- a/arch/powerpc/kernel/process.c
8944+++ b/arch/powerpc/kernel/process.c
8945@@ -1040,8 +1040,8 @@ void show_regs(struct pt_regs * regs)
8946 * Lookup NIP late so we have the best change of getting the
8947 * above info out without failing
8948 */
8949- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8950- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8951+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8952+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8953 #endif
8954 show_stack(current, (unsigned long *) regs->gpr[1]);
8955 if (!user_mode(regs))
8956@@ -1560,10 +1560,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8957 newsp = stack[0];
8958 ip = stack[STACK_FRAME_LR_SAVE];
8959 if (!firstframe || ip != lr) {
8960- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8961+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8962 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8963 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8964- printk(" (%pS)",
8965+ printk(" (%pA)",
8966 (void *)current->ret_stack[curr_frame].ret);
8967 curr_frame--;
8968 }
8969@@ -1583,7 +1583,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8970 struct pt_regs *regs = (struct pt_regs *)
8971 (sp + STACK_FRAME_OVERHEAD);
8972 lr = regs->link;
8973- printk("--- interrupt: %lx at %pS\n LR = %pS\n",
8974+ printk("--- interrupt: %lx at %pA\n LR = %pA\n",
8975 regs->trap, (void *)regs->nip, (void *)lr);
8976 firstframe = 1;
8977 }
8978@@ -1619,58 +1619,3 @@ void notrace __ppc64_runlatch_off(void)
8979 mtspr(SPRN_CTRLT, ctrl);
8980 }
8981 #endif /* CONFIG_PPC64 */
8982-
8983-unsigned long arch_align_stack(unsigned long sp)
8984-{
8985- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8986- sp -= get_random_int() & ~PAGE_MASK;
8987- return sp & ~0xf;
8988-}
8989-
8990-static inline unsigned long brk_rnd(void)
8991-{
8992- unsigned long rnd = 0;
8993-
8994- /* 8MB for 32bit, 1GB for 64bit */
8995- if (is_32bit_task())
8996- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8997- else
8998- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8999-
9000- return rnd << PAGE_SHIFT;
9001-}
9002-
9003-unsigned long arch_randomize_brk(struct mm_struct *mm)
9004-{
9005- unsigned long base = mm->brk;
9006- unsigned long ret;
9007-
9008-#ifdef CONFIG_PPC_STD_MMU_64
9009- /*
9010- * If we are using 1TB segments and we are allowed to randomise
9011- * the heap, we can put it above 1TB so it is backed by a 1TB
9012- * segment. Otherwise the heap will be in the bottom 1TB
9013- * which always uses 256MB segments and this may result in a
9014- * performance penalty.
9015- */
9016- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
9017- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
9018-#endif
9019-
9020- ret = PAGE_ALIGN(base + brk_rnd());
9021-
9022- if (ret < mm->brk)
9023- return mm->brk;
9024-
9025- return ret;
9026-}
9027-
9028-unsigned long randomize_et_dyn(unsigned long base)
9029-{
9030- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
9031-
9032- if (ret < base)
9033- return base;
9034-
9035- return ret;
9036-}
9037diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
9038index f21897b..28c0428 100644
9039--- a/arch/powerpc/kernel/ptrace.c
9040+++ b/arch/powerpc/kernel/ptrace.c
9041@@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
9042 return ret;
9043 }
9044
9045+#ifdef CONFIG_GRKERNSEC_SETXID
9046+extern void gr_delayed_cred_worker(void);
9047+#endif
9048+
9049 /*
9050 * We must return the syscall number to actually look up in the table.
9051 * This can be -1L to skip running any syscall at all.
9052@@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
9053
9054 secure_computing_strict(regs->gpr[0]);
9055
9056+#ifdef CONFIG_GRKERNSEC_SETXID
9057+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9058+ gr_delayed_cred_worker();
9059+#endif
9060+
9061 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
9062 tracehook_report_syscall_entry(regs))
9063 /*
9064@@ -1805,6 +1814,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
9065 {
9066 int step;
9067
9068+#ifdef CONFIG_GRKERNSEC_SETXID
9069+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9070+ gr_delayed_cred_worker();
9071+#endif
9072+
9073 audit_syscall_exit(regs);
9074
9075 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9076diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
9077index b171001..4ac7ac5 100644
9078--- a/arch/powerpc/kernel/signal_32.c
9079+++ b/arch/powerpc/kernel/signal_32.c
9080@@ -1011,7 +1011,7 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,
9081 /* Save user registers on the stack */
9082 frame = &rt_sf->uc.uc_mcontext;
9083 addr = frame;
9084- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
9085+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9086 sigret = 0;
9087 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
9088 } else {
9089diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
9090index 2cb0c94..c0c0bc9 100644
9091--- a/arch/powerpc/kernel/signal_64.c
9092+++ b/arch/powerpc/kernel/signal_64.c
9093@@ -754,7 +754,7 @@ int handle_rt_signal64(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs
9094 current->thread.fp_state.fpscr = 0;
9095
9096 /* Set up to return from userspace. */
9097- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
9098+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9099 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
9100 } else {
9101 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
9102diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
9103index 0dc43f9..a885d33 100644
9104--- a/arch/powerpc/kernel/traps.c
9105+++ b/arch/powerpc/kernel/traps.c
9106@@ -36,6 +36,7 @@
9107 #include <linux/debugfs.h>
9108 #include <linux/ratelimit.h>
9109 #include <linux/context_tracking.h>
9110+#include <linux/uaccess.h>
9111
9112 #include <asm/emulated_ops.h>
9113 #include <asm/pgtable.h>
9114@@ -142,6 +143,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
9115 return flags;
9116 }
9117
9118+extern void gr_handle_kernel_exploit(void);
9119+
9120 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9121 int signr)
9122 {
9123@@ -191,6 +194,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9124 panic("Fatal exception in interrupt");
9125 if (panic_on_oops)
9126 panic("Fatal exception");
9127+
9128+ gr_handle_kernel_exploit();
9129+
9130 do_exit(signr);
9131 }
9132
9133@@ -1137,6 +1143,26 @@ void __kprobes program_check_exception(struct pt_regs *regs)
9134 enum ctx_state prev_state = exception_enter();
9135 unsigned int reason = get_reason(regs);
9136
9137+#ifdef CONFIG_PAX_REFCOUNT
9138+ unsigned int bkpt;
9139+ const struct exception_table_entry *entry;
9140+
9141+ if (reason & REASON_ILLEGAL) {
9142+ /* Check if PaX bad instruction */
9143+ if (!probe_kernel_address(regs->nip, bkpt) && bkpt == 0xc00b00) {
9144+ current->thread.trap_nr = 0;
9145+ pax_report_refcount_overflow(regs);
9146+ /* fixup_exception() for PowerPC does not exist, simulate its job */
9147+ if ((entry = search_exception_tables(regs->nip)) != NULL) {
9148+ regs->nip = entry->fixup;
9149+ return;
9150+ }
9151+ /* fixup_exception() could not handle */
9152+ goto bail;
9153+ }
9154+ }
9155+#endif
9156+
9157 /* We can now get here via a FP Unavailable exception if the core
9158 * has no FPU, in that case the reason flags will be 0 */
9159
9160diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
9161index f174351..5722009 100644
9162--- a/arch/powerpc/kernel/vdso.c
9163+++ b/arch/powerpc/kernel/vdso.c
9164@@ -35,6 +35,7 @@
9165 #include <asm/vdso.h>
9166 #include <asm/vdso_datapage.h>
9167 #include <asm/setup.h>
9168+#include <asm/mman.h>
9169
9170 #undef DEBUG
9171
9172@@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9173 vdso_base = VDSO32_MBASE;
9174 #endif
9175
9176- current->mm->context.vdso_base = 0;
9177+ current->mm->context.vdso_base = ~0UL;
9178
9179 /* vDSO has a problem and was disabled, just don't "enable" it for the
9180 * process
9181@@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9182 vdso_base = get_unmapped_area(NULL, vdso_base,
9183 (vdso_pages << PAGE_SHIFT) +
9184 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
9185- 0, 0);
9186+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
9187 if (IS_ERR_VALUE(vdso_base)) {
9188 rc = vdso_base;
9189 goto fail_mmapsem;
9190diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
9191index c1f8f53..71a3b96 100644
9192--- a/arch/powerpc/kvm/powerpc.c
9193+++ b/arch/powerpc/kvm/powerpc.c
9194@@ -1409,7 +1409,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
9195 }
9196 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
9197
9198-int kvm_arch_init(void *opaque)
9199+int kvm_arch_init(const void *opaque)
9200 {
9201 return 0;
9202 }
9203diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
9204index 5eea6f3..5d10396 100644
9205--- a/arch/powerpc/lib/usercopy_64.c
9206+++ b/arch/powerpc/lib/usercopy_64.c
9207@@ -9,22 +9,6 @@
9208 #include <linux/module.h>
9209 #include <asm/uaccess.h>
9210
9211-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9212-{
9213- if (likely(access_ok(VERIFY_READ, from, n)))
9214- n = __copy_from_user(to, from, n);
9215- else
9216- memset(to, 0, n);
9217- return n;
9218-}
9219-
9220-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9221-{
9222- if (likely(access_ok(VERIFY_WRITE, to, n)))
9223- n = __copy_to_user(to, from, n);
9224- return n;
9225-}
9226-
9227 unsigned long copy_in_user(void __user *to, const void __user *from,
9228 unsigned long n)
9229 {
9230@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
9231 return n;
9232 }
9233
9234-EXPORT_SYMBOL(copy_from_user);
9235-EXPORT_SYMBOL(copy_to_user);
9236 EXPORT_SYMBOL(copy_in_user);
9237
9238diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
9239index 08d659a..ab329f4 100644
9240--- a/arch/powerpc/mm/fault.c
9241+++ b/arch/powerpc/mm/fault.c
9242@@ -33,6 +33,10 @@
9243 #include <linux/ratelimit.h>
9244 #include <linux/context_tracking.h>
9245 #include <linux/hugetlb.h>
9246+#include <linux/slab.h>
9247+#include <linux/pagemap.h>
9248+#include <linux/compiler.h>
9249+#include <linux/unistd.h>
9250
9251 #include <asm/firmware.h>
9252 #include <asm/page.h>
9253@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
9254 }
9255 #endif
9256
9257+#ifdef CONFIG_PAX_PAGEEXEC
9258+/*
9259+ * PaX: decide what to do with offenders (regs->nip = fault address)
9260+ *
9261+ * returns 1 when task should be killed
9262+ */
9263+static int pax_handle_fetch_fault(struct pt_regs *regs)
9264+{
9265+ return 1;
9266+}
9267+
9268+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9269+{
9270+ unsigned long i;
9271+
9272+ printk(KERN_ERR "PAX: bytes at PC: ");
9273+ for (i = 0; i < 5; i++) {
9274+ unsigned int c;
9275+ if (get_user(c, (unsigned int __user *)pc+i))
9276+ printk(KERN_CONT "???????? ");
9277+ else
9278+ printk(KERN_CONT "%08x ", c);
9279+ }
9280+ printk("\n");
9281+}
9282+#endif
9283+
9284 /*
9285 * Check whether the instruction at regs->nip is a store using
9286 * an update addressing form which will update r1.
9287@@ -228,7 +259,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
9288 * indicate errors in DSISR but can validly be set in SRR1.
9289 */
9290 if (trap == 0x400)
9291- error_code &= 0x48200000;
9292+ error_code &= 0x58200000;
9293 else
9294 is_write = error_code & DSISR_ISSTORE;
9295 #else
9296@@ -390,7 +421,7 @@ good_area:
9297 * "undefined". Of those that can be set, this is the only
9298 * one which seems bad.
9299 */
9300- if (error_code & 0x10000000)
9301+ if (error_code & DSISR_GUARDED)
9302 /* Guarded storage error. */
9303 goto bad_area;
9304 #endif /* CONFIG_8xx */
9305@@ -405,7 +436,7 @@ good_area:
9306 * processors use the same I/D cache coherency mechanism
9307 * as embedded.
9308 */
9309- if (error_code & DSISR_PROTFAULT)
9310+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
9311 goto bad_area;
9312 #endif /* CONFIG_PPC_STD_MMU */
9313
9314@@ -495,6 +526,23 @@ bad_area:
9315 bad_area_nosemaphore:
9316 /* User mode accesses cause a SIGSEGV */
9317 if (user_mode(regs)) {
9318+
9319+#ifdef CONFIG_PAX_PAGEEXEC
9320+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
9321+#ifdef CONFIG_PPC_STD_MMU
9322+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
9323+#else
9324+ if (is_exec && regs->nip == address) {
9325+#endif
9326+ switch (pax_handle_fetch_fault(regs)) {
9327+ }
9328+
9329+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
9330+ do_group_exit(SIGKILL);
9331+ }
9332+ }
9333+#endif
9334+
9335 _exception(SIGSEGV, regs, code, address);
9336 goto bail;
9337 }
9338diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
9339index cb8bdbe..cde4bc7 100644
9340--- a/arch/powerpc/mm/mmap.c
9341+++ b/arch/powerpc/mm/mmap.c
9342@@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
9343 return sysctl_legacy_va_layout;
9344 }
9345
9346-static unsigned long mmap_rnd(void)
9347+static unsigned long mmap_rnd(struct mm_struct *mm)
9348 {
9349 unsigned long rnd = 0;
9350
9351+#ifdef CONFIG_PAX_RANDMMAP
9352+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9353+#endif
9354+
9355 if (current->flags & PF_RANDOMIZE) {
9356 /* 8MB for 32bit, 1GB for 64bit */
9357 if (is_32bit_task())
9358@@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
9359 return rnd << PAGE_SHIFT;
9360 }
9361
9362-static inline unsigned long mmap_base(void)
9363+static inline unsigned long mmap_base(struct mm_struct *mm)
9364 {
9365 unsigned long gap = rlimit(RLIMIT_STACK);
9366
9367@@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
9368 else if (gap > MAX_GAP)
9369 gap = MAX_GAP;
9370
9371- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
9372+ return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
9373 }
9374
9375 /*
9376@@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9377 */
9378 if (mmap_is_legacy()) {
9379 mm->mmap_base = TASK_UNMAPPED_BASE;
9380+
9381+#ifdef CONFIG_PAX_RANDMMAP
9382+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9383+ mm->mmap_base += mm->delta_mmap;
9384+#endif
9385+
9386 mm->get_unmapped_area = arch_get_unmapped_area;
9387 } else {
9388- mm->mmap_base = mmap_base();
9389+ mm->mmap_base = mmap_base(mm);
9390+
9391+#ifdef CONFIG_PAX_RANDMMAP
9392+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9393+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9394+#endif
9395+
9396 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9397 }
9398 }
9399diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
9400index ded0ea1..f213a9b 100644
9401--- a/arch/powerpc/mm/slice.c
9402+++ b/arch/powerpc/mm/slice.c
9403@@ -105,7 +105,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
9404 if ((mm->task_size - len) < addr)
9405 return 0;
9406 vma = find_vma(mm, addr);
9407- return (!vma || (addr + len) <= vma->vm_start);
9408+ return check_heap_stack_gap(vma, addr, len, 0);
9409 }
9410
9411 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
9412@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
9413 info.align_offset = 0;
9414
9415 addr = TASK_UNMAPPED_BASE;
9416+
9417+#ifdef CONFIG_PAX_RANDMMAP
9418+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9419+ addr += mm->delta_mmap;
9420+#endif
9421+
9422 while (addr < TASK_SIZE) {
9423 info.low_limit = addr;
9424 if (!slice_scan_available(addr, available, 1, &addr))
9425@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
9426 if (fixed && addr > (mm->task_size - len))
9427 return -ENOMEM;
9428
9429+#ifdef CONFIG_PAX_RANDMMAP
9430+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
9431+ addr = 0;
9432+#endif
9433+
9434 /* If hint, make sure it matches our alignment restrictions */
9435 if (!fixed && addr) {
9436 addr = _ALIGN_UP(addr, 1ul << pshift);
9437diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9438index 4278acf..67fd0e6 100644
9439--- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9440+++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9441@@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
9442 }
9443
9444 static struct pci_ops scc_pciex_pci_ops = {
9445- scc_pciex_read_config,
9446- scc_pciex_write_config,
9447+ .read = scc_pciex_read_config,
9448+ .write = scc_pciex_write_config,
9449 };
9450
9451 static void pciex_clear_intr_all(unsigned int __iomem *base)
9452diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
9453index d966bbe..372124a 100644
9454--- a/arch/powerpc/platforms/cell/spufs/file.c
9455+++ b/arch/powerpc/platforms/cell/spufs/file.c
9456@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9457 return VM_FAULT_NOPAGE;
9458 }
9459
9460-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
9461+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
9462 unsigned long address,
9463- void *buf, int len, int write)
9464+ void *buf, size_t len, int write)
9465 {
9466 struct spu_context *ctx = vma->vm_file->private_data;
9467 unsigned long offset = address - vma->vm_start;
9468diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
9469index fa934fe..c296056 100644
9470--- a/arch/s390/include/asm/atomic.h
9471+++ b/arch/s390/include/asm/atomic.h
9472@@ -412,4 +412,14 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
9473 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
9474 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9475
9476+#define atomic64_read_unchecked(v) atomic64_read(v)
9477+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9478+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9479+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9480+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9481+#define atomic64_inc_unchecked(v) atomic64_inc(v)
9482+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9483+#define atomic64_dec_unchecked(v) atomic64_dec(v)
9484+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9485+
9486 #endif /* __ARCH_S390_ATOMIC__ */
9487diff --git a/arch/s390/include/asm/barrier.h b/arch/s390/include/asm/barrier.h
9488index b5dce65..8aca09a 100644
9489--- a/arch/s390/include/asm/barrier.h
9490+++ b/arch/s390/include/asm/barrier.h
9491@@ -39,7 +39,7 @@
9492 do { \
9493 compiletime_assert_atomic_type(*p); \
9494 barrier(); \
9495- ACCESS_ONCE(*p) = (v); \
9496+ ACCESS_ONCE_RW(*p) = (v); \
9497 } while (0)
9498
9499 #define smp_load_acquire(p) \
9500diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
9501index 4d7ccac..d03d0ad 100644
9502--- a/arch/s390/include/asm/cache.h
9503+++ b/arch/s390/include/asm/cache.h
9504@@ -9,8 +9,10 @@
9505 #ifndef __ARCH_S390_CACHE_H
9506 #define __ARCH_S390_CACHE_H
9507
9508-#define L1_CACHE_BYTES 256
9509+#include <linux/const.h>
9510+
9511 #define L1_CACHE_SHIFT 8
9512+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9513 #define NET_SKB_PAD 32
9514
9515 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9516diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
9517index f6e43d3..5f57681 100644
9518--- a/arch/s390/include/asm/elf.h
9519+++ b/arch/s390/include/asm/elf.h
9520@@ -163,8 +163,14 @@ extern unsigned int vdso_enabled;
9521 the loader. We need to make sure that it is out of the way of the program
9522 that it will "exec", and that there is sufficient room for the brk. */
9523
9524-extern unsigned long randomize_et_dyn(unsigned long base);
9525-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9526+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9527+
9528+#ifdef CONFIG_PAX_ASLR
9529+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9530+
9531+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9532+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9533+#endif
9534
9535 /* This yields a mask that user programs can use to figure out what
9536 instruction set this CPU supports. */
9537@@ -223,9 +229,6 @@ struct linux_binprm;
9538 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9539 int arch_setup_additional_pages(struct linux_binprm *, int);
9540
9541-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9542-#define arch_randomize_brk arch_randomize_brk
9543-
9544 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa, __vector128 *vxrs);
9545
9546 #endif
9547diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9548index c4a93d6..4d2a9b4 100644
9549--- a/arch/s390/include/asm/exec.h
9550+++ b/arch/s390/include/asm/exec.h
9551@@ -7,6 +7,6 @@
9552 #ifndef __ASM_EXEC_H
9553 #define __ASM_EXEC_H
9554
9555-extern unsigned long arch_align_stack(unsigned long sp);
9556+#define arch_align_stack(x) ((x) & ~0xfUL)
9557
9558 #endif /* __ASM_EXEC_H */
9559diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9560index cd4c68e..6764641 100644
9561--- a/arch/s390/include/asm/uaccess.h
9562+++ b/arch/s390/include/asm/uaccess.h
9563@@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9564 __range_ok((unsigned long)(addr), (size)); \
9565 })
9566
9567+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9568 #define access_ok(type, addr, size) __access_ok(addr, size)
9569
9570 /*
9571@@ -275,6 +276,10 @@ static inline unsigned long __must_check
9572 copy_to_user(void __user *to, const void *from, unsigned long n)
9573 {
9574 might_fault();
9575+
9576+ if ((long)n < 0)
9577+ return n;
9578+
9579 return __copy_to_user(to, from, n);
9580 }
9581
9582@@ -303,10 +308,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9583 static inline unsigned long __must_check
9584 copy_from_user(void *to, const void __user *from, unsigned long n)
9585 {
9586- unsigned int sz = __compiletime_object_size(to);
9587+ size_t sz = __compiletime_object_size(to);
9588
9589 might_fault();
9590- if (unlikely(sz != -1 && sz < n)) {
9591+
9592+ if ((long)n < 0)
9593+ return n;
9594+
9595+ if (unlikely(sz != (size_t)-1 && sz < n)) {
9596 copy_from_user_overflow();
9597 return n;
9598 }
9599diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9600index b89b591..fd9609d 100644
9601--- a/arch/s390/kernel/module.c
9602+++ b/arch/s390/kernel/module.c
9603@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9604
9605 /* Increase core size by size of got & plt and set start
9606 offsets for got and plt. */
9607- me->core_size = ALIGN(me->core_size, 4);
9608- me->arch.got_offset = me->core_size;
9609- me->core_size += me->arch.got_size;
9610- me->arch.plt_offset = me->core_size;
9611- me->core_size += me->arch.plt_size;
9612+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
9613+ me->arch.got_offset = me->core_size_rw;
9614+ me->core_size_rw += me->arch.got_size;
9615+ me->arch.plt_offset = me->core_size_rx;
9616+ me->core_size_rx += me->arch.plt_size;
9617 return 0;
9618 }
9619
9620@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9621 if (info->got_initialized == 0) {
9622 Elf_Addr *gotent;
9623
9624- gotent = me->module_core + me->arch.got_offset +
9625+ gotent = me->module_core_rw + me->arch.got_offset +
9626 info->got_offset;
9627 *gotent = val;
9628 info->got_initialized = 1;
9629@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9630 rc = apply_rela_bits(loc, val, 0, 64, 0);
9631 else if (r_type == R_390_GOTENT ||
9632 r_type == R_390_GOTPLTENT) {
9633- val += (Elf_Addr) me->module_core - loc;
9634+ val += (Elf_Addr) me->module_core_rw - loc;
9635 rc = apply_rela_bits(loc, val, 1, 32, 1);
9636 }
9637 break;
9638@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9639 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9640 if (info->plt_initialized == 0) {
9641 unsigned int *ip;
9642- ip = me->module_core + me->arch.plt_offset +
9643+ ip = me->module_core_rx + me->arch.plt_offset +
9644 info->plt_offset;
9645 #ifndef CONFIG_64BIT
9646 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9647@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9648 val - loc + 0xffffUL < 0x1ffffeUL) ||
9649 (r_type == R_390_PLT32DBL &&
9650 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9651- val = (Elf_Addr) me->module_core +
9652+ val = (Elf_Addr) me->module_core_rx +
9653 me->arch.plt_offset +
9654 info->plt_offset;
9655 val += rela->r_addend - loc;
9656@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9657 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9658 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9659 val = val + rela->r_addend -
9660- ((Elf_Addr) me->module_core + me->arch.got_offset);
9661+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9662 if (r_type == R_390_GOTOFF16)
9663 rc = apply_rela_bits(loc, val, 0, 16, 0);
9664 else if (r_type == R_390_GOTOFF32)
9665@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9666 break;
9667 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9668 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9669- val = (Elf_Addr) me->module_core + me->arch.got_offset +
9670+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9671 rela->r_addend - loc;
9672 if (r_type == R_390_GOTPC)
9673 rc = apply_rela_bits(loc, val, 1, 32, 0);
9674diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9675index ed84cc2..c05a9d2 100644
9676--- a/arch/s390/kernel/process.c
9677+++ b/arch/s390/kernel/process.c
9678@@ -218,37 +218,3 @@ unsigned long get_wchan(struct task_struct *p)
9679 }
9680 return 0;
9681 }
9682-
9683-unsigned long arch_align_stack(unsigned long sp)
9684-{
9685- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9686- sp -= get_random_int() & ~PAGE_MASK;
9687- return sp & ~0xf;
9688-}
9689-
9690-static inline unsigned long brk_rnd(void)
9691-{
9692- /* 8MB for 32bit, 1GB for 64bit */
9693- if (is_32bit_task())
9694- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9695- else
9696- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9697-}
9698-
9699-unsigned long arch_randomize_brk(struct mm_struct *mm)
9700-{
9701- unsigned long ret;
9702-
9703- ret = PAGE_ALIGN(mm->brk + brk_rnd());
9704- return (ret > mm->brk) ? ret : mm->brk;
9705-}
9706-
9707-unsigned long randomize_et_dyn(unsigned long base)
9708-{
9709- unsigned long ret;
9710-
9711- if (!(current->flags & PF_RANDOMIZE))
9712- return base;
9713- ret = PAGE_ALIGN(base + brk_rnd());
9714- return (ret > base) ? ret : base;
9715-}
9716diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9717index 9b436c2..54fbf0a 100644
9718--- a/arch/s390/mm/mmap.c
9719+++ b/arch/s390/mm/mmap.c
9720@@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9721 */
9722 if (mmap_is_legacy()) {
9723 mm->mmap_base = mmap_base_legacy();
9724+
9725+#ifdef CONFIG_PAX_RANDMMAP
9726+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9727+ mm->mmap_base += mm->delta_mmap;
9728+#endif
9729+
9730 mm->get_unmapped_area = arch_get_unmapped_area;
9731 } else {
9732 mm->mmap_base = mmap_base();
9733+
9734+#ifdef CONFIG_PAX_RANDMMAP
9735+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9736+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9737+#endif
9738+
9739 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9740 }
9741 }
9742@@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9743 */
9744 if (mmap_is_legacy()) {
9745 mm->mmap_base = mmap_base_legacy();
9746+
9747+#ifdef CONFIG_PAX_RANDMMAP
9748+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9749+ mm->mmap_base += mm->delta_mmap;
9750+#endif
9751+
9752 mm->get_unmapped_area = s390_get_unmapped_area;
9753 } else {
9754 mm->mmap_base = mmap_base();
9755+
9756+#ifdef CONFIG_PAX_RANDMMAP
9757+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9758+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9759+#endif
9760+
9761 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9762 }
9763 }
9764diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9765index ae3d59f..f65f075 100644
9766--- a/arch/score/include/asm/cache.h
9767+++ b/arch/score/include/asm/cache.h
9768@@ -1,7 +1,9 @@
9769 #ifndef _ASM_SCORE_CACHE_H
9770 #define _ASM_SCORE_CACHE_H
9771
9772+#include <linux/const.h>
9773+
9774 #define L1_CACHE_SHIFT 4
9775-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9776+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9777
9778 #endif /* _ASM_SCORE_CACHE_H */
9779diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9780index f9f3cd5..58ff438 100644
9781--- a/arch/score/include/asm/exec.h
9782+++ b/arch/score/include/asm/exec.h
9783@@ -1,6 +1,6 @@
9784 #ifndef _ASM_SCORE_EXEC_H
9785 #define _ASM_SCORE_EXEC_H
9786
9787-extern unsigned long arch_align_stack(unsigned long sp);
9788+#define arch_align_stack(x) (x)
9789
9790 #endif /* _ASM_SCORE_EXEC_H */
9791diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9792index a1519ad3..e8ac1ff 100644
9793--- a/arch/score/kernel/process.c
9794+++ b/arch/score/kernel/process.c
9795@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9796
9797 return task_pt_regs(task)->cp0_epc;
9798 }
9799-
9800-unsigned long arch_align_stack(unsigned long sp)
9801-{
9802- return sp;
9803-}
9804diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9805index ef9e555..331bd29 100644
9806--- a/arch/sh/include/asm/cache.h
9807+++ b/arch/sh/include/asm/cache.h
9808@@ -9,10 +9,11 @@
9809 #define __ASM_SH_CACHE_H
9810 #ifdef __KERNEL__
9811
9812+#include <linux/const.h>
9813 #include <linux/init.h>
9814 #include <cpu/cache.h>
9815
9816-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9817+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9818
9819 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9820
9821diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9822index 6777177..cb5e44f 100644
9823--- a/arch/sh/mm/mmap.c
9824+++ b/arch/sh/mm/mmap.c
9825@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9826 struct mm_struct *mm = current->mm;
9827 struct vm_area_struct *vma;
9828 int do_colour_align;
9829+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9830 struct vm_unmapped_area_info info;
9831
9832 if (flags & MAP_FIXED) {
9833@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9834 if (filp || (flags & MAP_SHARED))
9835 do_colour_align = 1;
9836
9837+#ifdef CONFIG_PAX_RANDMMAP
9838+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9839+#endif
9840+
9841 if (addr) {
9842 if (do_colour_align)
9843 addr = COLOUR_ALIGN(addr, pgoff);
9844@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9845 addr = PAGE_ALIGN(addr);
9846
9847 vma = find_vma(mm, addr);
9848- if (TASK_SIZE - len >= addr &&
9849- (!vma || addr + len <= vma->vm_start))
9850+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9851 return addr;
9852 }
9853
9854 info.flags = 0;
9855 info.length = len;
9856- info.low_limit = TASK_UNMAPPED_BASE;
9857+ info.low_limit = mm->mmap_base;
9858 info.high_limit = TASK_SIZE;
9859 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9860 info.align_offset = pgoff << PAGE_SHIFT;
9861@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9862 struct mm_struct *mm = current->mm;
9863 unsigned long addr = addr0;
9864 int do_colour_align;
9865+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9866 struct vm_unmapped_area_info info;
9867
9868 if (flags & MAP_FIXED) {
9869@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9870 if (filp || (flags & MAP_SHARED))
9871 do_colour_align = 1;
9872
9873+#ifdef CONFIG_PAX_RANDMMAP
9874+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9875+#endif
9876+
9877 /* requesting a specific address */
9878 if (addr) {
9879 if (do_colour_align)
9880@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9881 addr = PAGE_ALIGN(addr);
9882
9883 vma = find_vma(mm, addr);
9884- if (TASK_SIZE - len >= addr &&
9885- (!vma || addr + len <= vma->vm_start))
9886+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9887 return addr;
9888 }
9889
9890@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9891 VM_BUG_ON(addr != -ENOMEM);
9892 info.flags = 0;
9893 info.low_limit = TASK_UNMAPPED_BASE;
9894+
9895+#ifdef CONFIG_PAX_RANDMMAP
9896+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9897+ info.low_limit += mm->delta_mmap;
9898+#endif
9899+
9900 info.high_limit = TASK_SIZE;
9901 addr = vm_unmapped_area(&info);
9902 }
9903diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9904index 4082749..fd97781 100644
9905--- a/arch/sparc/include/asm/atomic_64.h
9906+++ b/arch/sparc/include/asm/atomic_64.h
9907@@ -15,18 +15,38 @@
9908 #define ATOMIC64_INIT(i) { (i) }
9909
9910 #define atomic_read(v) ACCESS_ONCE((v)->counter)
9911+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9912+{
9913+ return ACCESS_ONCE(v->counter);
9914+}
9915 #define atomic64_read(v) ACCESS_ONCE((v)->counter)
9916+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9917+{
9918+ return ACCESS_ONCE(v->counter);
9919+}
9920
9921 #define atomic_set(v, i) (((v)->counter) = i)
9922+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9923+{
9924+ v->counter = i;
9925+}
9926 #define atomic64_set(v, i) (((v)->counter) = i)
9927+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9928+{
9929+ v->counter = i;
9930+}
9931
9932-#define ATOMIC_OP(op) \
9933-void atomic_##op(int, atomic_t *); \
9934-void atomic64_##op(long, atomic64_t *);
9935+#define __ATOMIC_OP(op, suffix) \
9936+void atomic_##op##suffix(int, atomic##suffix##_t *); \
9937+void atomic64_##op##suffix(long, atomic64##suffix##_t *);
9938
9939-#define ATOMIC_OP_RETURN(op) \
9940-int atomic_##op##_return(int, atomic_t *); \
9941-long atomic64_##op##_return(long, atomic64_t *);
9942+#define ATOMIC_OP(op) __ATOMIC_OP(op, ) __ATOMIC_OP(op, _unchecked)
9943+
9944+#define __ATOMIC_OP_RETURN(op, suffix) \
9945+int atomic_##op##_return##suffix(int, atomic##suffix##_t *); \
9946+long atomic64_##op##_return##suffix(long, atomic64##suffix##_t *);
9947+
9948+#define ATOMIC_OP_RETURN(op) __ATOMIC_OP_RETURN(op, ) __ATOMIC_OP_RETURN(op, _unchecked)
9949
9950 #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op)
9951
9952@@ -35,13 +55,23 @@ ATOMIC_OPS(sub)
9953
9954 #undef ATOMIC_OPS
9955 #undef ATOMIC_OP_RETURN
9956+#undef __ATOMIC_OP_RETURN
9957 #undef ATOMIC_OP
9958+#undef __ATOMIC_OP
9959
9960 #define atomic_dec_return(v) atomic_sub_return(1, v)
9961 #define atomic64_dec_return(v) atomic64_sub_return(1, v)
9962
9963 #define atomic_inc_return(v) atomic_add_return(1, v)
9964+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9965+{
9966+ return atomic_add_return_unchecked(1, v);
9967+}
9968 #define atomic64_inc_return(v) atomic64_add_return(1, v)
9969+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9970+{
9971+ return atomic64_add_return_unchecked(1, v);
9972+}
9973
9974 /*
9975 * atomic_inc_and_test - increment and test
9976@@ -52,6 +82,10 @@ ATOMIC_OPS(sub)
9977 * other cases.
9978 */
9979 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9980+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9981+{
9982+ return atomic_inc_return_unchecked(v) == 0;
9983+}
9984 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9985
9986 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
9987@@ -61,25 +95,60 @@ ATOMIC_OPS(sub)
9988 #define atomic64_dec_and_test(v) (atomic64_sub_return(1, v) == 0)
9989
9990 #define atomic_inc(v) atomic_add(1, v)
9991+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9992+{
9993+ atomic_add_unchecked(1, v);
9994+}
9995 #define atomic64_inc(v) atomic64_add(1, v)
9996+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9997+{
9998+ atomic64_add_unchecked(1, v);
9999+}
10000
10001 #define atomic_dec(v) atomic_sub(1, v)
10002+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
10003+{
10004+ atomic_sub_unchecked(1, v);
10005+}
10006 #define atomic64_dec(v) atomic64_sub(1, v)
10007+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
10008+{
10009+ atomic64_sub_unchecked(1, v);
10010+}
10011
10012 #define atomic_add_negative(i, v) (atomic_add_return(i, v) < 0)
10013 #define atomic64_add_negative(i, v) (atomic64_add_return(i, v) < 0)
10014
10015 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
10016+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
10017+{
10018+ return cmpxchg(&v->counter, old, new);
10019+}
10020 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
10021+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
10022+{
10023+ return xchg(&v->counter, new);
10024+}
10025
10026 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10027 {
10028- int c, old;
10029+ int c, old, new;
10030 c = atomic_read(v);
10031 for (;;) {
10032- if (unlikely(c == (u)))
10033+ if (unlikely(c == u))
10034 break;
10035- old = atomic_cmpxchg((v), c, c + (a));
10036+
10037+ asm volatile("addcc %2, %0, %0\n"
10038+
10039+#ifdef CONFIG_PAX_REFCOUNT
10040+ "tvs %%icc, 6\n"
10041+#endif
10042+
10043+ : "=r" (new)
10044+ : "0" (c), "ir" (a)
10045+ : "cc");
10046+
10047+ old = atomic_cmpxchg(v, c, new);
10048 if (likely(old == c))
10049 break;
10050 c = old;
10051@@ -90,20 +159,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10052 #define atomic64_cmpxchg(v, o, n) \
10053 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
10054 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
10055+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
10056+{
10057+ return xchg(&v->counter, new);
10058+}
10059
10060 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
10061 {
10062- long c, old;
10063+ long c, old, new;
10064 c = atomic64_read(v);
10065 for (;;) {
10066- if (unlikely(c == (u)))
10067+ if (unlikely(c == u))
10068 break;
10069- old = atomic64_cmpxchg((v), c, c + (a));
10070+
10071+ asm volatile("addcc %2, %0, %0\n"
10072+
10073+#ifdef CONFIG_PAX_REFCOUNT
10074+ "tvs %%xcc, 6\n"
10075+#endif
10076+
10077+ : "=r" (new)
10078+ : "0" (c), "ir" (a)
10079+ : "cc");
10080+
10081+ old = atomic64_cmpxchg(v, c, new);
10082 if (likely(old == c))
10083 break;
10084 c = old;
10085 }
10086- return c != (u);
10087+ return c != u;
10088 }
10089
10090 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10091diff --git a/arch/sparc/include/asm/barrier_64.h b/arch/sparc/include/asm/barrier_64.h
10092index 305dcc3..7835030 100644
10093--- a/arch/sparc/include/asm/barrier_64.h
10094+++ b/arch/sparc/include/asm/barrier_64.h
10095@@ -57,7 +57,7 @@ do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \
10096 do { \
10097 compiletime_assert_atomic_type(*p); \
10098 barrier(); \
10099- ACCESS_ONCE(*p) = (v); \
10100+ ACCESS_ONCE_RW(*p) = (v); \
10101 } while (0)
10102
10103 #define smp_load_acquire(p) \
10104diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
10105index 5bb6991..5c2132e 100644
10106--- a/arch/sparc/include/asm/cache.h
10107+++ b/arch/sparc/include/asm/cache.h
10108@@ -7,10 +7,12 @@
10109 #ifndef _SPARC_CACHE_H
10110 #define _SPARC_CACHE_H
10111
10112+#include <linux/const.h>
10113+
10114 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
10115
10116 #define L1_CACHE_SHIFT 5
10117-#define L1_CACHE_BYTES 32
10118+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10119
10120 #ifdef CONFIG_SPARC32
10121 #define SMP_CACHE_BYTES_SHIFT 5
10122diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
10123index a24e41f..47677ff 100644
10124--- a/arch/sparc/include/asm/elf_32.h
10125+++ b/arch/sparc/include/asm/elf_32.h
10126@@ -114,6 +114,13 @@ typedef struct {
10127
10128 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
10129
10130+#ifdef CONFIG_PAX_ASLR
10131+#define PAX_ELF_ET_DYN_BASE 0x10000UL
10132+
10133+#define PAX_DELTA_MMAP_LEN 16
10134+#define PAX_DELTA_STACK_LEN 16
10135+#endif
10136+
10137 /* This yields a mask that user programs can use to figure out what
10138 instruction set this cpu supports. This can NOT be done in userspace
10139 on Sparc. */
10140diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
10141index 370ca1e..d4f4a98 100644
10142--- a/arch/sparc/include/asm/elf_64.h
10143+++ b/arch/sparc/include/asm/elf_64.h
10144@@ -189,6 +189,13 @@ typedef struct {
10145 #define ELF_ET_DYN_BASE 0x0000010000000000UL
10146 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
10147
10148+#ifdef CONFIG_PAX_ASLR
10149+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
10150+
10151+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
10152+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
10153+#endif
10154+
10155 extern unsigned long sparc64_elf_hwcap;
10156 #define ELF_HWCAP sparc64_elf_hwcap
10157
10158diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
10159index a3890da..f6a408e 100644
10160--- a/arch/sparc/include/asm/pgalloc_32.h
10161+++ b/arch/sparc/include/asm/pgalloc_32.h
10162@@ -35,6 +35,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
10163 }
10164
10165 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
10166+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
10167
10168 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
10169 unsigned long address)
10170diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
10171index 5e31871..13469c6 100644
10172--- a/arch/sparc/include/asm/pgalloc_64.h
10173+++ b/arch/sparc/include/asm/pgalloc_64.h
10174@@ -21,6 +21,7 @@ static inline void __pgd_populate(pgd_t *pgd, pud_t *pud)
10175 }
10176
10177 #define pgd_populate(MM, PGD, PUD) __pgd_populate(PGD, PUD)
10178+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
10179
10180 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
10181 {
10182@@ -38,6 +39,7 @@ static inline void __pud_populate(pud_t *pud, pmd_t *pmd)
10183 }
10184
10185 #define pud_populate(MM, PUD, PMD) __pud_populate(PUD, PMD)
10186+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
10187
10188 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
10189 {
10190diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
10191index 59ba6f6..4518128 100644
10192--- a/arch/sparc/include/asm/pgtable.h
10193+++ b/arch/sparc/include/asm/pgtable.h
10194@@ -5,4 +5,8 @@
10195 #else
10196 #include <asm/pgtable_32.h>
10197 #endif
10198+
10199+#define ktla_ktva(addr) (addr)
10200+#define ktva_ktla(addr) (addr)
10201+
10202 #endif
10203diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
10204index b9b91ae..950b91e 100644
10205--- a/arch/sparc/include/asm/pgtable_32.h
10206+++ b/arch/sparc/include/asm/pgtable_32.h
10207@@ -51,6 +51,9 @@ unsigned long __init bootmem_init(unsigned long *pages_avail);
10208 #define PAGE_SHARED SRMMU_PAGE_SHARED
10209 #define PAGE_COPY SRMMU_PAGE_COPY
10210 #define PAGE_READONLY SRMMU_PAGE_RDONLY
10211+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
10212+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
10213+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
10214 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
10215
10216 /* Top-level page directory - dummy used by init-mm.
10217@@ -63,18 +66,18 @@ extern unsigned long ptr_in_current_pgd;
10218
10219 /* xwr */
10220 #define __P000 PAGE_NONE
10221-#define __P001 PAGE_READONLY
10222-#define __P010 PAGE_COPY
10223-#define __P011 PAGE_COPY
10224+#define __P001 PAGE_READONLY_NOEXEC
10225+#define __P010 PAGE_COPY_NOEXEC
10226+#define __P011 PAGE_COPY_NOEXEC
10227 #define __P100 PAGE_READONLY
10228 #define __P101 PAGE_READONLY
10229 #define __P110 PAGE_COPY
10230 #define __P111 PAGE_COPY
10231
10232 #define __S000 PAGE_NONE
10233-#define __S001 PAGE_READONLY
10234-#define __S010 PAGE_SHARED
10235-#define __S011 PAGE_SHARED
10236+#define __S001 PAGE_READONLY_NOEXEC
10237+#define __S010 PAGE_SHARED_NOEXEC
10238+#define __S011 PAGE_SHARED_NOEXEC
10239 #define __S100 PAGE_READONLY
10240 #define __S101 PAGE_READONLY
10241 #define __S110 PAGE_SHARED
10242diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
10243index 79da178..c2eede8 100644
10244--- a/arch/sparc/include/asm/pgtsrmmu.h
10245+++ b/arch/sparc/include/asm/pgtsrmmu.h
10246@@ -115,6 +115,11 @@
10247 SRMMU_EXEC | SRMMU_REF)
10248 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
10249 SRMMU_EXEC | SRMMU_REF)
10250+
10251+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
10252+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10253+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10254+
10255 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
10256 SRMMU_DIRTY | SRMMU_REF)
10257
10258diff --git a/arch/sparc/include/asm/setup.h b/arch/sparc/include/asm/setup.h
10259index 29d64b1..4272fe8 100644
10260--- a/arch/sparc/include/asm/setup.h
10261+++ b/arch/sparc/include/asm/setup.h
10262@@ -55,8 +55,8 @@ int handle_ldf_stq(u32 insn, struct pt_regs *regs);
10263 void handle_ld_nf(u32 insn, struct pt_regs *regs);
10264
10265 /* init_64.c */
10266-extern atomic_t dcpage_flushes;
10267-extern atomic_t dcpage_flushes_xcall;
10268+extern atomic_unchecked_t dcpage_flushes;
10269+extern atomic_unchecked_t dcpage_flushes_xcall;
10270
10271 extern int sysctl_tsb_ratio;
10272 #endif
10273diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
10274index 9689176..63c18ea 100644
10275--- a/arch/sparc/include/asm/spinlock_64.h
10276+++ b/arch/sparc/include/asm/spinlock_64.h
10277@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
10278
10279 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
10280
10281-static void inline arch_read_lock(arch_rwlock_t *lock)
10282+static inline void arch_read_lock(arch_rwlock_t *lock)
10283 {
10284 unsigned long tmp1, tmp2;
10285
10286 __asm__ __volatile__ (
10287 "1: ldsw [%2], %0\n"
10288 " brlz,pn %0, 2f\n"
10289-"4: add %0, 1, %1\n"
10290+"4: addcc %0, 1, %1\n"
10291+
10292+#ifdef CONFIG_PAX_REFCOUNT
10293+" tvs %%icc, 6\n"
10294+#endif
10295+
10296 " cas [%2], %0, %1\n"
10297 " cmp %0, %1\n"
10298 " bne,pn %%icc, 1b\n"
10299@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
10300 " .previous"
10301 : "=&r" (tmp1), "=&r" (tmp2)
10302 : "r" (lock)
10303- : "memory");
10304+ : "memory", "cc");
10305 }
10306
10307-static int inline arch_read_trylock(arch_rwlock_t *lock)
10308+static inline int arch_read_trylock(arch_rwlock_t *lock)
10309 {
10310 int tmp1, tmp2;
10311
10312@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10313 "1: ldsw [%2], %0\n"
10314 " brlz,a,pn %0, 2f\n"
10315 " mov 0, %0\n"
10316-" add %0, 1, %1\n"
10317+" addcc %0, 1, %1\n"
10318+
10319+#ifdef CONFIG_PAX_REFCOUNT
10320+" tvs %%icc, 6\n"
10321+#endif
10322+
10323 " cas [%2], %0, %1\n"
10324 " cmp %0, %1\n"
10325 " bne,pn %%icc, 1b\n"
10326@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10327 return tmp1;
10328 }
10329
10330-static void inline arch_read_unlock(arch_rwlock_t *lock)
10331+static inline void arch_read_unlock(arch_rwlock_t *lock)
10332 {
10333 unsigned long tmp1, tmp2;
10334
10335 __asm__ __volatile__(
10336 "1: lduw [%2], %0\n"
10337-" sub %0, 1, %1\n"
10338+" subcc %0, 1, %1\n"
10339+
10340+#ifdef CONFIG_PAX_REFCOUNT
10341+" tvs %%icc, 6\n"
10342+#endif
10343+
10344 " cas [%2], %0, %1\n"
10345 " cmp %0, %1\n"
10346 " bne,pn %%xcc, 1b\n"
10347@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
10348 : "memory");
10349 }
10350
10351-static void inline arch_write_lock(arch_rwlock_t *lock)
10352+static inline void arch_write_lock(arch_rwlock_t *lock)
10353 {
10354 unsigned long mask, tmp1, tmp2;
10355
10356@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
10357 : "memory");
10358 }
10359
10360-static void inline arch_write_unlock(arch_rwlock_t *lock)
10361+static inline void arch_write_unlock(arch_rwlock_t *lock)
10362 {
10363 __asm__ __volatile__(
10364 " stw %%g0, [%0]"
10365@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
10366 : "memory");
10367 }
10368
10369-static int inline arch_write_trylock(arch_rwlock_t *lock)
10370+static inline int arch_write_trylock(arch_rwlock_t *lock)
10371 {
10372 unsigned long mask, tmp1, tmp2, result;
10373
10374diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
10375index 025c984..a216504 100644
10376--- a/arch/sparc/include/asm/thread_info_32.h
10377+++ b/arch/sparc/include/asm/thread_info_32.h
10378@@ -49,6 +49,8 @@ struct thread_info {
10379 unsigned long w_saved;
10380
10381 struct restart_block restart_block;
10382+
10383+ unsigned long lowest_stack;
10384 };
10385
10386 /*
10387diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
10388index 798f027..b009941 100644
10389--- a/arch/sparc/include/asm/thread_info_64.h
10390+++ b/arch/sparc/include/asm/thread_info_64.h
10391@@ -63,6 +63,8 @@ struct thread_info {
10392 struct pt_regs *kern_una_regs;
10393 unsigned int kern_una_insn;
10394
10395+ unsigned long lowest_stack;
10396+
10397 unsigned long fpregs[(7 * 256) / sizeof(unsigned long)]
10398 __attribute__ ((aligned(64)));
10399 };
10400@@ -190,12 +192,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
10401 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
10402 /* flag bit 4 is available */
10403 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
10404-/* flag bit 6 is available */
10405+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
10406 #define TIF_32BIT 7 /* 32-bit binary */
10407 #define TIF_NOHZ 8 /* in adaptive nohz mode */
10408 #define TIF_SECCOMP 9 /* secure computing */
10409 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
10410 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
10411+
10412 /* NOTE: Thread flags >= 12 should be ones we have no interest
10413 * in using in assembly, else we can't use the mask as
10414 * an immediate value in instructions such as andcc.
10415@@ -215,12 +218,17 @@ register struct thread_info *current_thread_info_reg asm("g6");
10416 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
10417 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
10418 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
10419+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
10420
10421 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
10422 _TIF_DO_NOTIFY_RESUME_MASK | \
10423 _TIF_NEED_RESCHED)
10424 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
10425
10426+#define _TIF_WORK_SYSCALL \
10427+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
10428+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
10429+
10430 #define is_32bit_task() (test_thread_flag(TIF_32BIT))
10431
10432 /*
10433diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
10434index bd56c28..4b63d83 100644
10435--- a/arch/sparc/include/asm/uaccess.h
10436+++ b/arch/sparc/include/asm/uaccess.h
10437@@ -1,5 +1,6 @@
10438 #ifndef ___ASM_SPARC_UACCESS_H
10439 #define ___ASM_SPARC_UACCESS_H
10440+
10441 #if defined(__sparc__) && defined(__arch64__)
10442 #include <asm/uaccess_64.h>
10443 #else
10444diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
10445index 9634d08..f55fe4f 100644
10446--- a/arch/sparc/include/asm/uaccess_32.h
10447+++ b/arch/sparc/include/asm/uaccess_32.h
10448@@ -250,27 +250,46 @@ unsigned long __copy_user(void __user *to, const void __user *from, unsigned lon
10449
10450 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
10451 {
10452- if (n && __access_ok((unsigned long) to, n))
10453+ if ((long)n < 0)
10454+ return n;
10455+
10456+ if (n && __access_ok((unsigned long) to, n)) {
10457+ if (!__builtin_constant_p(n))
10458+ check_object_size(from, n, true);
10459 return __copy_user(to, (__force void __user *) from, n);
10460- else
10461+ } else
10462 return n;
10463 }
10464
10465 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
10466 {
10467+ if ((long)n < 0)
10468+ return n;
10469+
10470+ if (!__builtin_constant_p(n))
10471+ check_object_size(from, n, true);
10472+
10473 return __copy_user(to, (__force void __user *) from, n);
10474 }
10475
10476 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
10477 {
10478- if (n && __access_ok((unsigned long) from, n))
10479+ if ((long)n < 0)
10480+ return n;
10481+
10482+ if (n && __access_ok((unsigned long) from, n)) {
10483+ if (!__builtin_constant_p(n))
10484+ check_object_size(to, n, false);
10485 return __copy_user((__force void __user *) to, from, n);
10486- else
10487+ } else
10488 return n;
10489 }
10490
10491 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
10492 {
10493+ if ((long)n < 0)
10494+ return n;
10495+
10496 return __copy_user((__force void __user *) to, from, n);
10497 }
10498
10499diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
10500index c990a5e..f17b9c1 100644
10501--- a/arch/sparc/include/asm/uaccess_64.h
10502+++ b/arch/sparc/include/asm/uaccess_64.h
10503@@ -10,6 +10,7 @@
10504 #include <linux/compiler.h>
10505 #include <linux/string.h>
10506 #include <linux/thread_info.h>
10507+#include <linux/kernel.h>
10508 #include <asm/asi.h>
10509 #include <asm/spitfire.h>
10510 #include <asm-generic/uaccess-unaligned.h>
10511@@ -214,8 +215,15 @@ unsigned long copy_from_user_fixup(void *to, const void __user *from,
10512 static inline unsigned long __must_check
10513 copy_from_user(void *to, const void __user *from, unsigned long size)
10514 {
10515- unsigned long ret = ___copy_from_user(to, from, size);
10516+ unsigned long ret;
10517
10518+ if ((long)size < 0 || size > INT_MAX)
10519+ return size;
10520+
10521+ if (!__builtin_constant_p(size))
10522+ check_object_size(to, size, false);
10523+
10524+ ret = ___copy_from_user(to, from, size);
10525 if (unlikely(ret))
10526 ret = copy_from_user_fixup(to, from, size);
10527
10528@@ -231,8 +239,15 @@ unsigned long copy_to_user_fixup(void __user *to, const void *from,
10529 static inline unsigned long __must_check
10530 copy_to_user(void __user *to, const void *from, unsigned long size)
10531 {
10532- unsigned long ret = ___copy_to_user(to, from, size);
10533+ unsigned long ret;
10534
10535+ if ((long)size < 0 || size > INT_MAX)
10536+ return size;
10537+
10538+ if (!__builtin_constant_p(size))
10539+ check_object_size(from, size, true);
10540+
10541+ ret = ___copy_to_user(to, from, size);
10542 if (unlikely(ret))
10543 ret = copy_to_user_fixup(to, from, size);
10544 return ret;
10545diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10546index 7cf9c6e..6206648 100644
10547--- a/arch/sparc/kernel/Makefile
10548+++ b/arch/sparc/kernel/Makefile
10549@@ -4,7 +4,7 @@
10550 #
10551
10552 asflags-y := -ansi
10553-ccflags-y := -Werror
10554+#ccflags-y := -Werror
10555
10556 extra-y := head_$(BITS).o
10557
10558diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10559index 50e7b62..79fae35 100644
10560--- a/arch/sparc/kernel/process_32.c
10561+++ b/arch/sparc/kernel/process_32.c
10562@@ -123,14 +123,14 @@ void show_regs(struct pt_regs *r)
10563
10564 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10565 r->psr, r->pc, r->npc, r->y, print_tainted());
10566- printk("PC: <%pS>\n", (void *) r->pc);
10567+ printk("PC: <%pA>\n", (void *) r->pc);
10568 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10569 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10570 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10571 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10572 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10573 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10574- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10575+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10576
10577 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10578 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10579@@ -167,7 +167,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10580 rw = (struct reg_window32 *) fp;
10581 pc = rw->ins[7];
10582 printk("[%08lx : ", pc);
10583- printk("%pS ] ", (void *) pc);
10584+ printk("%pA ] ", (void *) pc);
10585 fp = rw->ins[6];
10586 } while (++count < 16);
10587 printk("\n");
10588diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10589index 0be7bf9..2b1cba8 100644
10590--- a/arch/sparc/kernel/process_64.c
10591+++ b/arch/sparc/kernel/process_64.c
10592@@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
10593 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10594 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10595 if (regs->tstate & TSTATE_PRIV)
10596- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10597+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10598 }
10599
10600 void show_regs(struct pt_regs *regs)
10601@@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
10602
10603 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10604 regs->tpc, regs->tnpc, regs->y, print_tainted());
10605- printk("TPC: <%pS>\n", (void *) regs->tpc);
10606+ printk("TPC: <%pA>\n", (void *) regs->tpc);
10607 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10608 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10609 regs->u_regs[3]);
10610@@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
10611 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10612 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10613 regs->u_regs[15]);
10614- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10615+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10616 show_regwindow(regs);
10617 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10618 }
10619@@ -278,7 +278,7 @@ void arch_trigger_all_cpu_backtrace(bool include_self)
10620 ((tp && tp->task) ? tp->task->pid : -1));
10621
10622 if (gp->tstate & TSTATE_PRIV) {
10623- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10624+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10625 (void *) gp->tpc,
10626 (void *) gp->o7,
10627 (void *) gp->i7,
10628diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10629index 79cc0d1..ec62734 100644
10630--- a/arch/sparc/kernel/prom_common.c
10631+++ b/arch/sparc/kernel/prom_common.c
10632@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10633
10634 unsigned int prom_early_allocated __initdata;
10635
10636-static struct of_pdt_ops prom_sparc_ops __initdata = {
10637+static struct of_pdt_ops prom_sparc_ops __initconst = {
10638 .nextprop = prom_common_nextprop,
10639 .getproplen = prom_getproplen,
10640 .getproperty = prom_getproperty,
10641diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10642index 9ddc492..27a5619 100644
10643--- a/arch/sparc/kernel/ptrace_64.c
10644+++ b/arch/sparc/kernel/ptrace_64.c
10645@@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10646 return ret;
10647 }
10648
10649+#ifdef CONFIG_GRKERNSEC_SETXID
10650+extern void gr_delayed_cred_worker(void);
10651+#endif
10652+
10653 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10654 {
10655 int ret = 0;
10656@@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10657 if (test_thread_flag(TIF_NOHZ))
10658 user_exit();
10659
10660+#ifdef CONFIG_GRKERNSEC_SETXID
10661+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10662+ gr_delayed_cred_worker();
10663+#endif
10664+
10665 if (test_thread_flag(TIF_SYSCALL_TRACE))
10666 ret = tracehook_report_syscall_entry(regs);
10667
10668@@ -1088,6 +1097,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10669 if (test_thread_flag(TIF_NOHZ))
10670 user_exit();
10671
10672+#ifdef CONFIG_GRKERNSEC_SETXID
10673+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10674+ gr_delayed_cred_worker();
10675+#endif
10676+
10677 audit_syscall_exit(regs);
10678
10679 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10680diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10681index da6f1a7..e5dea8f 100644
10682--- a/arch/sparc/kernel/smp_64.c
10683+++ b/arch/sparc/kernel/smp_64.c
10684@@ -887,7 +887,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10685 return;
10686
10687 #ifdef CONFIG_DEBUG_DCFLUSH
10688- atomic_inc(&dcpage_flushes);
10689+ atomic_inc_unchecked(&dcpage_flushes);
10690 #endif
10691
10692 this_cpu = get_cpu();
10693@@ -911,7 +911,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10694 xcall_deliver(data0, __pa(pg_addr),
10695 (u64) pg_addr, cpumask_of(cpu));
10696 #ifdef CONFIG_DEBUG_DCFLUSH
10697- atomic_inc(&dcpage_flushes_xcall);
10698+ atomic_inc_unchecked(&dcpage_flushes_xcall);
10699 #endif
10700 }
10701 }
10702@@ -930,7 +930,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10703 preempt_disable();
10704
10705 #ifdef CONFIG_DEBUG_DCFLUSH
10706- atomic_inc(&dcpage_flushes);
10707+ atomic_inc_unchecked(&dcpage_flushes);
10708 #endif
10709 data0 = 0;
10710 pg_addr = page_address(page);
10711@@ -947,7 +947,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10712 xcall_deliver(data0, __pa(pg_addr),
10713 (u64) pg_addr, cpu_online_mask);
10714 #ifdef CONFIG_DEBUG_DCFLUSH
10715- atomic_inc(&dcpage_flushes_xcall);
10716+ atomic_inc_unchecked(&dcpage_flushes_xcall);
10717 #endif
10718 }
10719 __local_flush_dcache_page(page);
10720diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10721index 646988d..b88905f 100644
10722--- a/arch/sparc/kernel/sys_sparc_32.c
10723+++ b/arch/sparc/kernel/sys_sparc_32.c
10724@@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10725 if (len > TASK_SIZE - PAGE_SIZE)
10726 return -ENOMEM;
10727 if (!addr)
10728- addr = TASK_UNMAPPED_BASE;
10729+ addr = current->mm->mmap_base;
10730
10731 info.flags = 0;
10732 info.length = len;
10733diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10734index c85403d..6af95c9 100644
10735--- a/arch/sparc/kernel/sys_sparc_64.c
10736+++ b/arch/sparc/kernel/sys_sparc_64.c
10737@@ -89,13 +89,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10738 struct vm_area_struct * vma;
10739 unsigned long task_size = TASK_SIZE;
10740 int do_color_align;
10741+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10742 struct vm_unmapped_area_info info;
10743
10744 if (flags & MAP_FIXED) {
10745 /* We do not accept a shared mapping if it would violate
10746 * cache aliasing constraints.
10747 */
10748- if ((flags & MAP_SHARED) &&
10749+ if ((filp || (flags & MAP_SHARED)) &&
10750 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10751 return -EINVAL;
10752 return addr;
10753@@ -110,6 +111,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10754 if (filp || (flags & MAP_SHARED))
10755 do_color_align = 1;
10756
10757+#ifdef CONFIG_PAX_RANDMMAP
10758+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10759+#endif
10760+
10761 if (addr) {
10762 if (do_color_align)
10763 addr = COLOR_ALIGN(addr, pgoff);
10764@@ -117,22 +122,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10765 addr = PAGE_ALIGN(addr);
10766
10767 vma = find_vma(mm, addr);
10768- if (task_size - len >= addr &&
10769- (!vma || addr + len <= vma->vm_start))
10770+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10771 return addr;
10772 }
10773
10774 info.flags = 0;
10775 info.length = len;
10776- info.low_limit = TASK_UNMAPPED_BASE;
10777+ info.low_limit = mm->mmap_base;
10778 info.high_limit = min(task_size, VA_EXCLUDE_START);
10779 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10780 info.align_offset = pgoff << PAGE_SHIFT;
10781+ info.threadstack_offset = offset;
10782 addr = vm_unmapped_area(&info);
10783
10784 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10785 VM_BUG_ON(addr != -ENOMEM);
10786 info.low_limit = VA_EXCLUDE_END;
10787+
10788+#ifdef CONFIG_PAX_RANDMMAP
10789+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10790+ info.low_limit += mm->delta_mmap;
10791+#endif
10792+
10793 info.high_limit = task_size;
10794 addr = vm_unmapped_area(&info);
10795 }
10796@@ -150,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10797 unsigned long task_size = STACK_TOP32;
10798 unsigned long addr = addr0;
10799 int do_color_align;
10800+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10801 struct vm_unmapped_area_info info;
10802
10803 /* This should only ever run for 32-bit processes. */
10804@@ -159,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10805 /* We do not accept a shared mapping if it would violate
10806 * cache aliasing constraints.
10807 */
10808- if ((flags & MAP_SHARED) &&
10809+ if ((filp || (flags & MAP_SHARED)) &&
10810 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10811 return -EINVAL;
10812 return addr;
10813@@ -172,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10814 if (filp || (flags & MAP_SHARED))
10815 do_color_align = 1;
10816
10817+#ifdef CONFIG_PAX_RANDMMAP
10818+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10819+#endif
10820+
10821 /* requesting a specific address */
10822 if (addr) {
10823 if (do_color_align)
10824@@ -180,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10825 addr = PAGE_ALIGN(addr);
10826
10827 vma = find_vma(mm, addr);
10828- if (task_size - len >= addr &&
10829- (!vma || addr + len <= vma->vm_start))
10830+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10831 return addr;
10832 }
10833
10834@@ -191,6 +206,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10835 info.high_limit = mm->mmap_base;
10836 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10837 info.align_offset = pgoff << PAGE_SHIFT;
10838+ info.threadstack_offset = offset;
10839 addr = vm_unmapped_area(&info);
10840
10841 /*
10842@@ -203,6 +219,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10843 VM_BUG_ON(addr != -ENOMEM);
10844 info.flags = 0;
10845 info.low_limit = TASK_UNMAPPED_BASE;
10846+
10847+#ifdef CONFIG_PAX_RANDMMAP
10848+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10849+ info.low_limit += mm->delta_mmap;
10850+#endif
10851+
10852 info.high_limit = STACK_TOP32;
10853 addr = vm_unmapped_area(&info);
10854 }
10855@@ -259,10 +281,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10856 EXPORT_SYMBOL(get_fb_unmapped_area);
10857
10858 /* Essentially the same as PowerPC. */
10859-static unsigned long mmap_rnd(void)
10860+static unsigned long mmap_rnd(struct mm_struct *mm)
10861 {
10862 unsigned long rnd = 0UL;
10863
10864+#ifdef CONFIG_PAX_RANDMMAP
10865+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10866+#endif
10867+
10868 if (current->flags & PF_RANDOMIZE) {
10869 unsigned long val = get_random_int();
10870 if (test_thread_flag(TIF_32BIT))
10871@@ -275,7 +301,7 @@ static unsigned long mmap_rnd(void)
10872
10873 void arch_pick_mmap_layout(struct mm_struct *mm)
10874 {
10875- unsigned long random_factor = mmap_rnd();
10876+ unsigned long random_factor = mmap_rnd(mm);
10877 unsigned long gap;
10878
10879 /*
10880@@ -288,6 +314,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10881 gap == RLIM_INFINITY ||
10882 sysctl_legacy_va_layout) {
10883 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
10884+
10885+#ifdef CONFIG_PAX_RANDMMAP
10886+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10887+ mm->mmap_base += mm->delta_mmap;
10888+#endif
10889+
10890 mm->get_unmapped_area = arch_get_unmapped_area;
10891 } else {
10892 /* We know it's 32-bit */
10893@@ -299,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10894 gap = (task_size / 6 * 5);
10895
10896 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
10897+
10898+#ifdef CONFIG_PAX_RANDMMAP
10899+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10900+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10901+#endif
10902+
10903 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10904 }
10905 }
10906diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
10907index 33a17e7..d87fb1f 100644
10908--- a/arch/sparc/kernel/syscalls.S
10909+++ b/arch/sparc/kernel/syscalls.S
10910@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
10911 #endif
10912 .align 32
10913 1: ldx [%g6 + TI_FLAGS], %l5
10914- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10915+ andcc %l5, _TIF_WORK_SYSCALL, %g0
10916 be,pt %icc, rtrap
10917 nop
10918 call syscall_trace_leave
10919@@ -184,7 +184,7 @@ linux_sparc_syscall32:
10920
10921 srl %i3, 0, %o3 ! IEU0
10922 srl %i2, 0, %o2 ! IEU0 Group
10923- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10924+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10925 bne,pn %icc, linux_syscall_trace32 ! CTI
10926 mov %i0, %l5 ! IEU1
10927 5: call %l7 ! CTI Group brk forced
10928@@ -208,7 +208,7 @@ linux_sparc_syscall:
10929
10930 mov %i3, %o3 ! IEU1
10931 mov %i4, %o4 ! IEU0 Group
10932- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10933+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10934 bne,pn %icc, linux_syscall_trace ! CTI Group
10935 mov %i0, %l5 ! IEU0
10936 2: call %l7 ! CTI Group brk forced
10937@@ -223,7 +223,7 @@ ret_sys_call:
10938
10939 cmp %o0, -ERESTART_RESTARTBLOCK
10940 bgeu,pn %xcc, 1f
10941- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10942+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10943 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10944
10945 2:
10946diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10947index 6fd386c5..6907d81 100644
10948--- a/arch/sparc/kernel/traps_32.c
10949+++ b/arch/sparc/kernel/traps_32.c
10950@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10951 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10952 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10953
10954+extern void gr_handle_kernel_exploit(void);
10955+
10956 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
10957 {
10958 static int die_counter;
10959@@ -76,15 +78,17 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
10960 count++ < 30 &&
10961 (((unsigned long) rw) >= PAGE_OFFSET) &&
10962 !(((unsigned long) rw) & 0x7)) {
10963- printk("Caller[%08lx]: %pS\n", rw->ins[7],
10964+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
10965 (void *) rw->ins[7]);
10966 rw = (struct reg_window32 *)rw->ins[6];
10967 }
10968 }
10969 printk("Instruction DUMP:");
10970 instruction_dump ((unsigned long *) regs->pc);
10971- if(regs->psr & PSR_PS)
10972+ if(regs->psr & PSR_PS) {
10973+ gr_handle_kernel_exploit();
10974 do_exit(SIGKILL);
10975+ }
10976 do_exit(SIGSEGV);
10977 }
10978
10979diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10980index 981a769..d906eda 100644
10981--- a/arch/sparc/kernel/traps_64.c
10982+++ b/arch/sparc/kernel/traps_64.c
10983@@ -79,7 +79,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10984 i + 1,
10985 p->trapstack[i].tstate, p->trapstack[i].tpc,
10986 p->trapstack[i].tnpc, p->trapstack[i].tt);
10987- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10988+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10989 }
10990 }
10991
10992@@ -99,6 +99,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10993
10994 lvl -= 0x100;
10995 if (regs->tstate & TSTATE_PRIV) {
10996+
10997+#ifdef CONFIG_PAX_REFCOUNT
10998+ if (lvl == 6)
10999+ pax_report_refcount_overflow(regs);
11000+#endif
11001+
11002 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
11003 die_if_kernel(buffer, regs);
11004 }
11005@@ -117,11 +123,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
11006 void bad_trap_tl1(struct pt_regs *regs, long lvl)
11007 {
11008 char buffer[32];
11009-
11010+
11011 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
11012 0, lvl, SIGTRAP) == NOTIFY_STOP)
11013 return;
11014
11015+#ifdef CONFIG_PAX_REFCOUNT
11016+ if (lvl == 6)
11017+ pax_report_refcount_overflow(regs);
11018+#endif
11019+
11020 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
11021
11022 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
11023@@ -1151,7 +1162,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
11024 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
11025 printk("%s" "ERROR(%d): ",
11026 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
11027- printk("TPC<%pS>\n", (void *) regs->tpc);
11028+ printk("TPC<%pA>\n", (void *) regs->tpc);
11029 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
11030 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
11031 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
11032@@ -1758,7 +1769,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11033 smp_processor_id(),
11034 (type & 0x1) ? 'I' : 'D',
11035 regs->tpc);
11036- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
11037+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
11038 panic("Irrecoverable Cheetah+ parity error.");
11039 }
11040
11041@@ -1766,7 +1777,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11042 smp_processor_id(),
11043 (type & 0x1) ? 'I' : 'D',
11044 regs->tpc);
11045- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
11046+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
11047 }
11048
11049 struct sun4v_error_entry {
11050@@ -1839,8 +1850,8 @@ struct sun4v_error_entry {
11051 /*0x38*/u64 reserved_5;
11052 };
11053
11054-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11055-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11056+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11057+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11058
11059 static const char *sun4v_err_type_to_str(u8 type)
11060 {
11061@@ -1932,7 +1943,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
11062 }
11063
11064 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11065- int cpu, const char *pfx, atomic_t *ocnt)
11066+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
11067 {
11068 u64 *raw_ptr = (u64 *) ent;
11069 u32 attrs;
11070@@ -1990,8 +2001,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11071
11072 show_regs(regs);
11073
11074- if ((cnt = atomic_read(ocnt)) != 0) {
11075- atomic_set(ocnt, 0);
11076+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
11077+ atomic_set_unchecked(ocnt, 0);
11078 wmb();
11079 printk("%s: Queue overflowed %d times.\n",
11080 pfx, cnt);
11081@@ -2048,7 +2059,7 @@ out:
11082 */
11083 void sun4v_resum_overflow(struct pt_regs *regs)
11084 {
11085- atomic_inc(&sun4v_resum_oflow_cnt);
11086+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
11087 }
11088
11089 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
11090@@ -2101,7 +2112,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
11091 /* XXX Actually even this can make not that much sense. Perhaps
11092 * XXX we should just pull the plug and panic directly from here?
11093 */
11094- atomic_inc(&sun4v_nonresum_oflow_cnt);
11095+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
11096 }
11097
11098 static void sun4v_tlb_error(struct pt_regs *regs)
11099@@ -2120,9 +2131,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
11100
11101 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
11102 regs->tpc, tl);
11103- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
11104+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
11105 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11106- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
11107+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
11108 (void *) regs->u_regs[UREG_I7]);
11109 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
11110 "pte[%lx] error[%lx]\n",
11111@@ -2143,9 +2154,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
11112
11113 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
11114 regs->tpc, tl);
11115- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
11116+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
11117 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11118- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
11119+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
11120 (void *) regs->u_regs[UREG_I7]);
11121 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
11122 "pte[%lx] error[%lx]\n",
11123@@ -2362,13 +2373,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
11124 fp = (unsigned long)sf->fp + STACK_BIAS;
11125 }
11126
11127- printk(" [%016lx] %pS\n", pc, (void *) pc);
11128+ printk(" [%016lx] %pA\n", pc, (void *) pc);
11129 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
11130 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
11131 int index = tsk->curr_ret_stack;
11132 if (tsk->ret_stack && index >= graph) {
11133 pc = tsk->ret_stack[index - graph].ret;
11134- printk(" [%016lx] %pS\n", pc, (void *) pc);
11135+ printk(" [%016lx] %pA\n", pc, (void *) pc);
11136 graph++;
11137 }
11138 }
11139@@ -2386,6 +2397,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
11140 return (struct reg_window *) (fp + STACK_BIAS);
11141 }
11142
11143+extern void gr_handle_kernel_exploit(void);
11144+
11145 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11146 {
11147 static int die_counter;
11148@@ -2414,7 +2427,7 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11149 while (rw &&
11150 count++ < 30 &&
11151 kstack_valid(tp, (unsigned long) rw)) {
11152- printk("Caller[%016lx]: %pS\n", rw->ins[7],
11153+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
11154 (void *) rw->ins[7]);
11155
11156 rw = kernel_stack_up(rw);
11157@@ -2427,8 +2440,10 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11158 }
11159 user_instruction_dump ((unsigned int __user *) regs->tpc);
11160 }
11161- if (regs->tstate & TSTATE_PRIV)
11162+ if (regs->tstate & TSTATE_PRIV) {
11163+ gr_handle_kernel_exploit();
11164 do_exit(SIGKILL);
11165+ }
11166 do_exit(SIGSEGV);
11167 }
11168 EXPORT_SYMBOL(die_if_kernel);
11169diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
11170index 62098a8..547ab2c 100644
11171--- a/arch/sparc/kernel/unaligned_64.c
11172+++ b/arch/sparc/kernel/unaligned_64.c
11173@@ -297,7 +297,7 @@ static void log_unaligned(struct pt_regs *regs)
11174 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
11175
11176 if (__ratelimit(&ratelimit)) {
11177- printk("Kernel unaligned access at TPC[%lx] %pS\n",
11178+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
11179 regs->tpc, (void *) regs->tpc);
11180 }
11181 }
11182diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
11183index 3269b02..64f5231 100644
11184--- a/arch/sparc/lib/Makefile
11185+++ b/arch/sparc/lib/Makefile
11186@@ -2,7 +2,7 @@
11187 #
11188
11189 asflags-y := -ansi -DST_DIV0=0x02
11190-ccflags-y := -Werror
11191+#ccflags-y := -Werror
11192
11193 lib-$(CONFIG_SPARC32) += ashrdi3.o
11194 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
11195diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
11196index 05dac43..76f8ed4 100644
11197--- a/arch/sparc/lib/atomic_64.S
11198+++ b/arch/sparc/lib/atomic_64.S
11199@@ -15,11 +15,22 @@
11200 * a value and does the barriers.
11201 */
11202
11203-#define ATOMIC_OP(op) \
11204-ENTRY(atomic_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
11205+#ifdef CONFIG_PAX_REFCOUNT
11206+#define __REFCOUNT_OP(op) op##cc
11207+#define __OVERFLOW_IOP tvs %icc, 6;
11208+#define __OVERFLOW_XOP tvs %xcc, 6;
11209+#else
11210+#define __REFCOUNT_OP(op) op
11211+#define __OVERFLOW_IOP
11212+#define __OVERFLOW_XOP
11213+#endif
11214+
11215+#define __ATOMIC_OP(op, suffix, asm_op, post_op) \
11216+ENTRY(atomic_##op##suffix) /* %o0 = increment, %o1 = atomic_ptr */ \
11217 BACKOFF_SETUP(%o2); \
11218 1: lduw [%o1], %g1; \
11219- op %g1, %o0, %g7; \
11220+ asm_op %g1, %o0, %g7; \
11221+ post_op \
11222 cas [%o1], %g1, %g7; \
11223 cmp %g1, %g7; \
11224 bne,pn %icc, BACKOFF_LABEL(2f, 1b); \
11225@@ -29,11 +40,15 @@ ENTRY(atomic_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
11226 2: BACKOFF_SPIN(%o2, %o3, 1b); \
11227 ENDPROC(atomic_##op); \
11228
11229-#define ATOMIC_OP_RETURN(op) \
11230-ENTRY(atomic_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
11231+#define ATOMIC_OP(op) __ATOMIC_OP(op, , op, ) \
11232+ __ATOMIC_OP(op, _unchecked, __REFCOUNT_OP(op), __OVERFLOW_IOP)
11233+
11234+#define __ATOMIC_OP_RETURN(op, suffix, asm_op, post_op) \
11235+ENTRY(atomic_##op##_return##suffix) /* %o0 = increment, %o1 = atomic_ptr */\
11236 BACKOFF_SETUP(%o2); \
11237 1: lduw [%o1], %g1; \
11238- op %g1, %o0, %g7; \
11239+ asm_op %g1, %o0, %g7; \
11240+ post_op \
11241 cas [%o1], %g1, %g7; \
11242 cmp %g1, %g7; \
11243 bne,pn %icc, BACKOFF_LABEL(2f, 1b); \
11244@@ -43,6 +58,9 @@ ENTRY(atomic_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
11245 2: BACKOFF_SPIN(%o2, %o3, 1b); \
11246 ENDPROC(atomic_##op##_return);
11247
11248+#define ATOMIC_OP_RETURN(op) __ATOMIC_OP_RETURN(op, , op, ) \
11249+ __ATOMIC_OP_RETURN(op, _unchecked, __REFCOUNT_OP(op), __OVERFLOW_IOP)
11250+
11251 #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op)
11252
11253 ATOMIC_OPS(add)
11254@@ -50,13 +68,16 @@ ATOMIC_OPS(sub)
11255
11256 #undef ATOMIC_OPS
11257 #undef ATOMIC_OP_RETURN
11258+#undef __ATOMIC_OP_RETURN
11259 #undef ATOMIC_OP
11260+#undef __ATOMIC_OP
11261
11262-#define ATOMIC64_OP(op) \
11263-ENTRY(atomic64_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
11264+#define __ATOMIC64_OP(op, suffix, asm_op, post_op) \
11265+ENTRY(atomic64_##op##suffix) /* %o0 = increment, %o1 = atomic_ptr */ \
11266 BACKOFF_SETUP(%o2); \
11267 1: ldx [%o1], %g1; \
11268- op %g1, %o0, %g7; \
11269+ asm_op %g1, %o0, %g7; \
11270+ post_op \
11271 casx [%o1], %g1, %g7; \
11272 cmp %g1, %g7; \
11273 bne,pn %xcc, BACKOFF_LABEL(2f, 1b); \
11274@@ -66,11 +87,15 @@ ENTRY(atomic64_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
11275 2: BACKOFF_SPIN(%o2, %o3, 1b); \
11276 ENDPROC(atomic64_##op); \
11277
11278-#define ATOMIC64_OP_RETURN(op) \
11279-ENTRY(atomic64_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
11280+#define ATOMIC64_OP(op) __ATOMIC64_OP(op, , op, ) \
11281+ __ATOMIC64_OP(op, _unchecked, __REFCOUNT_OP(op), __OVERFLOW_XOP)
11282+
11283+#define __ATOMIC64_OP_RETURN(op, suffix, asm_op, post_op) \
11284+ENTRY(atomic64_##op##_return##suffix) /* %o0 = increment, %o1 = atomic_ptr */\
11285 BACKOFF_SETUP(%o2); \
11286 1: ldx [%o1], %g1; \
11287- op %g1, %o0, %g7; \
11288+ asm_op %g1, %o0, %g7; \
11289+ post_op \
11290 casx [%o1], %g1, %g7; \
11291 cmp %g1, %g7; \
11292 bne,pn %xcc, BACKOFF_LABEL(2f, 1b); \
11293@@ -80,6 +105,9 @@ ENTRY(atomic64_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
11294 2: BACKOFF_SPIN(%o2, %o3, 1b); \
11295 ENDPROC(atomic64_##op##_return);
11296
11297+#define ATOMIC64_OP_RETURN(op) __ATOMIC64_OP_RETURN(op, , op, ) \
11298+i __ATOMIC64_OP_RETURN(op, _unchecked, __REFCOUNT_OP(op), __OVERFLOW_XOP)
11299+
11300 #define ATOMIC64_OPS(op) ATOMIC64_OP(op) ATOMIC64_OP_RETURN(op)
11301
11302 ATOMIC64_OPS(add)
11303@@ -87,7 +115,12 @@ ATOMIC64_OPS(sub)
11304
11305 #undef ATOMIC64_OPS
11306 #undef ATOMIC64_OP_RETURN
11307+#undef __ATOMIC64_OP_RETURN
11308 #undef ATOMIC64_OP
11309+#undef __ATOMIC64_OP
11310+#undef __OVERFLOW_XOP
11311+#undef __OVERFLOW_IOP
11312+#undef __REFCOUNT_OP
11313
11314 ENTRY(atomic64_dec_if_positive) /* %o0 = atomic_ptr */
11315 BACKOFF_SETUP(%o2)
11316diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
11317index 1d649a9..fbc5bfc 100644
11318--- a/arch/sparc/lib/ksyms.c
11319+++ b/arch/sparc/lib/ksyms.c
11320@@ -101,7 +101,9 @@ EXPORT_SYMBOL(__clear_user);
11321 /* Atomic counter implementation. */
11322 #define ATOMIC_OP(op) \
11323 EXPORT_SYMBOL(atomic_##op); \
11324-EXPORT_SYMBOL(atomic64_##op);
11325+EXPORT_SYMBOL(atomic_##op##_unchecked); \
11326+EXPORT_SYMBOL(atomic64_##op); \
11327+EXPORT_SYMBOL(atomic64_##op##_unchecked);
11328
11329 #define ATOMIC_OP_RETURN(op) \
11330 EXPORT_SYMBOL(atomic_##op##_return); \
11331@@ -110,6 +112,8 @@ EXPORT_SYMBOL(atomic64_##op##_return);
11332 #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op)
11333
11334 ATOMIC_OPS(add)
11335+EXPORT_SYMBOL(atomic_add_ret_unchecked);
11336+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
11337 ATOMIC_OPS(sub)
11338
11339 #undef ATOMIC_OPS
11340diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
11341index 30c3ecc..736f015 100644
11342--- a/arch/sparc/mm/Makefile
11343+++ b/arch/sparc/mm/Makefile
11344@@ -2,7 +2,7 @@
11345 #
11346
11347 asflags-y := -ansi
11348-ccflags-y := -Werror
11349+#ccflags-y := -Werror
11350
11351 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
11352 obj-y += fault_$(BITS).o
11353diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
11354index 908e8c1..1524793 100644
11355--- a/arch/sparc/mm/fault_32.c
11356+++ b/arch/sparc/mm/fault_32.c
11357@@ -21,6 +21,9 @@
11358 #include <linux/perf_event.h>
11359 #include <linux/interrupt.h>
11360 #include <linux/kdebug.h>
11361+#include <linux/slab.h>
11362+#include <linux/pagemap.h>
11363+#include <linux/compiler.h>
11364
11365 #include <asm/page.h>
11366 #include <asm/pgtable.h>
11367@@ -156,6 +159,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
11368 return safe_compute_effective_address(regs, insn);
11369 }
11370
11371+#ifdef CONFIG_PAX_PAGEEXEC
11372+#ifdef CONFIG_PAX_DLRESOLVE
11373+static void pax_emuplt_close(struct vm_area_struct *vma)
11374+{
11375+ vma->vm_mm->call_dl_resolve = 0UL;
11376+}
11377+
11378+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11379+{
11380+ unsigned int *kaddr;
11381+
11382+ vmf->page = alloc_page(GFP_HIGHUSER);
11383+ if (!vmf->page)
11384+ return VM_FAULT_OOM;
11385+
11386+ kaddr = kmap(vmf->page);
11387+ memset(kaddr, 0, PAGE_SIZE);
11388+ kaddr[0] = 0x9DE3BFA8U; /* save */
11389+ flush_dcache_page(vmf->page);
11390+ kunmap(vmf->page);
11391+ return VM_FAULT_MAJOR;
11392+}
11393+
11394+static const struct vm_operations_struct pax_vm_ops = {
11395+ .close = pax_emuplt_close,
11396+ .fault = pax_emuplt_fault
11397+};
11398+
11399+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11400+{
11401+ int ret;
11402+
11403+ INIT_LIST_HEAD(&vma->anon_vma_chain);
11404+ vma->vm_mm = current->mm;
11405+ vma->vm_start = addr;
11406+ vma->vm_end = addr + PAGE_SIZE;
11407+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11408+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11409+ vma->vm_ops = &pax_vm_ops;
11410+
11411+ ret = insert_vm_struct(current->mm, vma);
11412+ if (ret)
11413+ return ret;
11414+
11415+ ++current->mm->total_vm;
11416+ return 0;
11417+}
11418+#endif
11419+
11420+/*
11421+ * PaX: decide what to do with offenders (regs->pc = fault address)
11422+ *
11423+ * returns 1 when task should be killed
11424+ * 2 when patched PLT trampoline was detected
11425+ * 3 when unpatched PLT trampoline was detected
11426+ */
11427+static int pax_handle_fetch_fault(struct pt_regs *regs)
11428+{
11429+
11430+#ifdef CONFIG_PAX_EMUPLT
11431+ int err;
11432+
11433+ do { /* PaX: patched PLT emulation #1 */
11434+ unsigned int sethi1, sethi2, jmpl;
11435+
11436+ err = get_user(sethi1, (unsigned int *)regs->pc);
11437+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11438+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11439+
11440+ if (err)
11441+ break;
11442+
11443+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11444+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
11445+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
11446+ {
11447+ unsigned int addr;
11448+
11449+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11450+ addr = regs->u_regs[UREG_G1];
11451+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11452+ regs->pc = addr;
11453+ regs->npc = addr+4;
11454+ return 2;
11455+ }
11456+ } while (0);
11457+
11458+ do { /* PaX: patched PLT emulation #2 */
11459+ unsigned int ba;
11460+
11461+ err = get_user(ba, (unsigned int *)regs->pc);
11462+
11463+ if (err)
11464+ break;
11465+
11466+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11467+ unsigned int addr;
11468+
11469+ if ((ba & 0xFFC00000U) == 0x30800000U)
11470+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11471+ else
11472+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11473+ regs->pc = addr;
11474+ regs->npc = addr+4;
11475+ return 2;
11476+ }
11477+ } while (0);
11478+
11479+ do { /* PaX: patched PLT emulation #3 */
11480+ unsigned int sethi, bajmpl, nop;
11481+
11482+ err = get_user(sethi, (unsigned int *)regs->pc);
11483+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11484+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
11485+
11486+ if (err)
11487+ break;
11488+
11489+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11490+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11491+ nop == 0x01000000U)
11492+ {
11493+ unsigned int addr;
11494+
11495+ addr = (sethi & 0x003FFFFFU) << 10;
11496+ regs->u_regs[UREG_G1] = addr;
11497+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11498+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11499+ else
11500+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11501+ regs->pc = addr;
11502+ regs->npc = addr+4;
11503+ return 2;
11504+ }
11505+ } while (0);
11506+
11507+ do { /* PaX: unpatched PLT emulation step 1 */
11508+ unsigned int sethi, ba, nop;
11509+
11510+ err = get_user(sethi, (unsigned int *)regs->pc);
11511+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
11512+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
11513+
11514+ if (err)
11515+ break;
11516+
11517+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11518+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11519+ nop == 0x01000000U)
11520+ {
11521+ unsigned int addr, save, call;
11522+
11523+ if ((ba & 0xFFC00000U) == 0x30800000U)
11524+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11525+ else
11526+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11527+
11528+ err = get_user(save, (unsigned int *)addr);
11529+ err |= get_user(call, (unsigned int *)(addr+4));
11530+ err |= get_user(nop, (unsigned int *)(addr+8));
11531+ if (err)
11532+ break;
11533+
11534+#ifdef CONFIG_PAX_DLRESOLVE
11535+ if (save == 0x9DE3BFA8U &&
11536+ (call & 0xC0000000U) == 0x40000000U &&
11537+ nop == 0x01000000U)
11538+ {
11539+ struct vm_area_struct *vma;
11540+ unsigned long call_dl_resolve;
11541+
11542+ down_read(&current->mm->mmap_sem);
11543+ call_dl_resolve = current->mm->call_dl_resolve;
11544+ up_read(&current->mm->mmap_sem);
11545+ if (likely(call_dl_resolve))
11546+ goto emulate;
11547+
11548+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11549+
11550+ down_write(&current->mm->mmap_sem);
11551+ if (current->mm->call_dl_resolve) {
11552+ call_dl_resolve = current->mm->call_dl_resolve;
11553+ up_write(&current->mm->mmap_sem);
11554+ if (vma)
11555+ kmem_cache_free(vm_area_cachep, vma);
11556+ goto emulate;
11557+ }
11558+
11559+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11560+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11561+ up_write(&current->mm->mmap_sem);
11562+ if (vma)
11563+ kmem_cache_free(vm_area_cachep, vma);
11564+ return 1;
11565+ }
11566+
11567+ if (pax_insert_vma(vma, call_dl_resolve)) {
11568+ up_write(&current->mm->mmap_sem);
11569+ kmem_cache_free(vm_area_cachep, vma);
11570+ return 1;
11571+ }
11572+
11573+ current->mm->call_dl_resolve = call_dl_resolve;
11574+ up_write(&current->mm->mmap_sem);
11575+
11576+emulate:
11577+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11578+ regs->pc = call_dl_resolve;
11579+ regs->npc = addr+4;
11580+ return 3;
11581+ }
11582+#endif
11583+
11584+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11585+ if ((save & 0xFFC00000U) == 0x05000000U &&
11586+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11587+ nop == 0x01000000U)
11588+ {
11589+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11590+ regs->u_regs[UREG_G2] = addr + 4;
11591+ addr = (save & 0x003FFFFFU) << 10;
11592+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11593+ regs->pc = addr;
11594+ regs->npc = addr+4;
11595+ return 3;
11596+ }
11597+ }
11598+ } while (0);
11599+
11600+ do { /* PaX: unpatched PLT emulation step 2 */
11601+ unsigned int save, call, nop;
11602+
11603+ err = get_user(save, (unsigned int *)(regs->pc-4));
11604+ err |= get_user(call, (unsigned int *)regs->pc);
11605+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
11606+ if (err)
11607+ break;
11608+
11609+ if (save == 0x9DE3BFA8U &&
11610+ (call & 0xC0000000U) == 0x40000000U &&
11611+ nop == 0x01000000U)
11612+ {
11613+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11614+
11615+ regs->u_regs[UREG_RETPC] = regs->pc;
11616+ regs->pc = dl_resolve;
11617+ regs->npc = dl_resolve+4;
11618+ return 3;
11619+ }
11620+ } while (0);
11621+#endif
11622+
11623+ return 1;
11624+}
11625+
11626+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11627+{
11628+ unsigned long i;
11629+
11630+ printk(KERN_ERR "PAX: bytes at PC: ");
11631+ for (i = 0; i < 8; i++) {
11632+ unsigned int c;
11633+ if (get_user(c, (unsigned int *)pc+i))
11634+ printk(KERN_CONT "???????? ");
11635+ else
11636+ printk(KERN_CONT "%08x ", c);
11637+ }
11638+ printk("\n");
11639+}
11640+#endif
11641+
11642 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11643 int text_fault)
11644 {
11645@@ -226,6 +500,24 @@ good_area:
11646 if (!(vma->vm_flags & VM_WRITE))
11647 goto bad_area;
11648 } else {
11649+
11650+#ifdef CONFIG_PAX_PAGEEXEC
11651+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11652+ up_read(&mm->mmap_sem);
11653+ switch (pax_handle_fetch_fault(regs)) {
11654+
11655+#ifdef CONFIG_PAX_EMUPLT
11656+ case 2:
11657+ case 3:
11658+ return;
11659+#endif
11660+
11661+ }
11662+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11663+ do_group_exit(SIGKILL);
11664+ }
11665+#endif
11666+
11667 /* Allow reads even for write-only mappings */
11668 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11669 goto bad_area;
11670diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11671index 18fcd71..e4fe821 100644
11672--- a/arch/sparc/mm/fault_64.c
11673+++ b/arch/sparc/mm/fault_64.c
11674@@ -22,6 +22,9 @@
11675 #include <linux/kdebug.h>
11676 #include <linux/percpu.h>
11677 #include <linux/context_tracking.h>
11678+#include <linux/slab.h>
11679+#include <linux/pagemap.h>
11680+#include <linux/compiler.h>
11681
11682 #include <asm/page.h>
11683 #include <asm/pgtable.h>
11684@@ -76,7 +79,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11685 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11686 regs->tpc);
11687 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11688- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11689+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11690 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11691 dump_stack();
11692 unhandled_fault(regs->tpc, current, regs);
11693@@ -279,6 +282,466 @@ static void noinline __kprobes bogus_32bit_fault_tpc(struct pt_regs *regs)
11694 show_regs(regs);
11695 }
11696
11697+#ifdef CONFIG_PAX_PAGEEXEC
11698+#ifdef CONFIG_PAX_DLRESOLVE
11699+static void pax_emuplt_close(struct vm_area_struct *vma)
11700+{
11701+ vma->vm_mm->call_dl_resolve = 0UL;
11702+}
11703+
11704+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11705+{
11706+ unsigned int *kaddr;
11707+
11708+ vmf->page = alloc_page(GFP_HIGHUSER);
11709+ if (!vmf->page)
11710+ return VM_FAULT_OOM;
11711+
11712+ kaddr = kmap(vmf->page);
11713+ memset(kaddr, 0, PAGE_SIZE);
11714+ kaddr[0] = 0x9DE3BFA8U; /* save */
11715+ flush_dcache_page(vmf->page);
11716+ kunmap(vmf->page);
11717+ return VM_FAULT_MAJOR;
11718+}
11719+
11720+static const struct vm_operations_struct pax_vm_ops = {
11721+ .close = pax_emuplt_close,
11722+ .fault = pax_emuplt_fault
11723+};
11724+
11725+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11726+{
11727+ int ret;
11728+
11729+ INIT_LIST_HEAD(&vma->anon_vma_chain);
11730+ vma->vm_mm = current->mm;
11731+ vma->vm_start = addr;
11732+ vma->vm_end = addr + PAGE_SIZE;
11733+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11734+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11735+ vma->vm_ops = &pax_vm_ops;
11736+
11737+ ret = insert_vm_struct(current->mm, vma);
11738+ if (ret)
11739+ return ret;
11740+
11741+ ++current->mm->total_vm;
11742+ return 0;
11743+}
11744+#endif
11745+
11746+/*
11747+ * PaX: decide what to do with offenders (regs->tpc = fault address)
11748+ *
11749+ * returns 1 when task should be killed
11750+ * 2 when patched PLT trampoline was detected
11751+ * 3 when unpatched PLT trampoline was detected
11752+ */
11753+static int pax_handle_fetch_fault(struct pt_regs *regs)
11754+{
11755+
11756+#ifdef CONFIG_PAX_EMUPLT
11757+ int err;
11758+
11759+ do { /* PaX: patched PLT emulation #1 */
11760+ unsigned int sethi1, sethi2, jmpl;
11761+
11762+ err = get_user(sethi1, (unsigned int *)regs->tpc);
11763+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11764+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11765+
11766+ if (err)
11767+ break;
11768+
11769+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11770+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
11771+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
11772+ {
11773+ unsigned long addr;
11774+
11775+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11776+ addr = regs->u_regs[UREG_G1];
11777+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11778+
11779+ if (test_thread_flag(TIF_32BIT))
11780+ addr &= 0xFFFFFFFFUL;
11781+
11782+ regs->tpc = addr;
11783+ regs->tnpc = addr+4;
11784+ return 2;
11785+ }
11786+ } while (0);
11787+
11788+ do { /* PaX: patched PLT emulation #2 */
11789+ unsigned int ba;
11790+
11791+ err = get_user(ba, (unsigned int *)regs->tpc);
11792+
11793+ if (err)
11794+ break;
11795+
11796+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11797+ unsigned long addr;
11798+
11799+ if ((ba & 0xFFC00000U) == 0x30800000U)
11800+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11801+ else
11802+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11803+
11804+ if (test_thread_flag(TIF_32BIT))
11805+ addr &= 0xFFFFFFFFUL;
11806+
11807+ regs->tpc = addr;
11808+ regs->tnpc = addr+4;
11809+ return 2;
11810+ }
11811+ } while (0);
11812+
11813+ do { /* PaX: patched PLT emulation #3 */
11814+ unsigned int sethi, bajmpl, nop;
11815+
11816+ err = get_user(sethi, (unsigned int *)regs->tpc);
11817+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
11818+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11819+
11820+ if (err)
11821+ break;
11822+
11823+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11824+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11825+ nop == 0x01000000U)
11826+ {
11827+ unsigned long addr;
11828+
11829+ addr = (sethi & 0x003FFFFFU) << 10;
11830+ regs->u_regs[UREG_G1] = addr;
11831+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11832+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11833+ else
11834+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11835+
11836+ if (test_thread_flag(TIF_32BIT))
11837+ addr &= 0xFFFFFFFFUL;
11838+
11839+ regs->tpc = addr;
11840+ regs->tnpc = addr+4;
11841+ return 2;
11842+ }
11843+ } while (0);
11844+
11845+ do { /* PaX: patched PLT emulation #4 */
11846+ unsigned int sethi, mov1, call, mov2;
11847+
11848+ err = get_user(sethi, (unsigned int *)regs->tpc);
11849+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11850+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
11851+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11852+
11853+ if (err)
11854+ break;
11855+
11856+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11857+ mov1 == 0x8210000FU &&
11858+ (call & 0xC0000000U) == 0x40000000U &&
11859+ mov2 == 0x9E100001U)
11860+ {
11861+ unsigned long addr;
11862+
11863+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11864+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11865+
11866+ if (test_thread_flag(TIF_32BIT))
11867+ addr &= 0xFFFFFFFFUL;
11868+
11869+ regs->tpc = addr;
11870+ regs->tnpc = addr+4;
11871+ return 2;
11872+ }
11873+ } while (0);
11874+
11875+ do { /* PaX: patched PLT emulation #5 */
11876+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11877+
11878+ err = get_user(sethi, (unsigned int *)regs->tpc);
11879+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11880+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11881+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11882+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11883+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11884+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11885+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11886+
11887+ if (err)
11888+ break;
11889+
11890+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11891+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11892+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11893+ (or1 & 0xFFFFE000U) == 0x82106000U &&
11894+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11895+ sllx == 0x83287020U &&
11896+ jmpl == 0x81C04005U &&
11897+ nop == 0x01000000U)
11898+ {
11899+ unsigned long addr;
11900+
11901+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11902+ regs->u_regs[UREG_G1] <<= 32;
11903+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11904+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11905+ regs->tpc = addr;
11906+ regs->tnpc = addr+4;
11907+ return 2;
11908+ }
11909+ } while (0);
11910+
11911+ do { /* PaX: patched PLT emulation #6 */
11912+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11913+
11914+ err = get_user(sethi, (unsigned int *)regs->tpc);
11915+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11916+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11917+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11918+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
11919+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11920+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11921+
11922+ if (err)
11923+ break;
11924+
11925+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11926+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11927+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11928+ sllx == 0x83287020U &&
11929+ (or & 0xFFFFE000U) == 0x8A116000U &&
11930+ jmpl == 0x81C04005U &&
11931+ nop == 0x01000000U)
11932+ {
11933+ unsigned long addr;
11934+
11935+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11936+ regs->u_regs[UREG_G1] <<= 32;
11937+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11938+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11939+ regs->tpc = addr;
11940+ regs->tnpc = addr+4;
11941+ return 2;
11942+ }
11943+ } while (0);
11944+
11945+ do { /* PaX: unpatched PLT emulation step 1 */
11946+ unsigned int sethi, ba, nop;
11947+
11948+ err = get_user(sethi, (unsigned int *)regs->tpc);
11949+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11950+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11951+
11952+ if (err)
11953+ break;
11954+
11955+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11956+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11957+ nop == 0x01000000U)
11958+ {
11959+ unsigned long addr;
11960+ unsigned int save, call;
11961+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11962+
11963+ if ((ba & 0xFFC00000U) == 0x30800000U)
11964+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11965+ else
11966+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11967+
11968+ if (test_thread_flag(TIF_32BIT))
11969+ addr &= 0xFFFFFFFFUL;
11970+
11971+ err = get_user(save, (unsigned int *)addr);
11972+ err |= get_user(call, (unsigned int *)(addr+4));
11973+ err |= get_user(nop, (unsigned int *)(addr+8));
11974+ if (err)
11975+ break;
11976+
11977+#ifdef CONFIG_PAX_DLRESOLVE
11978+ if (save == 0x9DE3BFA8U &&
11979+ (call & 0xC0000000U) == 0x40000000U &&
11980+ nop == 0x01000000U)
11981+ {
11982+ struct vm_area_struct *vma;
11983+ unsigned long call_dl_resolve;
11984+
11985+ down_read(&current->mm->mmap_sem);
11986+ call_dl_resolve = current->mm->call_dl_resolve;
11987+ up_read(&current->mm->mmap_sem);
11988+ if (likely(call_dl_resolve))
11989+ goto emulate;
11990+
11991+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11992+
11993+ down_write(&current->mm->mmap_sem);
11994+ if (current->mm->call_dl_resolve) {
11995+ call_dl_resolve = current->mm->call_dl_resolve;
11996+ up_write(&current->mm->mmap_sem);
11997+ if (vma)
11998+ kmem_cache_free(vm_area_cachep, vma);
11999+ goto emulate;
12000+ }
12001+
12002+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
12003+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
12004+ up_write(&current->mm->mmap_sem);
12005+ if (vma)
12006+ kmem_cache_free(vm_area_cachep, vma);
12007+ return 1;
12008+ }
12009+
12010+ if (pax_insert_vma(vma, call_dl_resolve)) {
12011+ up_write(&current->mm->mmap_sem);
12012+ kmem_cache_free(vm_area_cachep, vma);
12013+ return 1;
12014+ }
12015+
12016+ current->mm->call_dl_resolve = call_dl_resolve;
12017+ up_write(&current->mm->mmap_sem);
12018+
12019+emulate:
12020+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12021+ regs->tpc = call_dl_resolve;
12022+ regs->tnpc = addr+4;
12023+ return 3;
12024+ }
12025+#endif
12026+
12027+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
12028+ if ((save & 0xFFC00000U) == 0x05000000U &&
12029+ (call & 0xFFFFE000U) == 0x85C0A000U &&
12030+ nop == 0x01000000U)
12031+ {
12032+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12033+ regs->u_regs[UREG_G2] = addr + 4;
12034+ addr = (save & 0x003FFFFFU) << 10;
12035+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12036+
12037+ if (test_thread_flag(TIF_32BIT))
12038+ addr &= 0xFFFFFFFFUL;
12039+
12040+ regs->tpc = addr;
12041+ regs->tnpc = addr+4;
12042+ return 3;
12043+ }
12044+
12045+ /* PaX: 64-bit PLT stub */
12046+ err = get_user(sethi1, (unsigned int *)addr);
12047+ err |= get_user(sethi2, (unsigned int *)(addr+4));
12048+ err |= get_user(or1, (unsigned int *)(addr+8));
12049+ err |= get_user(or2, (unsigned int *)(addr+12));
12050+ err |= get_user(sllx, (unsigned int *)(addr+16));
12051+ err |= get_user(add, (unsigned int *)(addr+20));
12052+ err |= get_user(jmpl, (unsigned int *)(addr+24));
12053+ err |= get_user(nop, (unsigned int *)(addr+28));
12054+ if (err)
12055+ break;
12056+
12057+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
12058+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12059+ (or1 & 0xFFFFE000U) == 0x88112000U &&
12060+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
12061+ sllx == 0x89293020U &&
12062+ add == 0x8A010005U &&
12063+ jmpl == 0x89C14000U &&
12064+ nop == 0x01000000U)
12065+ {
12066+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12067+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
12068+ regs->u_regs[UREG_G4] <<= 32;
12069+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
12070+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
12071+ regs->u_regs[UREG_G4] = addr + 24;
12072+ addr = regs->u_regs[UREG_G5];
12073+ regs->tpc = addr;
12074+ regs->tnpc = addr+4;
12075+ return 3;
12076+ }
12077+ }
12078+ } while (0);
12079+
12080+#ifdef CONFIG_PAX_DLRESOLVE
12081+ do { /* PaX: unpatched PLT emulation step 2 */
12082+ unsigned int save, call, nop;
12083+
12084+ err = get_user(save, (unsigned int *)(regs->tpc-4));
12085+ err |= get_user(call, (unsigned int *)regs->tpc);
12086+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
12087+ if (err)
12088+ break;
12089+
12090+ if (save == 0x9DE3BFA8U &&
12091+ (call & 0xC0000000U) == 0x40000000U &&
12092+ nop == 0x01000000U)
12093+ {
12094+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12095+
12096+ if (test_thread_flag(TIF_32BIT))
12097+ dl_resolve &= 0xFFFFFFFFUL;
12098+
12099+ regs->u_regs[UREG_RETPC] = regs->tpc;
12100+ regs->tpc = dl_resolve;
12101+ regs->tnpc = dl_resolve+4;
12102+ return 3;
12103+ }
12104+ } while (0);
12105+#endif
12106+
12107+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
12108+ unsigned int sethi, ba, nop;
12109+
12110+ err = get_user(sethi, (unsigned int *)regs->tpc);
12111+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12112+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12113+
12114+ if (err)
12115+ break;
12116+
12117+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
12118+ (ba & 0xFFF00000U) == 0x30600000U &&
12119+ nop == 0x01000000U)
12120+ {
12121+ unsigned long addr;
12122+
12123+ addr = (sethi & 0x003FFFFFU) << 10;
12124+ regs->u_regs[UREG_G1] = addr;
12125+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12126+
12127+ if (test_thread_flag(TIF_32BIT))
12128+ addr &= 0xFFFFFFFFUL;
12129+
12130+ regs->tpc = addr;
12131+ regs->tnpc = addr+4;
12132+ return 2;
12133+ }
12134+ } while (0);
12135+
12136+#endif
12137+
12138+ return 1;
12139+}
12140+
12141+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
12142+{
12143+ unsigned long i;
12144+
12145+ printk(KERN_ERR "PAX: bytes at PC: ");
12146+ for (i = 0; i < 8; i++) {
12147+ unsigned int c;
12148+ if (get_user(c, (unsigned int *)pc+i))
12149+ printk(KERN_CONT "???????? ");
12150+ else
12151+ printk(KERN_CONT "%08x ", c);
12152+ }
12153+ printk("\n");
12154+}
12155+#endif
12156+
12157 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
12158 {
12159 enum ctx_state prev_state = exception_enter();
12160@@ -353,6 +816,29 @@ retry:
12161 if (!vma)
12162 goto bad_area;
12163
12164+#ifdef CONFIG_PAX_PAGEEXEC
12165+ /* PaX: detect ITLB misses on non-exec pages */
12166+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
12167+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
12168+ {
12169+ if (address != regs->tpc)
12170+ goto good_area;
12171+
12172+ up_read(&mm->mmap_sem);
12173+ switch (pax_handle_fetch_fault(regs)) {
12174+
12175+#ifdef CONFIG_PAX_EMUPLT
12176+ case 2:
12177+ case 3:
12178+ return;
12179+#endif
12180+
12181+ }
12182+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
12183+ do_group_exit(SIGKILL);
12184+ }
12185+#endif
12186+
12187 /* Pure DTLB misses do not tell us whether the fault causing
12188 * load/store/atomic was a write or not, it only says that there
12189 * was no match. So in such a case we (carefully) read the
12190diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
12191index d329537..2c3746a 100644
12192--- a/arch/sparc/mm/hugetlbpage.c
12193+++ b/arch/sparc/mm/hugetlbpage.c
12194@@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12195 unsigned long addr,
12196 unsigned long len,
12197 unsigned long pgoff,
12198- unsigned long flags)
12199+ unsigned long flags,
12200+ unsigned long offset)
12201 {
12202+ struct mm_struct *mm = current->mm;
12203 unsigned long task_size = TASK_SIZE;
12204 struct vm_unmapped_area_info info;
12205
12206@@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12207
12208 info.flags = 0;
12209 info.length = len;
12210- info.low_limit = TASK_UNMAPPED_BASE;
12211+ info.low_limit = mm->mmap_base;
12212 info.high_limit = min(task_size, VA_EXCLUDE_START);
12213 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12214 info.align_offset = 0;
12215+ info.threadstack_offset = offset;
12216 addr = vm_unmapped_area(&info);
12217
12218 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
12219 VM_BUG_ON(addr != -ENOMEM);
12220 info.low_limit = VA_EXCLUDE_END;
12221+
12222+#ifdef CONFIG_PAX_RANDMMAP
12223+ if (mm->pax_flags & MF_PAX_RANDMMAP)
12224+ info.low_limit += mm->delta_mmap;
12225+#endif
12226+
12227 info.high_limit = task_size;
12228 addr = vm_unmapped_area(&info);
12229 }
12230@@ -55,7 +64,8 @@ static unsigned long
12231 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12232 const unsigned long len,
12233 const unsigned long pgoff,
12234- const unsigned long flags)
12235+ const unsigned long flags,
12236+ const unsigned long offset)
12237 {
12238 struct mm_struct *mm = current->mm;
12239 unsigned long addr = addr0;
12240@@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12241 info.high_limit = mm->mmap_base;
12242 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12243 info.align_offset = 0;
12244+ info.threadstack_offset = offset;
12245 addr = vm_unmapped_area(&info);
12246
12247 /*
12248@@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12249 VM_BUG_ON(addr != -ENOMEM);
12250 info.flags = 0;
12251 info.low_limit = TASK_UNMAPPED_BASE;
12252+
12253+#ifdef CONFIG_PAX_RANDMMAP
12254+ if (mm->pax_flags & MF_PAX_RANDMMAP)
12255+ info.low_limit += mm->delta_mmap;
12256+#endif
12257+
12258 info.high_limit = STACK_TOP32;
12259 addr = vm_unmapped_area(&info);
12260 }
12261@@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12262 struct mm_struct *mm = current->mm;
12263 struct vm_area_struct *vma;
12264 unsigned long task_size = TASK_SIZE;
12265+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
12266
12267 if (test_thread_flag(TIF_32BIT))
12268 task_size = STACK_TOP32;
12269@@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12270 return addr;
12271 }
12272
12273+#ifdef CONFIG_PAX_RANDMMAP
12274+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
12275+#endif
12276+
12277 if (addr) {
12278 addr = ALIGN(addr, HPAGE_SIZE);
12279 vma = find_vma(mm, addr);
12280- if (task_size - len >= addr &&
12281- (!vma || addr + len <= vma->vm_start))
12282+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
12283 return addr;
12284 }
12285 if (mm->get_unmapped_area == arch_get_unmapped_area)
12286 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
12287- pgoff, flags);
12288+ pgoff, flags, offset);
12289 else
12290 return hugetlb_get_unmapped_area_topdown(file, addr, len,
12291- pgoff, flags);
12292+ pgoff, flags, offset);
12293 }
12294
12295 pte_t *huge_pte_alloc(struct mm_struct *mm,
12296diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
12297index 2d91c62..17a8fff 100644
12298--- a/arch/sparc/mm/init_64.c
12299+++ b/arch/sparc/mm/init_64.c
12300@@ -186,9 +186,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
12301 int num_kernel_image_mappings;
12302
12303 #ifdef CONFIG_DEBUG_DCFLUSH
12304-atomic_t dcpage_flushes = ATOMIC_INIT(0);
12305+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
12306 #ifdef CONFIG_SMP
12307-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12308+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12309 #endif
12310 #endif
12311
12312@@ -196,7 +196,7 @@ inline void flush_dcache_page_impl(struct page *page)
12313 {
12314 BUG_ON(tlb_type == hypervisor);
12315 #ifdef CONFIG_DEBUG_DCFLUSH
12316- atomic_inc(&dcpage_flushes);
12317+ atomic_inc_unchecked(&dcpage_flushes);
12318 #endif
12319
12320 #ifdef DCACHE_ALIASING_POSSIBLE
12321@@ -468,10 +468,10 @@ void mmu_info(struct seq_file *m)
12322
12323 #ifdef CONFIG_DEBUG_DCFLUSH
12324 seq_printf(m, "DCPageFlushes\t: %d\n",
12325- atomic_read(&dcpage_flushes));
12326+ atomic_read_unchecked(&dcpage_flushes));
12327 #ifdef CONFIG_SMP
12328 seq_printf(m, "DCPageFlushesXC\t: %d\n",
12329- atomic_read(&dcpage_flushes_xcall));
12330+ atomic_read_unchecked(&dcpage_flushes_xcall));
12331 #endif /* CONFIG_SMP */
12332 #endif /* CONFIG_DEBUG_DCFLUSH */
12333 }
12334diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
12335index 7cca418..53fc030 100644
12336--- a/arch/tile/Kconfig
12337+++ b/arch/tile/Kconfig
12338@@ -192,6 +192,7 @@ source "kernel/Kconfig.hz"
12339
12340 config KEXEC
12341 bool "kexec system call"
12342+ depends on !GRKERNSEC_KMEM
12343 ---help---
12344 kexec is a system call that implements the ability to shutdown your
12345 current kernel, and to start another kernel. It is like a reboot
12346diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
12347index 7b11c5f..755a026 100644
12348--- a/arch/tile/include/asm/atomic_64.h
12349+++ b/arch/tile/include/asm/atomic_64.h
12350@@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
12351
12352 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12353
12354+#define atomic64_read_unchecked(v) atomic64_read(v)
12355+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
12356+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
12357+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
12358+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
12359+#define atomic64_inc_unchecked(v) atomic64_inc(v)
12360+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
12361+#define atomic64_dec_unchecked(v) atomic64_dec(v)
12362+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
12363+
12364 /* Define this to indicate that cmpxchg is an efficient operation. */
12365 #define __HAVE_ARCH_CMPXCHG
12366
12367diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
12368index 6160761..00cac88 100644
12369--- a/arch/tile/include/asm/cache.h
12370+++ b/arch/tile/include/asm/cache.h
12371@@ -15,11 +15,12 @@
12372 #ifndef _ASM_TILE_CACHE_H
12373 #define _ASM_TILE_CACHE_H
12374
12375+#include <linux/const.h>
12376 #include <arch/chip.h>
12377
12378 /* bytes per L1 data cache line */
12379 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
12380-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12381+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12382
12383 /* bytes per L2 cache line */
12384 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
12385diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
12386index b6cde32..c0cb736 100644
12387--- a/arch/tile/include/asm/uaccess.h
12388+++ b/arch/tile/include/asm/uaccess.h
12389@@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
12390 const void __user *from,
12391 unsigned long n)
12392 {
12393- int sz = __compiletime_object_size(to);
12394+ size_t sz = __compiletime_object_size(to);
12395
12396- if (likely(sz == -1 || sz >= n))
12397+ if (likely(sz == (size_t)-1 || sz >= n))
12398 n = _copy_from_user(to, from, n);
12399 else
12400 copy_from_user_overflow();
12401diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
12402index e514899..f8743c4 100644
12403--- a/arch/tile/mm/hugetlbpage.c
12404+++ b/arch/tile/mm/hugetlbpage.c
12405@@ -207,6 +207,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
12406 info.high_limit = TASK_SIZE;
12407 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12408 info.align_offset = 0;
12409+ info.threadstack_offset = 0;
12410 return vm_unmapped_area(&info);
12411 }
12412
12413@@ -224,6 +225,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
12414 info.high_limit = current->mm->mmap_base;
12415 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12416 info.align_offset = 0;
12417+ info.threadstack_offset = 0;
12418 addr = vm_unmapped_area(&info);
12419
12420 /*
12421diff --git a/arch/um/Makefile b/arch/um/Makefile
12422index e4b1a96..16162f8 100644
12423--- a/arch/um/Makefile
12424+++ b/arch/um/Makefile
12425@@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
12426 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
12427 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
12428
12429+ifdef CONSTIFY_PLUGIN
12430+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12431+endif
12432+
12433 #This will adjust *FLAGS accordingly to the platform.
12434 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
12435
12436diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
12437index 19e1bdd..3665b77 100644
12438--- a/arch/um/include/asm/cache.h
12439+++ b/arch/um/include/asm/cache.h
12440@@ -1,6 +1,7 @@
12441 #ifndef __UM_CACHE_H
12442 #define __UM_CACHE_H
12443
12444+#include <linux/const.h>
12445
12446 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12447 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12448@@ -12,6 +13,6 @@
12449 # define L1_CACHE_SHIFT 5
12450 #endif
12451
12452-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12453+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12454
12455 #endif
12456diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12457index 2e0a6b1..a64d0f5 100644
12458--- a/arch/um/include/asm/kmap_types.h
12459+++ b/arch/um/include/asm/kmap_types.h
12460@@ -8,6 +8,6 @@
12461
12462 /* No more #include "asm/arch/kmap_types.h" ! */
12463
12464-#define KM_TYPE_NR 14
12465+#define KM_TYPE_NR 15
12466
12467 #endif
12468diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12469index 71c5d13..4c7b9f1 100644
12470--- a/arch/um/include/asm/page.h
12471+++ b/arch/um/include/asm/page.h
12472@@ -14,6 +14,9 @@
12473 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12474 #define PAGE_MASK (~(PAGE_SIZE-1))
12475
12476+#define ktla_ktva(addr) (addr)
12477+#define ktva_ktla(addr) (addr)
12478+
12479 #ifndef __ASSEMBLY__
12480
12481 struct page;
12482diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12483index 0032f92..cd151e0 100644
12484--- a/arch/um/include/asm/pgtable-3level.h
12485+++ b/arch/um/include/asm/pgtable-3level.h
12486@@ -58,6 +58,7 @@
12487 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12488 #define pud_populate(mm, pud, pmd) \
12489 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12490+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12491
12492 #ifdef CONFIG_64BIT
12493 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12494diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12495index f17bca8..48adb87 100644
12496--- a/arch/um/kernel/process.c
12497+++ b/arch/um/kernel/process.c
12498@@ -356,22 +356,6 @@ int singlestepping(void * t)
12499 return 2;
12500 }
12501
12502-/*
12503- * Only x86 and x86_64 have an arch_align_stack().
12504- * All other arches have "#define arch_align_stack(x) (x)"
12505- * in their asm/exec.h
12506- * As this is included in UML from asm-um/system-generic.h,
12507- * we can use it to behave as the subarch does.
12508- */
12509-#ifndef arch_align_stack
12510-unsigned long arch_align_stack(unsigned long sp)
12511-{
12512- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12513- sp -= get_random_int() % 8192;
12514- return sp & ~0xf;
12515-}
12516-#endif
12517-
12518 unsigned long get_wchan(struct task_struct *p)
12519 {
12520 unsigned long stack_page, sp, ip;
12521diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12522index ad8f795..2c7eec6 100644
12523--- a/arch/unicore32/include/asm/cache.h
12524+++ b/arch/unicore32/include/asm/cache.h
12525@@ -12,8 +12,10 @@
12526 #ifndef __UNICORE_CACHE_H__
12527 #define __UNICORE_CACHE_H__
12528
12529-#define L1_CACHE_SHIFT (5)
12530-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12531+#include <linux/const.h>
12532+
12533+#define L1_CACHE_SHIFT 5
12534+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12535
12536 /*
12537 * Memory returned by kmalloc() may be used for DMA, so we must make
12538diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12539index 41a503c..cf98b04 100644
12540--- a/arch/x86/Kconfig
12541+++ b/arch/x86/Kconfig
12542@@ -129,7 +129,7 @@ config X86
12543 select RTC_LIB
12544 select HAVE_DEBUG_STACKOVERFLOW
12545 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
12546- select HAVE_CC_STACKPROTECTOR
12547+ select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
12548 select GENERIC_CPU_AUTOPROBE
12549 select HAVE_ARCH_AUDITSYSCALL
12550 select ARCH_SUPPORTS_ATOMIC_RMW
12551@@ -262,7 +262,7 @@ config X86_HT
12552
12553 config X86_32_LAZY_GS
12554 def_bool y
12555- depends on X86_32 && !CC_STACKPROTECTOR
12556+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12557
12558 config ARCH_HWEIGHT_CFLAGS
12559 string
12560@@ -600,6 +600,7 @@ config SCHED_OMIT_FRAME_POINTER
12561
12562 menuconfig HYPERVISOR_GUEST
12563 bool "Linux guest support"
12564+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12565 ---help---
12566 Say Y here to enable options for running Linux under various hyper-
12567 visors. This option enables basic hypervisor detection and platform
12568@@ -973,6 +974,7 @@ config VM86
12569
12570 config X86_16BIT
12571 bool "Enable support for 16-bit segments" if EXPERT
12572+ depends on !GRKERNSEC
12573 default y
12574 ---help---
12575 This option is required by programs like Wine to run 16-bit
12576@@ -1128,6 +1130,7 @@ choice
12577
12578 config NOHIGHMEM
12579 bool "off"
12580+ depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12581 ---help---
12582 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12583 However, the address space of 32-bit x86 processors is only 4
12584@@ -1164,6 +1167,7 @@ config NOHIGHMEM
12585
12586 config HIGHMEM4G
12587 bool "4GB"
12588+ depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12589 ---help---
12590 Select this if you have a 32-bit processor and between 1 and 4
12591 gigabytes of physical RAM.
12592@@ -1216,7 +1220,7 @@ config PAGE_OFFSET
12593 hex
12594 default 0xB0000000 if VMSPLIT_3G_OPT
12595 default 0x80000000 if VMSPLIT_2G
12596- default 0x78000000 if VMSPLIT_2G_OPT
12597+ default 0x70000000 if VMSPLIT_2G_OPT
12598 default 0x40000000 if VMSPLIT_1G
12599 default 0xC0000000
12600 depends on X86_32
12601@@ -1631,6 +1635,7 @@ source kernel/Kconfig.hz
12602
12603 config KEXEC
12604 bool "kexec system call"
12605+ depends on !GRKERNSEC_KMEM
12606 ---help---
12607 kexec is a system call that implements the ability to shutdown your
12608 current kernel, and to start another kernel. It is like a reboot
12609@@ -1816,7 +1821,9 @@ config X86_NEED_RELOCS
12610
12611 config PHYSICAL_ALIGN
12612 hex "Alignment value to which kernel should be aligned"
12613- default "0x200000"
12614+ default "0x1000000"
12615+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12616+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12617 range 0x2000 0x1000000 if X86_32
12618 range 0x200000 0x1000000 if X86_64
12619 ---help---
12620@@ -1899,6 +1906,7 @@ config COMPAT_VDSO
12621 def_bool n
12622 prompt "Disable the 32-bit vDSO (needed for glibc 2.3.3)"
12623 depends on X86_32 || IA32_EMULATION
12624+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12625 ---help---
12626 Certain buggy versions of glibc will crash if they are
12627 presented with a 32-bit vDSO that is not mapped at the address
12628diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12629index 6983314..54ad7e8 100644
12630--- a/arch/x86/Kconfig.cpu
12631+++ b/arch/x86/Kconfig.cpu
12632@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12633
12634 config X86_F00F_BUG
12635 def_bool y
12636- depends on M586MMX || M586TSC || M586 || M486
12637+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12638
12639 config X86_INVD_BUG
12640 def_bool y
12641@@ -327,7 +327,7 @@ config X86_INVD_BUG
12642
12643 config X86_ALIGNMENT_16
12644 def_bool y
12645- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12646+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12647
12648 config X86_INTEL_USERCOPY
12649 def_bool y
12650@@ -369,7 +369,7 @@ config X86_CMPXCHG64
12651 # generates cmov.
12652 config X86_CMOV
12653 def_bool y
12654- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12655+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12656
12657 config X86_MINIMUM_CPU_FAMILY
12658 int
12659diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12660index 61bd2ad..50b625d 100644
12661--- a/arch/x86/Kconfig.debug
12662+++ b/arch/x86/Kconfig.debug
12663@@ -93,7 +93,7 @@ config EFI_PGT_DUMP
12664 config DEBUG_RODATA
12665 bool "Write protect kernel read-only data structures"
12666 default y
12667- depends on DEBUG_KERNEL
12668+ depends on DEBUG_KERNEL && BROKEN
12669 ---help---
12670 Mark the kernel read-only data as write-protected in the pagetables,
12671 in order to catch accidental (and incorrect) writes to such const
12672@@ -111,7 +111,7 @@ config DEBUG_RODATA_TEST
12673
12674 config DEBUG_SET_MODULE_RONX
12675 bool "Set loadable kernel module data as NX and text as RO"
12676- depends on MODULES
12677+ depends on MODULES && BROKEN
12678 ---help---
12679 This option helps catch unintended modifications to loadable
12680 kernel module's text and read-only data. It also prevents execution
12681diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12682index 920e616..ac3d4df 100644
12683--- a/arch/x86/Makefile
12684+++ b/arch/x86/Makefile
12685@@ -65,9 +65,6 @@ ifeq ($(CONFIG_X86_32),y)
12686 # CPU-specific tuning. Anything which can be shared with UML should go here.
12687 include $(srctree)/arch/x86/Makefile_32.cpu
12688 KBUILD_CFLAGS += $(cflags-y)
12689-
12690- # temporary until string.h is fixed
12691- KBUILD_CFLAGS += -ffreestanding
12692 else
12693 BITS := 64
12694 UTS_MACHINE := x86_64
12695@@ -107,6 +104,9 @@ else
12696 KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args)
12697 endif
12698
12699+# temporary until string.h is fixed
12700+KBUILD_CFLAGS += -ffreestanding
12701+
12702 # Make sure compiler does not have buggy stack-protector support.
12703 ifdef CONFIG_CC_STACKPROTECTOR
12704 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12705@@ -180,6 +180,7 @@ archheaders:
12706 $(Q)$(MAKE) $(build)=arch/x86/syscalls all
12707
12708 archprepare:
12709+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12710 ifeq ($(CONFIG_KEXEC_FILE),y)
12711 $(Q)$(MAKE) $(build)=arch/x86/purgatory arch/x86/purgatory/kexec-purgatory.c
12712 endif
12713@@ -263,3 +264,9 @@ define archhelp
12714 echo ' FDARGS="..." arguments for the booted kernel'
12715 echo ' FDINITRD=file initrd for the booted kernel'
12716 endef
12717+
12718+define OLD_LD
12719+
12720+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12721+*** Please upgrade your binutils to 2.18 or newer
12722+endef
12723diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12724index 5b016e2..04ef69c 100644
12725--- a/arch/x86/boot/Makefile
12726+++ b/arch/x86/boot/Makefile
12727@@ -55,6 +55,9 @@ endif
12728 # ---------------------------------------------------------------------------
12729
12730 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
12731+ifdef CONSTIFY_PLUGIN
12732+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12733+endif
12734 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12735 GCOV_PROFILE := n
12736
12737diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12738index 878e4b9..20537ab 100644
12739--- a/arch/x86/boot/bitops.h
12740+++ b/arch/x86/boot/bitops.h
12741@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12742 u8 v;
12743 const u32 *p = (const u32 *)addr;
12744
12745- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12746+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12747 return v;
12748 }
12749
12750@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12751
12752 static inline void set_bit(int nr, void *addr)
12753 {
12754- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12755+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12756 }
12757
12758 #endif /* BOOT_BITOPS_H */
12759diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12760index bd49ec6..94c7f58 100644
12761--- a/arch/x86/boot/boot.h
12762+++ b/arch/x86/boot/boot.h
12763@@ -84,7 +84,7 @@ static inline void io_delay(void)
12764 static inline u16 ds(void)
12765 {
12766 u16 seg;
12767- asm("movw %%ds,%0" : "=rm" (seg));
12768+ asm volatile("movw %%ds,%0" : "=rm" (seg));
12769 return seg;
12770 }
12771
12772diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12773index 45abc36..97bea2d 100644
12774--- a/arch/x86/boot/compressed/Makefile
12775+++ b/arch/x86/boot/compressed/Makefile
12776@@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12777 KBUILD_CFLAGS += -mno-mmx -mno-sse
12778 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12779 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12780+ifdef CONSTIFY_PLUGIN
12781+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12782+endif
12783
12784 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12785 GCOV_PROFILE := n
12786diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12787index a53440e..c3dbf1e 100644
12788--- a/arch/x86/boot/compressed/efi_stub_32.S
12789+++ b/arch/x86/boot/compressed/efi_stub_32.S
12790@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12791 * parameter 2, ..., param n. To make things easy, we save the return
12792 * address of efi_call_phys in a global variable.
12793 */
12794- popl %ecx
12795- movl %ecx, saved_return_addr(%edx)
12796- /* get the function pointer into ECX*/
12797- popl %ecx
12798- movl %ecx, efi_rt_function_ptr(%edx)
12799+ popl saved_return_addr(%edx)
12800+ popl efi_rt_function_ptr(%edx)
12801
12802 /*
12803 * 3. Call the physical function.
12804 */
12805- call *%ecx
12806+ call *efi_rt_function_ptr(%edx)
12807
12808 /*
12809 * 4. Balance the stack. And because EAX contain the return value,
12810@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12811 1: popl %edx
12812 subl $1b, %edx
12813
12814- movl efi_rt_function_ptr(%edx), %ecx
12815- pushl %ecx
12816+ pushl efi_rt_function_ptr(%edx)
12817
12818 /*
12819 * 10. Push the saved return address onto the stack and return.
12820 */
12821- movl saved_return_addr(%edx), %ecx
12822- pushl %ecx
12823- ret
12824+ jmpl *saved_return_addr(%edx)
12825 ENDPROC(efi_call_phys)
12826 .previous
12827
12828diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12829index 1d7fbbc..36ecd58 100644
12830--- a/arch/x86/boot/compressed/head_32.S
12831+++ b/arch/x86/boot/compressed/head_32.S
12832@@ -140,10 +140,10 @@ preferred_addr:
12833 addl %eax, %ebx
12834 notl %eax
12835 andl %eax, %ebx
12836- cmpl $LOAD_PHYSICAL_ADDR, %ebx
12837+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12838 jge 1f
12839 #endif
12840- movl $LOAD_PHYSICAL_ADDR, %ebx
12841+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12842 1:
12843
12844 /* Target address to relocate to for decompression */
12845diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12846index 6b1766c..ad465c9 100644
12847--- a/arch/x86/boot/compressed/head_64.S
12848+++ b/arch/x86/boot/compressed/head_64.S
12849@@ -94,10 +94,10 @@ ENTRY(startup_32)
12850 addl %eax, %ebx
12851 notl %eax
12852 andl %eax, %ebx
12853- cmpl $LOAD_PHYSICAL_ADDR, %ebx
12854+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12855 jge 1f
12856 #endif
12857- movl $LOAD_PHYSICAL_ADDR, %ebx
12858+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12859 1:
12860
12861 /* Target address to relocate to for decompression */
12862@@ -322,10 +322,10 @@ preferred_addr:
12863 addq %rax, %rbp
12864 notq %rax
12865 andq %rax, %rbp
12866- cmpq $LOAD_PHYSICAL_ADDR, %rbp
12867+ cmpq $____LOAD_PHYSICAL_ADDR, %rbp
12868 jge 1f
12869 #endif
12870- movq $LOAD_PHYSICAL_ADDR, %rbp
12871+ movq $____LOAD_PHYSICAL_ADDR, %rbp
12872 1:
12873
12874 /* Target address to relocate to for decompression */
12875@@ -434,8 +434,8 @@ gdt:
12876 .long gdt
12877 .word 0
12878 .quad 0x0000000000000000 /* NULL descriptor */
12879- .quad 0x00af9a000000ffff /* __KERNEL_CS */
12880- .quad 0x00cf92000000ffff /* __KERNEL_DS */
12881+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
12882+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
12883 .quad 0x0080890000000000 /* TS descriptor */
12884 .quad 0x0000000000000000 /* TS continued */
12885 gdt_end:
12886diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12887index 30dd59a..cd9edc3 100644
12888--- a/arch/x86/boot/compressed/misc.c
12889+++ b/arch/x86/boot/compressed/misc.c
12890@@ -242,7 +242,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12891 * Calculate the delta between where vmlinux was linked to load
12892 * and where it was actually loaded.
12893 */
12894- delta = min_addr - LOAD_PHYSICAL_ADDR;
12895+ delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12896 if (!delta) {
12897 debug_putstr("No relocation needed... ");
12898 return;
12899@@ -312,7 +312,7 @@ static void parse_elf(void *output)
12900 Elf32_Ehdr ehdr;
12901 Elf32_Phdr *phdrs, *phdr;
12902 #endif
12903- void *dest;
12904+ void *dest, *prev;
12905 int i;
12906
12907 memcpy(&ehdr, output, sizeof(ehdr));
12908@@ -339,13 +339,16 @@ static void parse_elf(void *output)
12909 case PT_LOAD:
12910 #ifdef CONFIG_RELOCATABLE
12911 dest = output;
12912- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12913+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12914 #else
12915 dest = (void *)(phdr->p_paddr);
12916 #endif
12917 memcpy(dest,
12918 output + phdr->p_offset,
12919 phdr->p_filesz);
12920+ if (i)
12921+ memset(prev, 0xff, dest - prev);
12922+ prev = dest + phdr->p_filesz;
12923 break;
12924 default: /* Ignore other PT_* */ break;
12925 }
12926@@ -402,7 +405,7 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
12927 error("Destination address too large");
12928 #endif
12929 #ifndef CONFIG_RELOCATABLE
12930- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12931+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12932 error("Wrong destination address");
12933 #endif
12934
12935diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12936index 1fd7d57..0f7d096 100644
12937--- a/arch/x86/boot/cpucheck.c
12938+++ b/arch/x86/boot/cpucheck.c
12939@@ -125,9 +125,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12940 u32 ecx = MSR_K7_HWCR;
12941 u32 eax, edx;
12942
12943- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12944+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12945 eax &= ~(1 << 15);
12946- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12947+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12948
12949 get_cpuflags(); /* Make sure it really did something */
12950 err = check_cpuflags();
12951@@ -140,9 +140,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12952 u32 ecx = MSR_VIA_FCR;
12953 u32 eax, edx;
12954
12955- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12956+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12957 eax |= (1<<1)|(1<<7);
12958- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12959+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12960
12961 set_bit(X86_FEATURE_CX8, cpu.flags);
12962 err = check_cpuflags();
12963@@ -153,12 +153,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12964 u32 eax, edx;
12965 u32 level = 1;
12966
12967- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12968- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12969- asm("cpuid"
12970+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12971+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12972+ asm volatile("cpuid"
12973 : "+a" (level), "=d" (cpu.flags[0])
12974 : : "ecx", "ebx");
12975- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12976+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12977
12978 err = check_cpuflags();
12979 } else if (err == 0x01 &&
12980diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12981index 16ef025..91e033b 100644
12982--- a/arch/x86/boot/header.S
12983+++ b/arch/x86/boot/header.S
12984@@ -438,10 +438,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12985 # single linked list of
12986 # struct setup_data
12987
12988-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12989+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12990
12991 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12992+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12993+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12994+#else
12995 #define VO_INIT_SIZE (VO__end - VO__text)
12996+#endif
12997 #if ZO_INIT_SIZE > VO_INIT_SIZE
12998 #define INIT_SIZE ZO_INIT_SIZE
12999 #else
13000diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
13001index db75d07..8e6d0af 100644
13002--- a/arch/x86/boot/memory.c
13003+++ b/arch/x86/boot/memory.c
13004@@ -19,7 +19,7 @@
13005
13006 static int detect_memory_e820(void)
13007 {
13008- int count = 0;
13009+ unsigned int count = 0;
13010 struct biosregs ireg, oreg;
13011 struct e820entry *desc = boot_params.e820_map;
13012 static struct e820entry buf; /* static so it is zeroed */
13013diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
13014index ba3e100..6501b8f 100644
13015--- a/arch/x86/boot/video-vesa.c
13016+++ b/arch/x86/boot/video-vesa.c
13017@@ -201,6 +201,7 @@ static void vesa_store_pm_info(void)
13018
13019 boot_params.screen_info.vesapm_seg = oreg.es;
13020 boot_params.screen_info.vesapm_off = oreg.di;
13021+ boot_params.screen_info.vesapm_size = oreg.cx;
13022 }
13023
13024 /*
13025diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
13026index 43eda28..5ab5fdb 100644
13027--- a/arch/x86/boot/video.c
13028+++ b/arch/x86/boot/video.c
13029@@ -96,7 +96,7 @@ static void store_mode_params(void)
13030 static unsigned int get_entry(void)
13031 {
13032 char entry_buf[4];
13033- int i, len = 0;
13034+ unsigned int i, len = 0;
13035 int key;
13036 unsigned int v;
13037
13038diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
13039index 9105655..41779c1 100644
13040--- a/arch/x86/crypto/aes-x86_64-asm_64.S
13041+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
13042@@ -8,6 +8,8 @@
13043 * including this sentence is retained in full.
13044 */
13045
13046+#include <asm/alternative-asm.h>
13047+
13048 .extern crypto_ft_tab
13049 .extern crypto_it_tab
13050 .extern crypto_fl_tab
13051@@ -70,6 +72,8 @@
13052 je B192; \
13053 leaq 32(r9),r9;
13054
13055+#define ret pax_force_retaddr; ret
13056+
13057 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
13058 movq r1,r2; \
13059 movq r3,r4; \
13060diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
13061index 477e9d7..c92c7d8 100644
13062--- a/arch/x86/crypto/aesni-intel_asm.S
13063+++ b/arch/x86/crypto/aesni-intel_asm.S
13064@@ -31,6 +31,7 @@
13065
13066 #include <linux/linkage.h>
13067 #include <asm/inst.h>
13068+#include <asm/alternative-asm.h>
13069
13070 #ifdef __x86_64__
13071 .data
13072@@ -205,7 +206,7 @@ enc: .octa 0x2
13073 * num_initial_blocks = b mod 4
13074 * encrypt the initial num_initial_blocks blocks and apply ghash on
13075 * the ciphertext
13076-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13077+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13078 * are clobbered
13079 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13080 */
13081@@ -214,8 +215,8 @@ enc: .octa 0x2
13082 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13083 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13084 mov arg7, %r10 # %r10 = AAD
13085- mov arg8, %r12 # %r12 = aadLen
13086- mov %r12, %r11
13087+ mov arg8, %r15 # %r15 = aadLen
13088+ mov %r15, %r11
13089 pxor %xmm\i, %xmm\i
13090 _get_AAD_loop\num_initial_blocks\operation:
13091 movd (%r10), \TMP1
13092@@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13093 psrldq $4, %xmm\i
13094 pxor \TMP1, %xmm\i
13095 add $4, %r10
13096- sub $4, %r12
13097+ sub $4, %r15
13098 jne _get_AAD_loop\num_initial_blocks\operation
13099 cmp $16, %r11
13100 je _get_AAD_loop2_done\num_initial_blocks\operation
13101- mov $16, %r12
13102+ mov $16, %r15
13103 _get_AAD_loop2\num_initial_blocks\operation:
13104 psrldq $4, %xmm\i
13105- sub $4, %r12
13106- cmp %r11, %r12
13107+ sub $4, %r15
13108+ cmp %r11, %r15
13109 jne _get_AAD_loop2\num_initial_blocks\operation
13110 _get_AAD_loop2_done\num_initial_blocks\operation:
13111 movdqa SHUF_MASK(%rip), %xmm14
13112@@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
13113 * num_initial_blocks = b mod 4
13114 * encrypt the initial num_initial_blocks blocks and apply ghash on
13115 * the ciphertext
13116-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13117+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13118 * are clobbered
13119 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13120 */
13121@@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
13122 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13123 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13124 mov arg7, %r10 # %r10 = AAD
13125- mov arg8, %r12 # %r12 = aadLen
13126- mov %r12, %r11
13127+ mov arg8, %r15 # %r15 = aadLen
13128+ mov %r15, %r11
13129 pxor %xmm\i, %xmm\i
13130 _get_AAD_loop\num_initial_blocks\operation:
13131 movd (%r10), \TMP1
13132@@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13133 psrldq $4, %xmm\i
13134 pxor \TMP1, %xmm\i
13135 add $4, %r10
13136- sub $4, %r12
13137+ sub $4, %r15
13138 jne _get_AAD_loop\num_initial_blocks\operation
13139 cmp $16, %r11
13140 je _get_AAD_loop2_done\num_initial_blocks\operation
13141- mov $16, %r12
13142+ mov $16, %r15
13143 _get_AAD_loop2\num_initial_blocks\operation:
13144 psrldq $4, %xmm\i
13145- sub $4, %r12
13146- cmp %r11, %r12
13147+ sub $4, %r15
13148+ cmp %r11, %r15
13149 jne _get_AAD_loop2\num_initial_blocks\operation
13150 _get_AAD_loop2_done\num_initial_blocks\operation:
13151 movdqa SHUF_MASK(%rip), %xmm14
13152@@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
13153 *
13154 *****************************************************************************/
13155 ENTRY(aesni_gcm_dec)
13156- push %r12
13157+ push %r15
13158 push %r13
13159 push %r14
13160 mov %rsp, %r14
13161@@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
13162 */
13163 sub $VARIABLE_OFFSET, %rsp
13164 and $~63, %rsp # align rsp to 64 bytes
13165- mov %arg6, %r12
13166- movdqu (%r12), %xmm13 # %xmm13 = HashKey
13167+ mov %arg6, %r15
13168+ movdqu (%r15), %xmm13 # %xmm13 = HashKey
13169 movdqa SHUF_MASK(%rip), %xmm2
13170 PSHUFB_XMM %xmm2, %xmm13
13171
13172@@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
13173 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
13174 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
13175 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
13176- mov %r13, %r12
13177- and $(3<<4), %r12
13178+ mov %r13, %r15
13179+ and $(3<<4), %r15
13180 jz _initial_num_blocks_is_0_decrypt
13181- cmp $(2<<4), %r12
13182+ cmp $(2<<4), %r15
13183 jb _initial_num_blocks_is_1_decrypt
13184 je _initial_num_blocks_is_2_decrypt
13185 _initial_num_blocks_is_3_decrypt:
13186@@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
13187 sub $16, %r11
13188 add %r13, %r11
13189 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
13190- lea SHIFT_MASK+16(%rip), %r12
13191- sub %r13, %r12
13192+ lea SHIFT_MASK+16(%rip), %r15
13193+ sub %r13, %r15
13194 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
13195 # (%r13 is the number of bytes in plaintext mod 16)
13196- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13197+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13198 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
13199
13200 movdqa %xmm1, %xmm2
13201 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
13202- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13203+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13204 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
13205 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
13206 pand %xmm1, %xmm2
13207@@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
13208 sub $1, %r13
13209 jne _less_than_8_bytes_left_decrypt
13210 _multiple_of_16_bytes_decrypt:
13211- mov arg8, %r12 # %r13 = aadLen (number of bytes)
13212- shl $3, %r12 # convert into number of bits
13213- movd %r12d, %xmm15 # len(A) in %xmm15
13214+ mov arg8, %r15 # %r13 = aadLen (number of bytes)
13215+ shl $3, %r15 # convert into number of bits
13216+ movd %r15d, %xmm15 # len(A) in %xmm15
13217 shl $3, %arg4 # len(C) in bits (*128)
13218 MOVQ_R64_XMM %arg4, %xmm1
13219 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13220@@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
13221 mov %r14, %rsp
13222 pop %r14
13223 pop %r13
13224- pop %r12
13225+ pop %r15
13226+ pax_force_retaddr
13227 ret
13228 ENDPROC(aesni_gcm_dec)
13229
13230@@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
13231 * poly = x^128 + x^127 + x^126 + x^121 + 1
13232 ***************************************************************************/
13233 ENTRY(aesni_gcm_enc)
13234- push %r12
13235+ push %r15
13236 push %r13
13237 push %r14
13238 mov %rsp, %r14
13239@@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
13240 #
13241 sub $VARIABLE_OFFSET, %rsp
13242 and $~63, %rsp
13243- mov %arg6, %r12
13244- movdqu (%r12), %xmm13
13245+ mov %arg6, %r15
13246+ movdqu (%r15), %xmm13
13247 movdqa SHUF_MASK(%rip), %xmm2
13248 PSHUFB_XMM %xmm2, %xmm13
13249
13250@@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
13251 movdqa %xmm13, HashKey(%rsp)
13252 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
13253 and $-16, %r13
13254- mov %r13, %r12
13255+ mov %r13, %r15
13256
13257 # Encrypt first few blocks
13258
13259- and $(3<<4), %r12
13260+ and $(3<<4), %r15
13261 jz _initial_num_blocks_is_0_encrypt
13262- cmp $(2<<4), %r12
13263+ cmp $(2<<4), %r15
13264 jb _initial_num_blocks_is_1_encrypt
13265 je _initial_num_blocks_is_2_encrypt
13266 _initial_num_blocks_is_3_encrypt:
13267@@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
13268 sub $16, %r11
13269 add %r13, %r11
13270 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
13271- lea SHIFT_MASK+16(%rip), %r12
13272- sub %r13, %r12
13273+ lea SHIFT_MASK+16(%rip), %r15
13274+ sub %r13, %r15
13275 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
13276 # (%r13 is the number of bytes in plaintext mod 16)
13277- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13278+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13279 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
13280 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
13281- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13282+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13283 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
13284 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
13285 movdqa SHUF_MASK(%rip), %xmm10
13286@@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
13287 sub $1, %r13
13288 jne _less_than_8_bytes_left_encrypt
13289 _multiple_of_16_bytes_encrypt:
13290- mov arg8, %r12 # %r12 = addLen (number of bytes)
13291- shl $3, %r12
13292- movd %r12d, %xmm15 # len(A) in %xmm15
13293+ mov arg8, %r15 # %r15 = addLen (number of bytes)
13294+ shl $3, %r15
13295+ movd %r15d, %xmm15 # len(A) in %xmm15
13296 shl $3, %arg4 # len(C) in bits (*128)
13297 MOVQ_R64_XMM %arg4, %xmm1
13298 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13299@@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
13300 mov %r14, %rsp
13301 pop %r14
13302 pop %r13
13303- pop %r12
13304+ pop %r15
13305+ pax_force_retaddr
13306 ret
13307 ENDPROC(aesni_gcm_enc)
13308
13309@@ -1722,6 +1725,7 @@ _key_expansion_256a:
13310 pxor %xmm1, %xmm0
13311 movaps %xmm0, (TKEYP)
13312 add $0x10, TKEYP
13313+ pax_force_retaddr
13314 ret
13315 ENDPROC(_key_expansion_128)
13316 ENDPROC(_key_expansion_256a)
13317@@ -1748,6 +1752,7 @@ _key_expansion_192a:
13318 shufps $0b01001110, %xmm2, %xmm1
13319 movaps %xmm1, 0x10(TKEYP)
13320 add $0x20, TKEYP
13321+ pax_force_retaddr
13322 ret
13323 ENDPROC(_key_expansion_192a)
13324
13325@@ -1768,6 +1773,7 @@ _key_expansion_192b:
13326
13327 movaps %xmm0, (TKEYP)
13328 add $0x10, TKEYP
13329+ pax_force_retaddr
13330 ret
13331 ENDPROC(_key_expansion_192b)
13332
13333@@ -1781,6 +1787,7 @@ _key_expansion_256b:
13334 pxor %xmm1, %xmm2
13335 movaps %xmm2, (TKEYP)
13336 add $0x10, TKEYP
13337+ pax_force_retaddr
13338 ret
13339 ENDPROC(_key_expansion_256b)
13340
13341@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
13342 #ifndef __x86_64__
13343 popl KEYP
13344 #endif
13345+ pax_force_retaddr
13346 ret
13347 ENDPROC(aesni_set_key)
13348
13349@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
13350 popl KLEN
13351 popl KEYP
13352 #endif
13353+ pax_force_retaddr
13354 ret
13355 ENDPROC(aesni_enc)
13356
13357@@ -1974,6 +1983,7 @@ _aesni_enc1:
13358 AESENC KEY STATE
13359 movaps 0x70(TKEYP), KEY
13360 AESENCLAST KEY STATE
13361+ pax_force_retaddr
13362 ret
13363 ENDPROC(_aesni_enc1)
13364
13365@@ -2083,6 +2093,7 @@ _aesni_enc4:
13366 AESENCLAST KEY STATE2
13367 AESENCLAST KEY STATE3
13368 AESENCLAST KEY STATE4
13369+ pax_force_retaddr
13370 ret
13371 ENDPROC(_aesni_enc4)
13372
13373@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13374 popl KLEN
13375 popl KEYP
13376 #endif
13377+ pax_force_retaddr
13378 ret
13379 ENDPROC(aesni_dec)
13380
13381@@ -2164,6 +2176,7 @@ _aesni_dec1:
13382 AESDEC KEY STATE
13383 movaps 0x70(TKEYP), KEY
13384 AESDECLAST KEY STATE
13385+ pax_force_retaddr
13386 ret
13387 ENDPROC(_aesni_dec1)
13388
13389@@ -2273,6 +2286,7 @@ _aesni_dec4:
13390 AESDECLAST KEY STATE2
13391 AESDECLAST KEY STATE3
13392 AESDECLAST KEY STATE4
13393+ pax_force_retaddr
13394 ret
13395 ENDPROC(_aesni_dec4)
13396
13397@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13398 popl KEYP
13399 popl LEN
13400 #endif
13401+ pax_force_retaddr
13402 ret
13403 ENDPROC(aesni_ecb_enc)
13404
13405@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13406 popl KEYP
13407 popl LEN
13408 #endif
13409+ pax_force_retaddr
13410 ret
13411 ENDPROC(aesni_ecb_dec)
13412
13413@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13414 popl LEN
13415 popl IVP
13416 #endif
13417+ pax_force_retaddr
13418 ret
13419 ENDPROC(aesni_cbc_enc)
13420
13421@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13422 popl LEN
13423 popl IVP
13424 #endif
13425+ pax_force_retaddr
13426 ret
13427 ENDPROC(aesni_cbc_dec)
13428
13429@@ -2550,6 +2568,7 @@ _aesni_inc_init:
13430 mov $1, TCTR_LOW
13431 MOVQ_R64_XMM TCTR_LOW INC
13432 MOVQ_R64_XMM CTR TCTR_LOW
13433+ pax_force_retaddr
13434 ret
13435 ENDPROC(_aesni_inc_init)
13436
13437@@ -2579,6 +2598,7 @@ _aesni_inc:
13438 .Linc_low:
13439 movaps CTR, IV
13440 PSHUFB_XMM BSWAP_MASK IV
13441+ pax_force_retaddr
13442 ret
13443 ENDPROC(_aesni_inc)
13444
13445@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13446 .Lctr_enc_ret:
13447 movups IV, (IVP)
13448 .Lctr_enc_just_ret:
13449+ pax_force_retaddr
13450 ret
13451 ENDPROC(aesni_ctr_enc)
13452
13453@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13454 pxor INC, STATE4
13455 movdqu STATE4, 0x70(OUTP)
13456
13457+ pax_force_retaddr
13458 ret
13459 ENDPROC(aesni_xts_crypt8)
13460
13461diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13462index 246c670..466e2d6 100644
13463--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13464+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13465@@ -21,6 +21,7 @@
13466 */
13467
13468 #include <linux/linkage.h>
13469+#include <asm/alternative-asm.h>
13470
13471 .file "blowfish-x86_64-asm.S"
13472 .text
13473@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13474 jnz .L__enc_xor;
13475
13476 write_block();
13477+ pax_force_retaddr
13478 ret;
13479 .L__enc_xor:
13480 xor_block();
13481+ pax_force_retaddr
13482 ret;
13483 ENDPROC(__blowfish_enc_blk)
13484
13485@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13486
13487 movq %r11, %rbp;
13488
13489+ pax_force_retaddr
13490 ret;
13491 ENDPROC(blowfish_dec_blk)
13492
13493@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13494
13495 popq %rbx;
13496 popq %rbp;
13497+ pax_force_retaddr
13498 ret;
13499
13500 .L__enc_xor4:
13501@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13502
13503 popq %rbx;
13504 popq %rbp;
13505+ pax_force_retaddr
13506 ret;
13507 ENDPROC(__blowfish_enc_blk_4way)
13508
13509@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13510 popq %rbx;
13511 popq %rbp;
13512
13513+ pax_force_retaddr
13514 ret;
13515 ENDPROC(blowfish_dec_blk_4way)
13516diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13517index ce71f92..1dce7ec 100644
13518--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13519+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13520@@ -16,6 +16,7 @@
13521 */
13522
13523 #include <linux/linkage.h>
13524+#include <asm/alternative-asm.h>
13525
13526 #define CAMELLIA_TABLE_BYTE_LEN 272
13527
13528@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13529 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13530 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13531 %rcx, (%r9));
13532+ pax_force_retaddr
13533 ret;
13534 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13535
13536@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13537 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13538 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13539 %rax, (%r9));
13540+ pax_force_retaddr
13541 ret;
13542 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13543
13544@@ -780,6 +783,7 @@ __camellia_enc_blk16:
13545 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13546 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13547
13548+ pax_force_retaddr
13549 ret;
13550
13551 .align 8
13552@@ -865,6 +869,7 @@ __camellia_dec_blk16:
13553 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13554 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13555
13556+ pax_force_retaddr
13557 ret;
13558
13559 .align 8
13560@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13561 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13562 %xmm8, %rsi);
13563
13564+ pax_force_retaddr
13565 ret;
13566 ENDPROC(camellia_ecb_enc_16way)
13567
13568@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13569 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13570 %xmm8, %rsi);
13571
13572+ pax_force_retaddr
13573 ret;
13574 ENDPROC(camellia_ecb_dec_16way)
13575
13576@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13577 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13578 %xmm8, %rsi);
13579
13580+ pax_force_retaddr
13581 ret;
13582 ENDPROC(camellia_cbc_dec_16way)
13583
13584@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13585 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13586 %xmm8, %rsi);
13587
13588+ pax_force_retaddr
13589 ret;
13590 ENDPROC(camellia_ctr_16way)
13591
13592@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13593 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13594 %xmm8, %rsi);
13595
13596+ pax_force_retaddr
13597 ret;
13598 ENDPROC(camellia_xts_crypt_16way)
13599
13600diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13601index 0e0b886..5a3123c 100644
13602--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13603+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13604@@ -11,6 +11,7 @@
13605 */
13606
13607 #include <linux/linkage.h>
13608+#include <asm/alternative-asm.h>
13609
13610 #define CAMELLIA_TABLE_BYTE_LEN 272
13611
13612@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13613 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13614 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13615 %rcx, (%r9));
13616+ pax_force_retaddr
13617 ret;
13618 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13619
13620@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13621 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13622 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13623 %rax, (%r9));
13624+ pax_force_retaddr
13625 ret;
13626 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13627
13628@@ -820,6 +823,7 @@ __camellia_enc_blk32:
13629 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13630 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13631
13632+ pax_force_retaddr
13633 ret;
13634
13635 .align 8
13636@@ -905,6 +909,7 @@ __camellia_dec_blk32:
13637 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13638 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13639
13640+ pax_force_retaddr
13641 ret;
13642
13643 .align 8
13644@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13645
13646 vzeroupper;
13647
13648+ pax_force_retaddr
13649 ret;
13650 ENDPROC(camellia_ecb_enc_32way)
13651
13652@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13653
13654 vzeroupper;
13655
13656+ pax_force_retaddr
13657 ret;
13658 ENDPROC(camellia_ecb_dec_32way)
13659
13660@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13661
13662 vzeroupper;
13663
13664+ pax_force_retaddr
13665 ret;
13666 ENDPROC(camellia_cbc_dec_32way)
13667
13668@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13669
13670 vzeroupper;
13671
13672+ pax_force_retaddr
13673 ret;
13674 ENDPROC(camellia_ctr_32way)
13675
13676@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13677
13678 vzeroupper;
13679
13680+ pax_force_retaddr
13681 ret;
13682 ENDPROC(camellia_xts_crypt_32way)
13683
13684diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13685index 310319c..db3d7b5 100644
13686--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13687+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13688@@ -21,6 +21,7 @@
13689 */
13690
13691 #include <linux/linkage.h>
13692+#include <asm/alternative-asm.h>
13693
13694 .file "camellia-x86_64-asm_64.S"
13695 .text
13696@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13697 enc_outunpack(mov, RT1);
13698
13699 movq RRBP, %rbp;
13700+ pax_force_retaddr
13701 ret;
13702
13703 .L__enc_xor:
13704 enc_outunpack(xor, RT1);
13705
13706 movq RRBP, %rbp;
13707+ pax_force_retaddr
13708 ret;
13709 ENDPROC(__camellia_enc_blk)
13710
13711@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13712 dec_outunpack();
13713
13714 movq RRBP, %rbp;
13715+ pax_force_retaddr
13716 ret;
13717 ENDPROC(camellia_dec_blk)
13718
13719@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13720
13721 movq RRBP, %rbp;
13722 popq %rbx;
13723+ pax_force_retaddr
13724 ret;
13725
13726 .L__enc2_xor:
13727@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13728
13729 movq RRBP, %rbp;
13730 popq %rbx;
13731+ pax_force_retaddr
13732 ret;
13733 ENDPROC(__camellia_enc_blk_2way)
13734
13735@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13736
13737 movq RRBP, %rbp;
13738 movq RXOR, %rbx;
13739+ pax_force_retaddr
13740 ret;
13741 ENDPROC(camellia_dec_blk_2way)
13742diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13743index c35fd5d..2d8c7db 100644
13744--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13745+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13746@@ -24,6 +24,7 @@
13747 */
13748
13749 #include <linux/linkage.h>
13750+#include <asm/alternative-asm.h>
13751
13752 .file "cast5-avx-x86_64-asm_64.S"
13753
13754@@ -281,6 +282,7 @@ __cast5_enc_blk16:
13755 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13756 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13757
13758+ pax_force_retaddr
13759 ret;
13760 ENDPROC(__cast5_enc_blk16)
13761
13762@@ -352,6 +354,7 @@ __cast5_dec_blk16:
13763 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13764 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13765
13766+ pax_force_retaddr
13767 ret;
13768
13769 .L__skip_dec:
13770@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13771 vmovdqu RR4, (6*4*4)(%r11);
13772 vmovdqu RL4, (7*4*4)(%r11);
13773
13774+ pax_force_retaddr
13775 ret;
13776 ENDPROC(cast5_ecb_enc_16way)
13777
13778@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13779 vmovdqu RR4, (6*4*4)(%r11);
13780 vmovdqu RL4, (7*4*4)(%r11);
13781
13782+ pax_force_retaddr
13783 ret;
13784 ENDPROC(cast5_ecb_dec_16way)
13785
13786@@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13787 * %rdx: src
13788 */
13789
13790- pushq %r12;
13791+ pushq %r14;
13792
13793 movq %rsi, %r11;
13794- movq %rdx, %r12;
13795+ movq %rdx, %r14;
13796
13797 vmovdqu (0*16)(%rdx), RL1;
13798 vmovdqu (1*16)(%rdx), RR1;
13799@@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13800 call __cast5_dec_blk16;
13801
13802 /* xor with src */
13803- vmovq (%r12), RX;
13804+ vmovq (%r14), RX;
13805 vpshufd $0x4f, RX, RX;
13806 vpxor RX, RR1, RR1;
13807- vpxor 0*16+8(%r12), RL1, RL1;
13808- vpxor 1*16+8(%r12), RR2, RR2;
13809- vpxor 2*16+8(%r12), RL2, RL2;
13810- vpxor 3*16+8(%r12), RR3, RR3;
13811- vpxor 4*16+8(%r12), RL3, RL3;
13812- vpxor 5*16+8(%r12), RR4, RR4;
13813- vpxor 6*16+8(%r12), RL4, RL4;
13814+ vpxor 0*16+8(%r14), RL1, RL1;
13815+ vpxor 1*16+8(%r14), RR2, RR2;
13816+ vpxor 2*16+8(%r14), RL2, RL2;
13817+ vpxor 3*16+8(%r14), RR3, RR3;
13818+ vpxor 4*16+8(%r14), RL3, RL3;
13819+ vpxor 5*16+8(%r14), RR4, RR4;
13820+ vpxor 6*16+8(%r14), RL4, RL4;
13821
13822 vmovdqu RR1, (0*16)(%r11);
13823 vmovdqu RL1, (1*16)(%r11);
13824@@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13825 vmovdqu RR4, (6*16)(%r11);
13826 vmovdqu RL4, (7*16)(%r11);
13827
13828- popq %r12;
13829+ popq %r14;
13830
13831+ pax_force_retaddr
13832 ret;
13833 ENDPROC(cast5_cbc_dec_16way)
13834
13835@@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13836 * %rcx: iv (big endian, 64bit)
13837 */
13838
13839- pushq %r12;
13840+ pushq %r14;
13841
13842 movq %rsi, %r11;
13843- movq %rdx, %r12;
13844+ movq %rdx, %r14;
13845
13846 vpcmpeqd RTMP, RTMP, RTMP;
13847 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13848@@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13849 call __cast5_enc_blk16;
13850
13851 /* dst = src ^ iv */
13852- vpxor (0*16)(%r12), RR1, RR1;
13853- vpxor (1*16)(%r12), RL1, RL1;
13854- vpxor (2*16)(%r12), RR2, RR2;
13855- vpxor (3*16)(%r12), RL2, RL2;
13856- vpxor (4*16)(%r12), RR3, RR3;
13857- vpxor (5*16)(%r12), RL3, RL3;
13858- vpxor (6*16)(%r12), RR4, RR4;
13859- vpxor (7*16)(%r12), RL4, RL4;
13860+ vpxor (0*16)(%r14), RR1, RR1;
13861+ vpxor (1*16)(%r14), RL1, RL1;
13862+ vpxor (2*16)(%r14), RR2, RR2;
13863+ vpxor (3*16)(%r14), RL2, RL2;
13864+ vpxor (4*16)(%r14), RR3, RR3;
13865+ vpxor (5*16)(%r14), RL3, RL3;
13866+ vpxor (6*16)(%r14), RR4, RR4;
13867+ vpxor (7*16)(%r14), RL4, RL4;
13868 vmovdqu RR1, (0*16)(%r11);
13869 vmovdqu RL1, (1*16)(%r11);
13870 vmovdqu RR2, (2*16)(%r11);
13871@@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13872 vmovdqu RR4, (6*16)(%r11);
13873 vmovdqu RL4, (7*16)(%r11);
13874
13875- popq %r12;
13876+ popq %r14;
13877
13878+ pax_force_retaddr
13879 ret;
13880 ENDPROC(cast5_ctr_16way)
13881diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13882index e3531f8..e123f35 100644
13883--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13884+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13885@@ -24,6 +24,7 @@
13886 */
13887
13888 #include <linux/linkage.h>
13889+#include <asm/alternative-asm.h>
13890 #include "glue_helper-asm-avx.S"
13891
13892 .file "cast6-avx-x86_64-asm_64.S"
13893@@ -295,6 +296,7 @@ __cast6_enc_blk8:
13894 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13895 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13896
13897+ pax_force_retaddr
13898 ret;
13899 ENDPROC(__cast6_enc_blk8)
13900
13901@@ -340,6 +342,7 @@ __cast6_dec_blk8:
13902 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13903 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13904
13905+ pax_force_retaddr
13906 ret;
13907 ENDPROC(__cast6_dec_blk8)
13908
13909@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13910
13911 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13912
13913+ pax_force_retaddr
13914 ret;
13915 ENDPROC(cast6_ecb_enc_8way)
13916
13917@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13918
13919 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13920
13921+ pax_force_retaddr
13922 ret;
13923 ENDPROC(cast6_ecb_dec_8way)
13924
13925@@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13926 * %rdx: src
13927 */
13928
13929- pushq %r12;
13930+ pushq %r14;
13931
13932 movq %rsi, %r11;
13933- movq %rdx, %r12;
13934+ movq %rdx, %r14;
13935
13936 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13937
13938 call __cast6_dec_blk8;
13939
13940- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13941+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13942
13943- popq %r12;
13944+ popq %r14;
13945
13946+ pax_force_retaddr
13947 ret;
13948 ENDPROC(cast6_cbc_dec_8way)
13949
13950@@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13951 * %rcx: iv (little endian, 128bit)
13952 */
13953
13954- pushq %r12;
13955+ pushq %r14;
13956
13957 movq %rsi, %r11;
13958- movq %rdx, %r12;
13959+ movq %rdx, %r14;
13960
13961 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13962 RD2, RX, RKR, RKM);
13963
13964 call __cast6_enc_blk8;
13965
13966- store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13967+ store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13968
13969- popq %r12;
13970+ popq %r14;
13971
13972+ pax_force_retaddr
13973 ret;
13974 ENDPROC(cast6_ctr_8way)
13975
13976@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13977 /* dst <= regs xor IVs(in dst) */
13978 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13979
13980+ pax_force_retaddr
13981 ret;
13982 ENDPROC(cast6_xts_enc_8way)
13983
13984@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13985 /* dst <= regs xor IVs(in dst) */
13986 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13987
13988+ pax_force_retaddr
13989 ret;
13990 ENDPROC(cast6_xts_dec_8way)
13991diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13992index 26d49eb..c0a8c84 100644
13993--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13994+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13995@@ -45,6 +45,7 @@
13996
13997 #include <asm/inst.h>
13998 #include <linux/linkage.h>
13999+#include <asm/alternative-asm.h>
14000
14001 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
14002
14003@@ -309,6 +310,7 @@ do_return:
14004 popq %rsi
14005 popq %rdi
14006 popq %rbx
14007+ pax_force_retaddr
14008 ret
14009
14010 ################################################################
14011diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14012index 5d1e007..098cb4f 100644
14013--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
14014+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14015@@ -18,6 +18,7 @@
14016
14017 #include <linux/linkage.h>
14018 #include <asm/inst.h>
14019+#include <asm/alternative-asm.h>
14020
14021 .data
14022
14023@@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
14024 psrlq $1, T2
14025 pxor T2, T1
14026 pxor T1, DATA
14027+ pax_force_retaddr
14028 ret
14029 ENDPROC(__clmul_gf128mul_ble)
14030
14031@@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
14032 call __clmul_gf128mul_ble
14033 PSHUFB_XMM BSWAP DATA
14034 movups DATA, (%rdi)
14035+ pax_force_retaddr
14036 ret
14037 ENDPROC(clmul_ghash_mul)
14038
14039@@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
14040 PSHUFB_XMM BSWAP DATA
14041 movups DATA, (%rdi)
14042 .Lupdate_just_ret:
14043+ pax_force_retaddr
14044 ret
14045 ENDPROC(clmul_ghash_update)
14046diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14047index 9279e0b..c4b3d2c 100644
14048--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
14049+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14050@@ -1,4 +1,5 @@
14051 #include <linux/linkage.h>
14052+#include <asm/alternative-asm.h>
14053
14054 # enter salsa20_encrypt_bytes
14055 ENTRY(salsa20_encrypt_bytes)
14056@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
14057 add %r11,%rsp
14058 mov %rdi,%rax
14059 mov %rsi,%rdx
14060+ pax_force_retaddr
14061 ret
14062 # bytesatleast65:
14063 ._bytesatleast65:
14064@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
14065 add %r11,%rsp
14066 mov %rdi,%rax
14067 mov %rsi,%rdx
14068+ pax_force_retaddr
14069 ret
14070 ENDPROC(salsa20_keysetup)
14071
14072@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
14073 add %r11,%rsp
14074 mov %rdi,%rax
14075 mov %rsi,%rdx
14076+ pax_force_retaddr
14077 ret
14078 ENDPROC(salsa20_ivsetup)
14079diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14080index 2f202f4..d9164d6 100644
14081--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14082+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14083@@ -24,6 +24,7 @@
14084 */
14085
14086 #include <linux/linkage.h>
14087+#include <asm/alternative-asm.h>
14088 #include "glue_helper-asm-avx.S"
14089
14090 .file "serpent-avx-x86_64-asm_64.S"
14091@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
14092 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14093 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14094
14095+ pax_force_retaddr
14096 ret;
14097 ENDPROC(__serpent_enc_blk8_avx)
14098
14099@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
14100 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14101 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14102
14103+ pax_force_retaddr
14104 ret;
14105 ENDPROC(__serpent_dec_blk8_avx)
14106
14107@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
14108
14109 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14110
14111+ pax_force_retaddr
14112 ret;
14113 ENDPROC(serpent_ecb_enc_8way_avx)
14114
14115@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
14116
14117 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14118
14119+ pax_force_retaddr
14120 ret;
14121 ENDPROC(serpent_ecb_dec_8way_avx)
14122
14123@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
14124
14125 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14126
14127+ pax_force_retaddr
14128 ret;
14129 ENDPROC(serpent_cbc_dec_8way_avx)
14130
14131@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
14132
14133 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14134
14135+ pax_force_retaddr
14136 ret;
14137 ENDPROC(serpent_ctr_8way_avx)
14138
14139@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
14140 /* dst <= regs xor IVs(in dst) */
14141 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14142
14143+ pax_force_retaddr
14144 ret;
14145 ENDPROC(serpent_xts_enc_8way_avx)
14146
14147@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
14148 /* dst <= regs xor IVs(in dst) */
14149 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14150
14151+ pax_force_retaddr
14152 ret;
14153 ENDPROC(serpent_xts_dec_8way_avx)
14154diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
14155index b222085..abd483c 100644
14156--- a/arch/x86/crypto/serpent-avx2-asm_64.S
14157+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
14158@@ -15,6 +15,7 @@
14159 */
14160
14161 #include <linux/linkage.h>
14162+#include <asm/alternative-asm.h>
14163 #include "glue_helper-asm-avx2.S"
14164
14165 .file "serpent-avx2-asm_64.S"
14166@@ -610,6 +611,7 @@ __serpent_enc_blk16:
14167 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14168 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14169
14170+ pax_force_retaddr
14171 ret;
14172 ENDPROC(__serpent_enc_blk16)
14173
14174@@ -664,6 +666,7 @@ __serpent_dec_blk16:
14175 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14176 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14177
14178+ pax_force_retaddr
14179 ret;
14180 ENDPROC(__serpent_dec_blk16)
14181
14182@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
14183
14184 vzeroupper;
14185
14186+ pax_force_retaddr
14187 ret;
14188 ENDPROC(serpent_ecb_enc_16way)
14189
14190@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
14191
14192 vzeroupper;
14193
14194+ pax_force_retaddr
14195 ret;
14196 ENDPROC(serpent_ecb_dec_16way)
14197
14198@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
14199
14200 vzeroupper;
14201
14202+ pax_force_retaddr
14203 ret;
14204 ENDPROC(serpent_cbc_dec_16way)
14205
14206@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
14207
14208 vzeroupper;
14209
14210+ pax_force_retaddr
14211 ret;
14212 ENDPROC(serpent_ctr_16way)
14213
14214@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
14215
14216 vzeroupper;
14217
14218+ pax_force_retaddr
14219 ret;
14220 ENDPROC(serpent_xts_enc_16way)
14221
14222@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
14223
14224 vzeroupper;
14225
14226+ pax_force_retaddr
14227 ret;
14228 ENDPROC(serpent_xts_dec_16way)
14229diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14230index acc066c..1559cc4 100644
14231--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14232+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14233@@ -25,6 +25,7 @@
14234 */
14235
14236 #include <linux/linkage.h>
14237+#include <asm/alternative-asm.h>
14238
14239 .file "serpent-sse2-x86_64-asm_64.S"
14240 .text
14241@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
14242 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14243 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14244
14245+ pax_force_retaddr
14246 ret;
14247
14248 .L__enc_xor8:
14249 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14250 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14251
14252+ pax_force_retaddr
14253 ret;
14254 ENDPROC(__serpent_enc_blk_8way)
14255
14256@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
14257 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14258 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14259
14260+ pax_force_retaddr
14261 ret;
14262 ENDPROC(serpent_dec_blk_8way)
14263diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
14264index a410950..9dfe7ad 100644
14265--- a/arch/x86/crypto/sha1_ssse3_asm.S
14266+++ b/arch/x86/crypto/sha1_ssse3_asm.S
14267@@ -29,6 +29,7 @@
14268 */
14269
14270 #include <linux/linkage.h>
14271+#include <asm/alternative-asm.h>
14272
14273 #define CTX %rdi // arg1
14274 #define BUF %rsi // arg2
14275@@ -75,9 +76,9 @@
14276
14277 push %rbx
14278 push %rbp
14279- push %r12
14280+ push %r14
14281
14282- mov %rsp, %r12
14283+ mov %rsp, %r14
14284 sub $64, %rsp # allocate workspace
14285 and $~15, %rsp # align stack
14286
14287@@ -99,11 +100,12 @@
14288 xor %rax, %rax
14289 rep stosq
14290
14291- mov %r12, %rsp # deallocate workspace
14292+ mov %r14, %rsp # deallocate workspace
14293
14294- pop %r12
14295+ pop %r14
14296 pop %rbp
14297 pop %rbx
14298+ pax_force_retaddr
14299 ret
14300
14301 ENDPROC(\name)
14302diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
14303index 642f156..51a513c 100644
14304--- a/arch/x86/crypto/sha256-avx-asm.S
14305+++ b/arch/x86/crypto/sha256-avx-asm.S
14306@@ -49,6 +49,7 @@
14307
14308 #ifdef CONFIG_AS_AVX
14309 #include <linux/linkage.h>
14310+#include <asm/alternative-asm.h>
14311
14312 ## assume buffers not aligned
14313 #define VMOVDQ vmovdqu
14314@@ -460,6 +461,7 @@ done_hash:
14315 popq %r13
14316 popq %rbp
14317 popq %rbx
14318+ pax_force_retaddr
14319 ret
14320 ENDPROC(sha256_transform_avx)
14321
14322diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
14323index 9e86944..3795e6a 100644
14324--- a/arch/x86/crypto/sha256-avx2-asm.S
14325+++ b/arch/x86/crypto/sha256-avx2-asm.S
14326@@ -50,6 +50,7 @@
14327
14328 #ifdef CONFIG_AS_AVX2
14329 #include <linux/linkage.h>
14330+#include <asm/alternative-asm.h>
14331
14332 ## assume buffers not aligned
14333 #define VMOVDQ vmovdqu
14334@@ -720,6 +721,7 @@ done_hash:
14335 popq %r12
14336 popq %rbp
14337 popq %rbx
14338+ pax_force_retaddr
14339 ret
14340 ENDPROC(sha256_transform_rorx)
14341
14342diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
14343index f833b74..8c62a9e 100644
14344--- a/arch/x86/crypto/sha256-ssse3-asm.S
14345+++ b/arch/x86/crypto/sha256-ssse3-asm.S
14346@@ -47,6 +47,7 @@
14347 ########################################################################
14348
14349 #include <linux/linkage.h>
14350+#include <asm/alternative-asm.h>
14351
14352 ## assume buffers not aligned
14353 #define MOVDQ movdqu
14354@@ -471,6 +472,7 @@ done_hash:
14355 popq %rbp
14356 popq %rbx
14357
14358+ pax_force_retaddr
14359 ret
14360 ENDPROC(sha256_transform_ssse3)
14361
14362diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
14363index 974dde9..a823ff9 100644
14364--- a/arch/x86/crypto/sha512-avx-asm.S
14365+++ b/arch/x86/crypto/sha512-avx-asm.S
14366@@ -49,6 +49,7 @@
14367
14368 #ifdef CONFIG_AS_AVX
14369 #include <linux/linkage.h>
14370+#include <asm/alternative-asm.h>
14371
14372 .text
14373
14374@@ -364,6 +365,7 @@ updateblock:
14375 mov frame_RSPSAVE(%rsp), %rsp
14376
14377 nowork:
14378+ pax_force_retaddr
14379 ret
14380 ENDPROC(sha512_transform_avx)
14381
14382diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14383index 568b961..ed20c37 100644
14384--- a/arch/x86/crypto/sha512-avx2-asm.S
14385+++ b/arch/x86/crypto/sha512-avx2-asm.S
14386@@ -51,6 +51,7 @@
14387
14388 #ifdef CONFIG_AS_AVX2
14389 #include <linux/linkage.h>
14390+#include <asm/alternative-asm.h>
14391
14392 .text
14393
14394@@ -678,6 +679,7 @@ done_hash:
14395
14396 # Restore Stack Pointer
14397 mov frame_RSPSAVE(%rsp), %rsp
14398+ pax_force_retaddr
14399 ret
14400 ENDPROC(sha512_transform_rorx)
14401
14402diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14403index fb56855..6edd768 100644
14404--- a/arch/x86/crypto/sha512-ssse3-asm.S
14405+++ b/arch/x86/crypto/sha512-ssse3-asm.S
14406@@ -48,6 +48,7 @@
14407 ########################################################################
14408
14409 #include <linux/linkage.h>
14410+#include <asm/alternative-asm.h>
14411
14412 .text
14413
14414@@ -363,6 +364,7 @@ updateblock:
14415 mov frame_RSPSAVE(%rsp), %rsp
14416
14417 nowork:
14418+ pax_force_retaddr
14419 ret
14420 ENDPROC(sha512_transform_ssse3)
14421
14422diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14423index 0505813..b067311 100644
14424--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14425+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14426@@ -24,6 +24,7 @@
14427 */
14428
14429 #include <linux/linkage.h>
14430+#include <asm/alternative-asm.h>
14431 #include "glue_helper-asm-avx.S"
14432
14433 .file "twofish-avx-x86_64-asm_64.S"
14434@@ -284,6 +285,7 @@ __twofish_enc_blk8:
14435 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14436 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14437
14438+ pax_force_retaddr
14439 ret;
14440 ENDPROC(__twofish_enc_blk8)
14441
14442@@ -324,6 +326,7 @@ __twofish_dec_blk8:
14443 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14444 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14445
14446+ pax_force_retaddr
14447 ret;
14448 ENDPROC(__twofish_dec_blk8)
14449
14450@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14451
14452 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14453
14454+ pax_force_retaddr
14455 ret;
14456 ENDPROC(twofish_ecb_enc_8way)
14457
14458@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14459
14460 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14461
14462+ pax_force_retaddr
14463 ret;
14464 ENDPROC(twofish_ecb_dec_8way)
14465
14466@@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14467 * %rdx: src
14468 */
14469
14470- pushq %r12;
14471+ pushq %r14;
14472
14473 movq %rsi, %r11;
14474- movq %rdx, %r12;
14475+ movq %rdx, %r14;
14476
14477 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14478
14479 call __twofish_dec_blk8;
14480
14481- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14482+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14483
14484- popq %r12;
14485+ popq %r14;
14486
14487+ pax_force_retaddr
14488 ret;
14489 ENDPROC(twofish_cbc_dec_8way)
14490
14491@@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14492 * %rcx: iv (little endian, 128bit)
14493 */
14494
14495- pushq %r12;
14496+ pushq %r14;
14497
14498 movq %rsi, %r11;
14499- movq %rdx, %r12;
14500+ movq %rdx, %r14;
14501
14502 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14503 RD2, RX0, RX1, RY0);
14504
14505 call __twofish_enc_blk8;
14506
14507- store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14508+ store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14509
14510- popq %r12;
14511+ popq %r14;
14512
14513+ pax_force_retaddr
14514 ret;
14515 ENDPROC(twofish_ctr_8way)
14516
14517@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14518 /* dst <= regs xor IVs(in dst) */
14519 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14520
14521+ pax_force_retaddr
14522 ret;
14523 ENDPROC(twofish_xts_enc_8way)
14524
14525@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14526 /* dst <= regs xor IVs(in dst) */
14527 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14528
14529+ pax_force_retaddr
14530 ret;
14531 ENDPROC(twofish_xts_dec_8way)
14532diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14533index 1c3b7ce..02f578d 100644
14534--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14535+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14536@@ -21,6 +21,7 @@
14537 */
14538
14539 #include <linux/linkage.h>
14540+#include <asm/alternative-asm.h>
14541
14542 .file "twofish-x86_64-asm-3way.S"
14543 .text
14544@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14545 popq %r13;
14546 popq %r14;
14547 popq %r15;
14548+ pax_force_retaddr
14549 ret;
14550
14551 .L__enc_xor3:
14552@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14553 popq %r13;
14554 popq %r14;
14555 popq %r15;
14556+ pax_force_retaddr
14557 ret;
14558 ENDPROC(__twofish_enc_blk_3way)
14559
14560@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14561 popq %r13;
14562 popq %r14;
14563 popq %r15;
14564+ pax_force_retaddr
14565 ret;
14566 ENDPROC(twofish_dec_blk_3way)
14567diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14568index a039d21..524b8b2 100644
14569--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14570+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14571@@ -22,6 +22,7 @@
14572
14573 #include <linux/linkage.h>
14574 #include <asm/asm-offsets.h>
14575+#include <asm/alternative-asm.h>
14576
14577 #define a_offset 0
14578 #define b_offset 4
14579@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14580
14581 popq R1
14582 movq $1,%rax
14583+ pax_force_retaddr
14584 ret
14585 ENDPROC(twofish_enc_blk)
14586
14587@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14588
14589 popq R1
14590 movq $1,%rax
14591+ pax_force_retaddr
14592 ret
14593 ENDPROC(twofish_dec_blk)
14594diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14595index df91466..74b31cb 100644
14596--- a/arch/x86/ia32/ia32_aout.c
14597+++ b/arch/x86/ia32/ia32_aout.c
14598@@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14599 unsigned long dump_start, dump_size;
14600 struct user32 dump;
14601
14602+ memset(&dump, 0, sizeof(dump));
14603+
14604 fs = get_fs();
14605 set_fs(KERNEL_DS);
14606 has_dumped = 1;
14607diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14608index f9e181a..300544c 100644
14609--- a/arch/x86/ia32/ia32_signal.c
14610+++ b/arch/x86/ia32/ia32_signal.c
14611@@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14612 if (__get_user(set.sig[0], &frame->sc.oldmask)
14613 || (_COMPAT_NSIG_WORDS > 1
14614 && __copy_from_user((((char *) &set.sig) + 4),
14615- &frame->extramask,
14616+ frame->extramask,
14617 sizeof(frame->extramask))))
14618 goto badframe;
14619
14620@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14621 sp -= frame_size;
14622 /* Align the stack pointer according to the i386 ABI,
14623 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14624- sp = ((sp + 4) & -16ul) - 4;
14625+ sp = ((sp - 12) & -16ul) - 4;
14626 return (void __user *) sp;
14627 }
14628
14629@@ -383,10 +383,10 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14630 } else {
14631 /* Return stub is in 32bit vsyscall page */
14632 if (current->mm->context.vdso)
14633- restorer = current->mm->context.vdso +
14634- selected_vdso32->sym___kernel_sigreturn;
14635+ restorer = (void __force_user *)(current->mm->context.vdso +
14636+ selected_vdso32->sym___kernel_sigreturn);
14637 else
14638- restorer = &frame->retcode;
14639+ restorer = frame->retcode;
14640 }
14641
14642 put_user_try {
14643@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14644 * These are actually not used anymore, but left because some
14645 * gdb versions depend on them as a marker.
14646 */
14647- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14648+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14649 } put_user_catch(err);
14650
14651 if (err)
14652@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14653 0xb8,
14654 __NR_ia32_rt_sigreturn,
14655 0x80cd,
14656- 0,
14657+ 0
14658 };
14659
14660 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14661@@ -461,16 +461,19 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14662
14663 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14664 restorer = ksig->ka.sa.sa_restorer;
14665+ else if (current->mm->context.vdso)
14666+ /* Return stub is in 32bit vsyscall page */
14667+ restorer = (void __force_user *)(current->mm->context.vdso +
14668+ selected_vdso32->sym___kernel_rt_sigreturn);
14669 else
14670- restorer = current->mm->context.vdso +
14671- selected_vdso32->sym___kernel_rt_sigreturn;
14672+ restorer = frame->retcode;
14673 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14674
14675 /*
14676 * Not actually used anymore, but left because some gdb
14677 * versions need it.
14678 */
14679- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14680+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14681 } put_user_catch(err);
14682
14683 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14684diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14685index ffe7122..899bad3 100644
14686--- a/arch/x86/ia32/ia32entry.S
14687+++ b/arch/x86/ia32/ia32entry.S
14688@@ -15,8 +15,10 @@
14689 #include <asm/irqflags.h>
14690 #include <asm/asm.h>
14691 #include <asm/smap.h>
14692+#include <asm/pgtable.h>
14693 #include <linux/linkage.h>
14694 #include <linux/err.h>
14695+#include <asm/alternative-asm.h>
14696
14697 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14698 #include <linux/elf-em.h>
14699@@ -62,12 +64,12 @@
14700 */
14701 .macro LOAD_ARGS32 offset, _r9=0
14702 .if \_r9
14703- movl \offset+16(%rsp),%r9d
14704+ movl \offset+R9(%rsp),%r9d
14705 .endif
14706- movl \offset+40(%rsp),%ecx
14707- movl \offset+48(%rsp),%edx
14708- movl \offset+56(%rsp),%esi
14709- movl \offset+64(%rsp),%edi
14710+ movl \offset+RCX(%rsp),%ecx
14711+ movl \offset+RDX(%rsp),%edx
14712+ movl \offset+RSI(%rsp),%esi
14713+ movl \offset+RDI(%rsp),%edi
14714 movl %eax,%eax /* zero extension */
14715 .endm
14716
14717@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14718 ENDPROC(native_irq_enable_sysexit)
14719 #endif
14720
14721+ .macro pax_enter_kernel_user
14722+ pax_set_fptr_mask
14723+#ifdef CONFIG_PAX_MEMORY_UDEREF
14724+ call pax_enter_kernel_user
14725+#endif
14726+ .endm
14727+
14728+ .macro pax_exit_kernel_user
14729+#ifdef CONFIG_PAX_MEMORY_UDEREF
14730+ call pax_exit_kernel_user
14731+#endif
14732+#ifdef CONFIG_PAX_RANDKSTACK
14733+ pushq %rax
14734+ pushq %r11
14735+ call pax_randomize_kstack
14736+ popq %r11
14737+ popq %rax
14738+#endif
14739+ .endm
14740+
14741+ .macro pax_erase_kstack
14742+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14743+ call pax_erase_kstack
14744+#endif
14745+ .endm
14746+
14747 /*
14748 * 32bit SYSENTER instruction entry.
14749 *
14750@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14751 CFI_REGISTER rsp,rbp
14752 SWAPGS_UNSAFE_STACK
14753 movq PER_CPU_VAR(kernel_stack), %rsp
14754- addq $(KERNEL_STACK_OFFSET),%rsp
14755- /*
14756- * No need to follow this irqs on/off section: the syscall
14757- * disabled irqs, here we enable it straight after entry:
14758- */
14759- ENABLE_INTERRUPTS(CLBR_NONE)
14760 movl %ebp,%ebp /* zero extension */
14761 pushq_cfi $__USER32_DS
14762 /*CFI_REL_OFFSET ss,0*/
14763@@ -135,23 +157,46 @@ ENTRY(ia32_sysenter_target)
14764 CFI_REL_OFFSET rsp,0
14765 pushfq_cfi
14766 /*CFI_REL_OFFSET rflags,0*/
14767- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14768- CFI_REGISTER rip,r10
14769+ orl $X86_EFLAGS_IF,(%rsp)
14770+ GET_THREAD_INFO(%r11)
14771+ movl TI_sysenter_return(%r11), %r11d
14772+ CFI_REGISTER rip,r11
14773 pushq_cfi $__USER32_CS
14774 /*CFI_REL_OFFSET cs,0*/
14775 movl %eax, %eax
14776- pushq_cfi %r10
14777+ pushq_cfi %r11
14778 CFI_REL_OFFSET rip,0
14779 pushq_cfi %rax
14780 cld
14781 SAVE_ARGS 0,1,0
14782+ pax_enter_kernel_user
14783+
14784+#ifdef CONFIG_PAX_RANDKSTACK
14785+ pax_erase_kstack
14786+#endif
14787+
14788+ /*
14789+ * No need to follow this irqs on/off section: the syscall
14790+ * disabled irqs, here we enable it straight after entry:
14791+ */
14792+ ENABLE_INTERRUPTS(CLBR_NONE)
14793 /* no need to do an access_ok check here because rbp has been
14794 32bit zero extended */
14795+
14796+#ifdef CONFIG_PAX_MEMORY_UDEREF
14797+ addq pax_user_shadow_base,%rbp
14798+ ASM_PAX_OPEN_USERLAND
14799+#endif
14800+
14801 ASM_STAC
14802 1: movl (%rbp),%ebp
14803 _ASM_EXTABLE(1b,ia32_badarg)
14804 ASM_CLAC
14805
14806+#ifdef CONFIG_PAX_MEMORY_UDEREF
14807+ ASM_PAX_CLOSE_USERLAND
14808+#endif
14809+
14810 /*
14811 * Sysenter doesn't filter flags, so we need to clear NT
14812 * ourselves. To save a few cycles, we can check whether
14813@@ -161,8 +206,9 @@ ENTRY(ia32_sysenter_target)
14814 jnz sysenter_fix_flags
14815 sysenter_flags_fixed:
14816
14817- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14818- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14819+ GET_THREAD_INFO(%r11)
14820+ orl $TS_COMPAT,TI_status(%r11)
14821+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14822 CFI_REMEMBER_STATE
14823 jnz sysenter_tracesys
14824 cmpq $(IA32_NR_syscalls-1),%rax
14825@@ -172,15 +218,18 @@ sysenter_do_call:
14826 sysenter_dispatch:
14827 call *ia32_sys_call_table(,%rax,8)
14828 movq %rax,RAX-ARGOFFSET(%rsp)
14829+ GET_THREAD_INFO(%r11)
14830 DISABLE_INTERRUPTS(CLBR_NONE)
14831 TRACE_IRQS_OFF
14832- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14833+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14834 jnz sysexit_audit
14835 sysexit_from_sys_call:
14836- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14837+ pax_exit_kernel_user
14838+ pax_erase_kstack
14839+ andl $~TS_COMPAT,TI_status(%r11)
14840 /* clear IF, that popfq doesn't enable interrupts early */
14841- andl $~0x200,EFLAGS-R11(%rsp)
14842- movl RIP-R11(%rsp),%edx /* User %eip */
14843+ andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14844+ movl RIP(%rsp),%edx /* User %eip */
14845 CFI_REGISTER rip,rdx
14846 RESTORE_ARGS 0,24,0,0,0,0
14847 xorq %r8,%r8
14848@@ -205,6 +254,9 @@ sysexit_from_sys_call:
14849 movl %ebx,%esi /* 2nd arg: 1st syscall arg */
14850 movl %eax,%edi /* 1st arg: syscall number */
14851 call __audit_syscall_entry
14852+
14853+ pax_erase_kstack
14854+
14855 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14856 cmpq $(IA32_NR_syscalls-1),%rax
14857 ja ia32_badsys
14858@@ -216,7 +268,7 @@ sysexit_from_sys_call:
14859 .endm
14860
14861 .macro auditsys_exit exit
14862- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14863+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14864 jnz ia32_ret_from_sys_call
14865 TRACE_IRQS_ON
14866 ENABLE_INTERRUPTS(CLBR_NONE)
14867@@ -227,11 +279,12 @@ sysexit_from_sys_call:
14868 1: setbe %al /* 1 if error, 0 if not */
14869 movzbl %al,%edi /* zero-extend that into %edi */
14870 call __audit_syscall_exit
14871+ GET_THREAD_INFO(%r11)
14872 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14873 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14874 DISABLE_INTERRUPTS(CLBR_NONE)
14875 TRACE_IRQS_OFF
14876- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14877+ testl %edi,TI_flags(%r11)
14878 jz \exit
14879 CLEAR_RREGS -ARGOFFSET
14880 jmp int_with_check
14881@@ -253,7 +306,7 @@ sysenter_fix_flags:
14882
14883 sysenter_tracesys:
14884 #ifdef CONFIG_AUDITSYSCALL
14885- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14886+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14887 jz sysenter_auditsys
14888 #endif
14889 SAVE_REST
14890@@ -265,6 +318,9 @@ sysenter_tracesys:
14891 RESTORE_REST
14892 cmpq $(IA32_NR_syscalls-1),%rax
14893 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14894+
14895+ pax_erase_kstack
14896+
14897 jmp sysenter_do_call
14898 CFI_ENDPROC
14899 ENDPROC(ia32_sysenter_target)
14900@@ -292,19 +348,25 @@ ENDPROC(ia32_sysenter_target)
14901 ENTRY(ia32_cstar_target)
14902 CFI_STARTPROC32 simple
14903 CFI_SIGNAL_FRAME
14904- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14905+ CFI_DEF_CFA rsp,0
14906 CFI_REGISTER rip,rcx
14907 /*CFI_REGISTER rflags,r11*/
14908 SWAPGS_UNSAFE_STACK
14909 movl %esp,%r8d
14910 CFI_REGISTER rsp,r8
14911 movq PER_CPU_VAR(kernel_stack),%rsp
14912+ SAVE_ARGS 8*6,0,0
14913+ pax_enter_kernel_user
14914+
14915+#ifdef CONFIG_PAX_RANDKSTACK
14916+ pax_erase_kstack
14917+#endif
14918+
14919 /*
14920 * No need to follow this irqs on/off section: the syscall
14921 * disabled irqs and here we enable it straight after entry:
14922 */
14923 ENABLE_INTERRUPTS(CLBR_NONE)
14924- SAVE_ARGS 8,0,0
14925 movl %eax,%eax /* zero extension */
14926 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14927 movq %rcx,RIP-ARGOFFSET(%rsp)
14928@@ -320,12 +382,25 @@ ENTRY(ia32_cstar_target)
14929 /* no need to do an access_ok check here because r8 has been
14930 32bit zero extended */
14931 /* hardware stack frame is complete now */
14932+
14933+#ifdef CONFIG_PAX_MEMORY_UDEREF
14934+ ASM_PAX_OPEN_USERLAND
14935+ movq pax_user_shadow_base,%r8
14936+ addq RSP-ARGOFFSET(%rsp),%r8
14937+#endif
14938+
14939 ASM_STAC
14940 1: movl (%r8),%r9d
14941 _ASM_EXTABLE(1b,ia32_badarg)
14942 ASM_CLAC
14943- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14944- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14945+
14946+#ifdef CONFIG_PAX_MEMORY_UDEREF
14947+ ASM_PAX_CLOSE_USERLAND
14948+#endif
14949+
14950+ GET_THREAD_INFO(%r11)
14951+ orl $TS_COMPAT,TI_status(%r11)
14952+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14953 CFI_REMEMBER_STATE
14954 jnz cstar_tracesys
14955 cmpq $IA32_NR_syscalls-1,%rax
14956@@ -335,13 +410,16 @@ cstar_do_call:
14957 cstar_dispatch:
14958 call *ia32_sys_call_table(,%rax,8)
14959 movq %rax,RAX-ARGOFFSET(%rsp)
14960+ GET_THREAD_INFO(%r11)
14961 DISABLE_INTERRUPTS(CLBR_NONE)
14962 TRACE_IRQS_OFF
14963- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14964+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14965 jnz sysretl_audit
14966 sysretl_from_sys_call:
14967- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14968- RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14969+ pax_exit_kernel_user
14970+ pax_erase_kstack
14971+ andl $~TS_COMPAT,TI_status(%r11)
14972+ RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14973 movl RIP-ARGOFFSET(%rsp),%ecx
14974 CFI_REGISTER rip,rcx
14975 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14976@@ -368,7 +446,7 @@ sysretl_audit:
14977
14978 cstar_tracesys:
14979 #ifdef CONFIG_AUDITSYSCALL
14980- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14981+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14982 jz cstar_auditsys
14983 #endif
14984 xchgl %r9d,%ebp
14985@@ -382,11 +460,19 @@ cstar_tracesys:
14986 xchgl %ebp,%r9d
14987 cmpq $(IA32_NR_syscalls-1),%rax
14988 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14989+
14990+ pax_erase_kstack
14991+
14992 jmp cstar_do_call
14993 END(ia32_cstar_target)
14994
14995 ia32_badarg:
14996 ASM_CLAC
14997+
14998+#ifdef CONFIG_PAX_MEMORY_UDEREF
14999+ ASM_PAX_CLOSE_USERLAND
15000+#endif
15001+
15002 movq $-EFAULT,%rax
15003 jmp ia32_sysret
15004 CFI_ENDPROC
15005@@ -423,19 +509,26 @@ ENTRY(ia32_syscall)
15006 CFI_REL_OFFSET rip,RIP-RIP
15007 PARAVIRT_ADJUST_EXCEPTION_FRAME
15008 SWAPGS
15009- /*
15010- * No need to follow this irqs on/off section: the syscall
15011- * disabled irqs and here we enable it straight after entry:
15012- */
15013- ENABLE_INTERRUPTS(CLBR_NONE)
15014 movl %eax,%eax
15015 pushq_cfi %rax
15016 cld
15017 /* note the registers are not zero extended to the sf.
15018 this could be a problem. */
15019 SAVE_ARGS 0,1,0
15020- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15021- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15022+ pax_enter_kernel_user
15023+
15024+#ifdef CONFIG_PAX_RANDKSTACK
15025+ pax_erase_kstack
15026+#endif
15027+
15028+ /*
15029+ * No need to follow this irqs on/off section: the syscall
15030+ * disabled irqs and here we enable it straight after entry:
15031+ */
15032+ ENABLE_INTERRUPTS(CLBR_NONE)
15033+ GET_THREAD_INFO(%r11)
15034+ orl $TS_COMPAT,TI_status(%r11)
15035+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15036 jnz ia32_tracesys
15037 cmpq $(IA32_NR_syscalls-1),%rax
15038 ja ia32_badsys
15039@@ -458,6 +551,9 @@ ia32_tracesys:
15040 RESTORE_REST
15041 cmpq $(IA32_NR_syscalls-1),%rax
15042 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
15043+
15044+ pax_erase_kstack
15045+
15046 jmp ia32_do_call
15047 END(ia32_syscall)
15048
15049diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
15050index 8e0ceec..af13504 100644
15051--- a/arch/x86/ia32/sys_ia32.c
15052+++ b/arch/x86/ia32/sys_ia32.c
15053@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
15054 */
15055 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
15056 {
15057- typeof(ubuf->st_uid) uid = 0;
15058- typeof(ubuf->st_gid) gid = 0;
15059+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
15060+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
15061 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
15062 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
15063 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
15064diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
15065index 372231c..51b537d 100644
15066--- a/arch/x86/include/asm/alternative-asm.h
15067+++ b/arch/x86/include/asm/alternative-asm.h
15068@@ -18,6 +18,45 @@
15069 .endm
15070 #endif
15071
15072+#ifdef KERNEXEC_PLUGIN
15073+ .macro pax_force_retaddr_bts rip=0
15074+ btsq $63,\rip(%rsp)
15075+ .endm
15076+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15077+ .macro pax_force_retaddr rip=0, reload=0
15078+ btsq $63,\rip(%rsp)
15079+ .endm
15080+ .macro pax_force_fptr ptr
15081+ btsq $63,\ptr
15082+ .endm
15083+ .macro pax_set_fptr_mask
15084+ .endm
15085+#endif
15086+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15087+ .macro pax_force_retaddr rip=0, reload=0
15088+ .if \reload
15089+ pax_set_fptr_mask
15090+ .endif
15091+ orq %r12,\rip(%rsp)
15092+ .endm
15093+ .macro pax_force_fptr ptr
15094+ orq %r12,\ptr
15095+ .endm
15096+ .macro pax_set_fptr_mask
15097+ movabs $0x8000000000000000,%r12
15098+ .endm
15099+#endif
15100+#else
15101+ .macro pax_force_retaddr rip=0, reload=0
15102+ .endm
15103+ .macro pax_force_fptr ptr
15104+ .endm
15105+ .macro pax_force_retaddr_bts rip=0
15106+ .endm
15107+ .macro pax_set_fptr_mask
15108+ .endm
15109+#endif
15110+
15111 .macro altinstruction_entry orig alt feature orig_len alt_len
15112 .long \orig - .
15113 .long \alt - .
15114diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
15115index 473bdbe..b1e3377 100644
15116--- a/arch/x86/include/asm/alternative.h
15117+++ b/arch/x86/include/asm/alternative.h
15118@@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15119 ".pushsection .discard,\"aw\",@progbits\n" \
15120 DISCARD_ENTRY(1) \
15121 ".popsection\n" \
15122- ".pushsection .altinstr_replacement, \"ax\"\n" \
15123+ ".pushsection .altinstr_replacement, \"a\"\n" \
15124 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
15125 ".popsection"
15126
15127@@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15128 DISCARD_ENTRY(1) \
15129 DISCARD_ENTRY(2) \
15130 ".popsection\n" \
15131- ".pushsection .altinstr_replacement, \"ax\"\n" \
15132+ ".pushsection .altinstr_replacement, \"a\"\n" \
15133 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
15134 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
15135 ".popsection"
15136diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
15137index 465b309..ab7e51f 100644
15138--- a/arch/x86/include/asm/apic.h
15139+++ b/arch/x86/include/asm/apic.h
15140@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
15141
15142 #ifdef CONFIG_X86_LOCAL_APIC
15143
15144-extern unsigned int apic_verbosity;
15145+extern int apic_verbosity;
15146 extern int local_apic_timer_c2_ok;
15147
15148 extern int disable_apic;
15149diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
15150index 20370c6..a2eb9b0 100644
15151--- a/arch/x86/include/asm/apm.h
15152+++ b/arch/x86/include/asm/apm.h
15153@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
15154 __asm__ __volatile__(APM_DO_ZERO_SEGS
15155 "pushl %%edi\n\t"
15156 "pushl %%ebp\n\t"
15157- "lcall *%%cs:apm_bios_entry\n\t"
15158+ "lcall *%%ss:apm_bios_entry\n\t"
15159 "setc %%al\n\t"
15160 "popl %%ebp\n\t"
15161 "popl %%edi\n\t"
15162@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
15163 __asm__ __volatile__(APM_DO_ZERO_SEGS
15164 "pushl %%edi\n\t"
15165 "pushl %%ebp\n\t"
15166- "lcall *%%cs:apm_bios_entry\n\t"
15167+ "lcall *%%ss:apm_bios_entry\n\t"
15168 "setc %%bl\n\t"
15169 "popl %%ebp\n\t"
15170 "popl %%edi\n\t"
15171diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
15172index 5e5cd12..3d18208 100644
15173--- a/arch/x86/include/asm/atomic.h
15174+++ b/arch/x86/include/asm/atomic.h
15175@@ -28,6 +28,17 @@ static inline int atomic_read(const atomic_t *v)
15176 }
15177
15178 /**
15179+ * atomic_read_unchecked - read atomic variable
15180+ * @v: pointer of type atomic_unchecked_t
15181+ *
15182+ * Atomically reads the value of @v.
15183+ */
15184+static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
15185+{
15186+ return ACCESS_ONCE((v)->counter);
15187+}
15188+
15189+/**
15190 * atomic_set - set atomic variable
15191 * @v: pointer of type atomic_t
15192 * @i: required value
15193@@ -40,6 +51,18 @@ static inline void atomic_set(atomic_t *v, int i)
15194 }
15195
15196 /**
15197+ * atomic_set_unchecked - set atomic variable
15198+ * @v: pointer of type atomic_unchecked_t
15199+ * @i: required value
15200+ *
15201+ * Atomically sets the value of @v to @i.
15202+ */
15203+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
15204+{
15205+ v->counter = i;
15206+}
15207+
15208+/**
15209 * atomic_add - add integer to atomic variable
15210 * @i: integer value to add
15211 * @v: pointer of type atomic_t
15212@@ -48,7 +71,29 @@ static inline void atomic_set(atomic_t *v, int i)
15213 */
15214 static inline void atomic_add(int i, atomic_t *v)
15215 {
15216- asm volatile(LOCK_PREFIX "addl %1,%0"
15217+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
15218+
15219+#ifdef CONFIG_PAX_REFCOUNT
15220+ "jno 0f\n"
15221+ LOCK_PREFIX "subl %1,%0\n"
15222+ "int $4\n0:\n"
15223+ _ASM_EXTABLE(0b, 0b)
15224+#endif
15225+
15226+ : "+m" (v->counter)
15227+ : "ir" (i));
15228+}
15229+
15230+/**
15231+ * atomic_add_unchecked - add integer to atomic variable
15232+ * @i: integer value to add
15233+ * @v: pointer of type atomic_unchecked_t
15234+ *
15235+ * Atomically adds @i to @v.
15236+ */
15237+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
15238+{
15239+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
15240 : "+m" (v->counter)
15241 : "ir" (i));
15242 }
15243@@ -62,7 +107,29 @@ static inline void atomic_add(int i, atomic_t *v)
15244 */
15245 static inline void atomic_sub(int i, atomic_t *v)
15246 {
15247- asm volatile(LOCK_PREFIX "subl %1,%0"
15248+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
15249+
15250+#ifdef CONFIG_PAX_REFCOUNT
15251+ "jno 0f\n"
15252+ LOCK_PREFIX "addl %1,%0\n"
15253+ "int $4\n0:\n"
15254+ _ASM_EXTABLE(0b, 0b)
15255+#endif
15256+
15257+ : "+m" (v->counter)
15258+ : "ir" (i));
15259+}
15260+
15261+/**
15262+ * atomic_sub_unchecked - subtract integer from atomic variable
15263+ * @i: integer value to subtract
15264+ * @v: pointer of type atomic_unchecked_t
15265+ *
15266+ * Atomically subtracts @i from @v.
15267+ */
15268+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
15269+{
15270+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
15271 : "+m" (v->counter)
15272 : "ir" (i));
15273 }
15274@@ -78,7 +145,7 @@ static inline void atomic_sub(int i, atomic_t *v)
15275 */
15276 static inline int atomic_sub_and_test(int i, atomic_t *v)
15277 {
15278- GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
15279+ GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
15280 }
15281
15282 /**
15283@@ -89,7 +156,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
15284 */
15285 static inline void atomic_inc(atomic_t *v)
15286 {
15287- asm volatile(LOCK_PREFIX "incl %0"
15288+ asm volatile(LOCK_PREFIX "incl %0\n"
15289+
15290+#ifdef CONFIG_PAX_REFCOUNT
15291+ "jno 0f\n"
15292+ LOCK_PREFIX "decl %0\n"
15293+ "int $4\n0:\n"
15294+ _ASM_EXTABLE(0b, 0b)
15295+#endif
15296+
15297+ : "+m" (v->counter));
15298+}
15299+
15300+/**
15301+ * atomic_inc_unchecked - increment atomic variable
15302+ * @v: pointer of type atomic_unchecked_t
15303+ *
15304+ * Atomically increments @v by 1.
15305+ */
15306+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
15307+{
15308+ asm volatile(LOCK_PREFIX "incl %0\n"
15309 : "+m" (v->counter));
15310 }
15311
15312@@ -101,7 +188,27 @@ static inline void atomic_inc(atomic_t *v)
15313 */
15314 static inline void atomic_dec(atomic_t *v)
15315 {
15316- asm volatile(LOCK_PREFIX "decl %0"
15317+ asm volatile(LOCK_PREFIX "decl %0\n"
15318+
15319+#ifdef CONFIG_PAX_REFCOUNT
15320+ "jno 0f\n"
15321+ LOCK_PREFIX "incl %0\n"
15322+ "int $4\n0:\n"
15323+ _ASM_EXTABLE(0b, 0b)
15324+#endif
15325+
15326+ : "+m" (v->counter));
15327+}
15328+
15329+/**
15330+ * atomic_dec_unchecked - decrement atomic variable
15331+ * @v: pointer of type atomic_unchecked_t
15332+ *
15333+ * Atomically decrements @v by 1.
15334+ */
15335+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
15336+{
15337+ asm volatile(LOCK_PREFIX "decl %0\n"
15338 : "+m" (v->counter));
15339 }
15340
15341@@ -115,7 +222,7 @@ static inline void atomic_dec(atomic_t *v)
15342 */
15343 static inline int atomic_dec_and_test(atomic_t *v)
15344 {
15345- GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
15346+ GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
15347 }
15348
15349 /**
15350@@ -128,7 +235,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
15351 */
15352 static inline int atomic_inc_and_test(atomic_t *v)
15353 {
15354- GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
15355+ GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
15356+}
15357+
15358+/**
15359+ * atomic_inc_and_test_unchecked - increment and test
15360+ * @v: pointer of type atomic_unchecked_t
15361+ *
15362+ * Atomically increments @v by 1
15363+ * and returns true if the result is zero, or false for all
15364+ * other cases.
15365+ */
15366+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
15367+{
15368+ GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
15369 }
15370
15371 /**
15372@@ -142,7 +262,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
15373 */
15374 static inline int atomic_add_negative(int i, atomic_t *v)
15375 {
15376- GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
15377+ GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
15378 }
15379
15380 /**
15381@@ -152,7 +272,19 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15382 *
15383 * Atomically adds @i to @v and returns @i + @v
15384 */
15385-static inline int atomic_add_return(int i, atomic_t *v)
15386+static inline int __intentional_overflow(-1) atomic_add_return(int i, atomic_t *v)
15387+{
15388+ return i + xadd_check_overflow(&v->counter, i);
15389+}
15390+
15391+/**
15392+ * atomic_add_return_unchecked - add integer and return
15393+ * @i: integer value to add
15394+ * @v: pointer of type atomic_unchecked_t
15395+ *
15396+ * Atomically adds @i to @v and returns @i + @v
15397+ */
15398+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15399 {
15400 return i + xadd(&v->counter, i);
15401 }
15402@@ -164,15 +296,24 @@ static inline int atomic_add_return(int i, atomic_t *v)
15403 *
15404 * Atomically subtracts @i from @v and returns @v - @i
15405 */
15406-static inline int atomic_sub_return(int i, atomic_t *v)
15407+static inline int __intentional_overflow(-1) atomic_sub_return(int i, atomic_t *v)
15408 {
15409 return atomic_add_return(-i, v);
15410 }
15411
15412 #define atomic_inc_return(v) (atomic_add_return(1, v))
15413+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15414+{
15415+ return atomic_add_return_unchecked(1, v);
15416+}
15417 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15418
15419-static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15420+static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15421+{
15422+ return cmpxchg(&v->counter, old, new);
15423+}
15424+
15425+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15426 {
15427 return cmpxchg(&v->counter, old, new);
15428 }
15429@@ -182,6 +323,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15430 return xchg(&v->counter, new);
15431 }
15432
15433+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15434+{
15435+ return xchg(&v->counter, new);
15436+}
15437+
15438 /**
15439 * __atomic_add_unless - add unless the number is already a given value
15440 * @v: pointer of type atomic_t
15441@@ -191,14 +337,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15442 * Atomically adds @a to @v, so long as @v was not already @u.
15443 * Returns the old value of @v.
15444 */
15445-static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15446+static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15447 {
15448- int c, old;
15449+ int c, old, new;
15450 c = atomic_read(v);
15451 for (;;) {
15452- if (unlikely(c == (u)))
15453+ if (unlikely(c == u))
15454 break;
15455- old = atomic_cmpxchg((v), c, c + (a));
15456+
15457+ asm volatile("addl %2,%0\n"
15458+
15459+#ifdef CONFIG_PAX_REFCOUNT
15460+ "jno 0f\n"
15461+ "subl %2,%0\n"
15462+ "int $4\n0:\n"
15463+ _ASM_EXTABLE(0b, 0b)
15464+#endif
15465+
15466+ : "=r" (new)
15467+ : "0" (c), "ir" (a));
15468+
15469+ old = atomic_cmpxchg(v, c, new);
15470 if (likely(old == c))
15471 break;
15472 c = old;
15473@@ -207,6 +366,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15474 }
15475
15476 /**
15477+ * atomic_inc_not_zero_hint - increment if not null
15478+ * @v: pointer of type atomic_t
15479+ * @hint: probable value of the atomic before the increment
15480+ *
15481+ * This version of atomic_inc_not_zero() gives a hint of probable
15482+ * value of the atomic. This helps processor to not read the memory
15483+ * before doing the atomic read/modify/write cycle, lowering
15484+ * number of bus transactions on some arches.
15485+ *
15486+ * Returns: 0 if increment was not done, 1 otherwise.
15487+ */
15488+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15489+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15490+{
15491+ int val, c = hint, new;
15492+
15493+ /* sanity test, should be removed by compiler if hint is a constant */
15494+ if (!hint)
15495+ return __atomic_add_unless(v, 1, 0);
15496+
15497+ do {
15498+ asm volatile("incl %0\n"
15499+
15500+#ifdef CONFIG_PAX_REFCOUNT
15501+ "jno 0f\n"
15502+ "decl %0\n"
15503+ "int $4\n0:\n"
15504+ _ASM_EXTABLE(0b, 0b)
15505+#endif
15506+
15507+ : "=r" (new)
15508+ : "0" (c));
15509+
15510+ val = atomic_cmpxchg(v, c, new);
15511+ if (val == c)
15512+ return 1;
15513+ c = val;
15514+ } while (c);
15515+
15516+ return 0;
15517+}
15518+
15519+/**
15520 * atomic_inc_short - increment of a short integer
15521 * @v: pointer to type int
15522 *
15523@@ -220,14 +422,37 @@ static inline short int atomic_inc_short(short int *v)
15524 }
15525
15526 /* These are x86-specific, used by some header files */
15527-#define atomic_clear_mask(mask, addr) \
15528- asm volatile(LOCK_PREFIX "andl %0,%1" \
15529- : : "r" (~(mask)), "m" (*(addr)) : "memory")
15530+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15531+{
15532+ asm volatile(LOCK_PREFIX "andl %1,%0"
15533+ : "+m" (v->counter)
15534+ : "r" (~(mask))
15535+ : "memory");
15536+}
15537
15538-#define atomic_set_mask(mask, addr) \
15539- asm volatile(LOCK_PREFIX "orl %0,%1" \
15540- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15541- : "memory")
15542+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15543+{
15544+ asm volatile(LOCK_PREFIX "andl %1,%0"
15545+ : "+m" (v->counter)
15546+ : "r" (~(mask))
15547+ : "memory");
15548+}
15549+
15550+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15551+{
15552+ asm volatile(LOCK_PREFIX "orl %1,%0"
15553+ : "+m" (v->counter)
15554+ : "r" (mask)
15555+ : "memory");
15556+}
15557+
15558+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15559+{
15560+ asm volatile(LOCK_PREFIX "orl %1,%0"
15561+ : "+m" (v->counter)
15562+ : "r" (mask)
15563+ : "memory");
15564+}
15565
15566 #ifdef CONFIG_X86_32
15567 # include <asm/atomic64_32.h>
15568diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15569index b154de7..bf18a5a 100644
15570--- a/arch/x86/include/asm/atomic64_32.h
15571+++ b/arch/x86/include/asm/atomic64_32.h
15572@@ -12,6 +12,14 @@ typedef struct {
15573 u64 __aligned(8) counter;
15574 } atomic64_t;
15575
15576+#ifdef CONFIG_PAX_REFCOUNT
15577+typedef struct {
15578+ u64 __aligned(8) counter;
15579+} atomic64_unchecked_t;
15580+#else
15581+typedef atomic64_t atomic64_unchecked_t;
15582+#endif
15583+
15584 #define ATOMIC64_INIT(val) { (val) }
15585
15586 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15587@@ -37,21 +45,31 @@ typedef struct {
15588 ATOMIC64_DECL_ONE(sym##_386)
15589
15590 ATOMIC64_DECL_ONE(add_386);
15591+ATOMIC64_DECL_ONE(add_unchecked_386);
15592 ATOMIC64_DECL_ONE(sub_386);
15593+ATOMIC64_DECL_ONE(sub_unchecked_386);
15594 ATOMIC64_DECL_ONE(inc_386);
15595+ATOMIC64_DECL_ONE(inc_unchecked_386);
15596 ATOMIC64_DECL_ONE(dec_386);
15597+ATOMIC64_DECL_ONE(dec_unchecked_386);
15598 #endif
15599
15600 #define alternative_atomic64(f, out, in...) \
15601 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15602
15603 ATOMIC64_DECL(read);
15604+ATOMIC64_DECL(read_unchecked);
15605 ATOMIC64_DECL(set);
15606+ATOMIC64_DECL(set_unchecked);
15607 ATOMIC64_DECL(xchg);
15608 ATOMIC64_DECL(add_return);
15609+ATOMIC64_DECL(add_return_unchecked);
15610 ATOMIC64_DECL(sub_return);
15611+ATOMIC64_DECL(sub_return_unchecked);
15612 ATOMIC64_DECL(inc_return);
15613+ATOMIC64_DECL(inc_return_unchecked);
15614 ATOMIC64_DECL(dec_return);
15615+ATOMIC64_DECL(dec_return_unchecked);
15616 ATOMIC64_DECL(dec_if_positive);
15617 ATOMIC64_DECL(inc_not_zero);
15618 ATOMIC64_DECL(add_unless);
15619@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15620 }
15621
15622 /**
15623+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15624+ * @p: pointer to type atomic64_unchecked_t
15625+ * @o: expected value
15626+ * @n: new value
15627+ *
15628+ * Atomically sets @v to @n if it was equal to @o and returns
15629+ * the old value.
15630+ */
15631+
15632+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15633+{
15634+ return cmpxchg64(&v->counter, o, n);
15635+}
15636+
15637+/**
15638 * atomic64_xchg - xchg atomic64 variable
15639 * @v: pointer to type atomic64_t
15640 * @n: value to assign
15641@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15642 }
15643
15644 /**
15645+ * atomic64_set_unchecked - set atomic64 variable
15646+ * @v: pointer to type atomic64_unchecked_t
15647+ * @n: value to assign
15648+ *
15649+ * Atomically sets the value of @v to @n.
15650+ */
15651+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15652+{
15653+ unsigned high = (unsigned)(i >> 32);
15654+ unsigned low = (unsigned)i;
15655+ alternative_atomic64(set, /* no output */,
15656+ "S" (v), "b" (low), "c" (high)
15657+ : "eax", "edx", "memory");
15658+}
15659+
15660+/**
15661 * atomic64_read - read atomic64 variable
15662 * @v: pointer to type atomic64_t
15663 *
15664@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15665 }
15666
15667 /**
15668+ * atomic64_read_unchecked - read atomic64 variable
15669+ * @v: pointer to type atomic64_unchecked_t
15670+ *
15671+ * Atomically reads the value of @v and returns it.
15672+ */
15673+static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15674+{
15675+ long long r;
15676+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15677+ return r;
15678+ }
15679+
15680+/**
15681 * atomic64_add_return - add and return
15682 * @i: integer value to add
15683 * @v: pointer to type atomic64_t
15684@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15685 return i;
15686 }
15687
15688+/**
15689+ * atomic64_add_return_unchecked - add and return
15690+ * @i: integer value to add
15691+ * @v: pointer to type atomic64_unchecked_t
15692+ *
15693+ * Atomically adds @i to @v and returns @i + *@v
15694+ */
15695+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15696+{
15697+ alternative_atomic64(add_return_unchecked,
15698+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15699+ ASM_NO_INPUT_CLOBBER("memory"));
15700+ return i;
15701+}
15702+
15703 /*
15704 * Other variants with different arithmetic operators:
15705 */
15706@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15707 return a;
15708 }
15709
15710+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15711+{
15712+ long long a;
15713+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
15714+ "S" (v) : "memory", "ecx");
15715+ return a;
15716+}
15717+
15718 static inline long long atomic64_dec_return(atomic64_t *v)
15719 {
15720 long long a;
15721@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15722 }
15723
15724 /**
15725+ * atomic64_add_unchecked - add integer to atomic64 variable
15726+ * @i: integer value to add
15727+ * @v: pointer to type atomic64_unchecked_t
15728+ *
15729+ * Atomically adds @i to @v.
15730+ */
15731+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15732+{
15733+ __alternative_atomic64(add_unchecked, add_return_unchecked,
15734+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15735+ ASM_NO_INPUT_CLOBBER("memory"));
15736+ return i;
15737+}
15738+
15739+/**
15740 * atomic64_sub - subtract the atomic64 variable
15741 * @i: integer value to subtract
15742 * @v: pointer to type atomic64_t
15743diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15744index f8d273e..02f39f3 100644
15745--- a/arch/x86/include/asm/atomic64_64.h
15746+++ b/arch/x86/include/asm/atomic64_64.h
15747@@ -22,6 +22,18 @@ static inline long atomic64_read(const atomic64_t *v)
15748 }
15749
15750 /**
15751+ * atomic64_read_unchecked - read atomic64 variable
15752+ * @v: pointer of type atomic64_unchecked_t
15753+ *
15754+ * Atomically reads the value of @v.
15755+ * Doesn't imply a read memory barrier.
15756+ */
15757+static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15758+{
15759+ return ACCESS_ONCE((v)->counter);
15760+}
15761+
15762+/**
15763 * atomic64_set - set atomic64 variable
15764 * @v: pointer to type atomic64_t
15765 * @i: required value
15766@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15767 }
15768
15769 /**
15770+ * atomic64_set_unchecked - set atomic64 variable
15771+ * @v: pointer to type atomic64_unchecked_t
15772+ * @i: required value
15773+ *
15774+ * Atomically sets the value of @v to @i.
15775+ */
15776+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15777+{
15778+ v->counter = i;
15779+}
15780+
15781+/**
15782 * atomic64_add - add integer to atomic64 variable
15783 * @i: integer value to add
15784 * @v: pointer to type atomic64_t
15785@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15786 */
15787 static inline void atomic64_add(long i, atomic64_t *v)
15788 {
15789+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
15790+
15791+#ifdef CONFIG_PAX_REFCOUNT
15792+ "jno 0f\n"
15793+ LOCK_PREFIX "subq %1,%0\n"
15794+ "int $4\n0:\n"
15795+ _ASM_EXTABLE(0b, 0b)
15796+#endif
15797+
15798+ : "=m" (v->counter)
15799+ : "er" (i), "m" (v->counter));
15800+}
15801+
15802+/**
15803+ * atomic64_add_unchecked - add integer to atomic64 variable
15804+ * @i: integer value to add
15805+ * @v: pointer to type atomic64_unchecked_t
15806+ *
15807+ * Atomically adds @i to @v.
15808+ */
15809+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15810+{
15811 asm volatile(LOCK_PREFIX "addq %1,%0"
15812 : "=m" (v->counter)
15813 : "er" (i), "m" (v->counter));
15814@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15815 */
15816 static inline void atomic64_sub(long i, atomic64_t *v)
15817 {
15818- asm volatile(LOCK_PREFIX "subq %1,%0"
15819+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15820+
15821+#ifdef CONFIG_PAX_REFCOUNT
15822+ "jno 0f\n"
15823+ LOCK_PREFIX "addq %1,%0\n"
15824+ "int $4\n0:\n"
15825+ _ASM_EXTABLE(0b, 0b)
15826+#endif
15827+
15828+ : "=m" (v->counter)
15829+ : "er" (i), "m" (v->counter));
15830+}
15831+
15832+/**
15833+ * atomic64_sub_unchecked - subtract the atomic64 variable
15834+ * @i: integer value to subtract
15835+ * @v: pointer to type atomic64_unchecked_t
15836+ *
15837+ * Atomically subtracts @i from @v.
15838+ */
15839+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15840+{
15841+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15842 : "=m" (v->counter)
15843 : "er" (i), "m" (v->counter));
15844 }
15845@@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15846 */
15847 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15848 {
15849- GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15850+ GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15851 }
15852
15853 /**
15854@@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15855 */
15856 static inline void atomic64_inc(atomic64_t *v)
15857 {
15858+ asm volatile(LOCK_PREFIX "incq %0\n"
15859+
15860+#ifdef CONFIG_PAX_REFCOUNT
15861+ "jno 0f\n"
15862+ LOCK_PREFIX "decq %0\n"
15863+ "int $4\n0:\n"
15864+ _ASM_EXTABLE(0b, 0b)
15865+#endif
15866+
15867+ : "=m" (v->counter)
15868+ : "m" (v->counter));
15869+}
15870+
15871+/**
15872+ * atomic64_inc_unchecked - increment atomic64 variable
15873+ * @v: pointer to type atomic64_unchecked_t
15874+ *
15875+ * Atomically increments @v by 1.
15876+ */
15877+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15878+{
15879 asm volatile(LOCK_PREFIX "incq %0"
15880 : "=m" (v->counter)
15881 : "m" (v->counter));
15882@@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15883 */
15884 static inline void atomic64_dec(atomic64_t *v)
15885 {
15886- asm volatile(LOCK_PREFIX "decq %0"
15887+ asm volatile(LOCK_PREFIX "decq %0\n"
15888+
15889+#ifdef CONFIG_PAX_REFCOUNT
15890+ "jno 0f\n"
15891+ LOCK_PREFIX "incq %0\n"
15892+ "int $4\n0:\n"
15893+ _ASM_EXTABLE(0b, 0b)
15894+#endif
15895+
15896+ : "=m" (v->counter)
15897+ : "m" (v->counter));
15898+}
15899+
15900+/**
15901+ * atomic64_dec_unchecked - decrement atomic64 variable
15902+ * @v: pointer to type atomic64_t
15903+ *
15904+ * Atomically decrements @v by 1.
15905+ */
15906+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15907+{
15908+ asm volatile(LOCK_PREFIX "decq %0\n"
15909 : "=m" (v->counter)
15910 : "m" (v->counter));
15911 }
15912@@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15913 */
15914 static inline int atomic64_dec_and_test(atomic64_t *v)
15915 {
15916- GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15917+ GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15918 }
15919
15920 /**
15921@@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15922 */
15923 static inline int atomic64_inc_and_test(atomic64_t *v)
15924 {
15925- GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15926+ GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15927 }
15928
15929 /**
15930@@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15931 */
15932 static inline int atomic64_add_negative(long i, atomic64_t *v)
15933 {
15934- GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15935+ GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15936 }
15937
15938 /**
15939@@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15940 */
15941 static inline long atomic64_add_return(long i, atomic64_t *v)
15942 {
15943+ return i + xadd_check_overflow(&v->counter, i);
15944+}
15945+
15946+/**
15947+ * atomic64_add_return_unchecked - add and return
15948+ * @i: integer value to add
15949+ * @v: pointer to type atomic64_unchecked_t
15950+ *
15951+ * Atomically adds @i to @v and returns @i + @v
15952+ */
15953+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15954+{
15955 return i + xadd(&v->counter, i);
15956 }
15957
15958@@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15959 }
15960
15961 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15962+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15963+{
15964+ return atomic64_add_return_unchecked(1, v);
15965+}
15966 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15967
15968 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15969@@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15970 return cmpxchg(&v->counter, old, new);
15971 }
15972
15973+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15974+{
15975+ return cmpxchg(&v->counter, old, new);
15976+}
15977+
15978 static inline long atomic64_xchg(atomic64_t *v, long new)
15979 {
15980 return xchg(&v->counter, new);
15981@@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15982 */
15983 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15984 {
15985- long c, old;
15986+ long c, old, new;
15987 c = atomic64_read(v);
15988 for (;;) {
15989- if (unlikely(c == (u)))
15990+ if (unlikely(c == u))
15991 break;
15992- old = atomic64_cmpxchg((v), c, c + (a));
15993+
15994+ asm volatile("add %2,%0\n"
15995+
15996+#ifdef CONFIG_PAX_REFCOUNT
15997+ "jno 0f\n"
15998+ "sub %2,%0\n"
15999+ "int $4\n0:\n"
16000+ _ASM_EXTABLE(0b, 0b)
16001+#endif
16002+
16003+ : "=r" (new)
16004+ : "0" (c), "ir" (a));
16005+
16006+ old = atomic64_cmpxchg(v, c, new);
16007 if (likely(old == c))
16008 break;
16009 c = old;
16010 }
16011- return c != (u);
16012+ return c != u;
16013 }
16014
16015 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
16016diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
16017index 0f4460b..fa1ee19 100644
16018--- a/arch/x86/include/asm/barrier.h
16019+++ b/arch/x86/include/asm/barrier.h
16020@@ -107,7 +107,7 @@
16021 do { \
16022 compiletime_assert_atomic_type(*p); \
16023 smp_mb(); \
16024- ACCESS_ONCE(*p) = (v); \
16025+ ACCESS_ONCE_RW(*p) = (v); \
16026 } while (0)
16027
16028 #define smp_load_acquire(p) \
16029@@ -124,7 +124,7 @@ do { \
16030 do { \
16031 compiletime_assert_atomic_type(*p); \
16032 barrier(); \
16033- ACCESS_ONCE(*p) = (v); \
16034+ ACCESS_ONCE_RW(*p) = (v); \
16035 } while (0)
16036
16037 #define smp_load_acquire(p) \
16038diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
16039index cfe3b95..d01b118 100644
16040--- a/arch/x86/include/asm/bitops.h
16041+++ b/arch/x86/include/asm/bitops.h
16042@@ -50,7 +50,7 @@
16043 * a mask operation on a byte.
16044 */
16045 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
16046-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
16047+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
16048 #define CONST_MASK(nr) (1 << ((nr) & 7))
16049
16050 /**
16051@@ -203,7 +203,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
16052 */
16053 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
16054 {
16055- GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16056+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16057 }
16058
16059 /**
16060@@ -249,7 +249,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
16061 */
16062 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
16063 {
16064- GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16065+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16066 }
16067
16068 /**
16069@@ -302,7 +302,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
16070 */
16071 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
16072 {
16073- GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16074+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16075 }
16076
16077 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
16078@@ -343,7 +343,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
16079 *
16080 * Undefined if no bit exists, so code should check against 0 first.
16081 */
16082-static inline unsigned long __ffs(unsigned long word)
16083+static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
16084 {
16085 asm("rep; bsf %1,%0"
16086 : "=r" (word)
16087@@ -357,7 +357,7 @@ static inline unsigned long __ffs(unsigned long word)
16088 *
16089 * Undefined if no zero exists, so code should check against ~0UL first.
16090 */
16091-static inline unsigned long ffz(unsigned long word)
16092+static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
16093 {
16094 asm("rep; bsf %1,%0"
16095 : "=r" (word)
16096@@ -371,7 +371,7 @@ static inline unsigned long ffz(unsigned long word)
16097 *
16098 * Undefined if no set bit exists, so code should check against 0 first.
16099 */
16100-static inline unsigned long __fls(unsigned long word)
16101+static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
16102 {
16103 asm("bsr %1,%0"
16104 : "=r" (word)
16105@@ -434,7 +434,7 @@ static inline int ffs(int x)
16106 * set bit if value is nonzero. The last (most significant) bit is
16107 * at position 32.
16108 */
16109-static inline int fls(int x)
16110+static inline int __intentional_overflow(-1) fls(int x)
16111 {
16112 int r;
16113
16114@@ -476,7 +476,7 @@ static inline int fls(int x)
16115 * at position 64.
16116 */
16117 #ifdef CONFIG_X86_64
16118-static __always_inline int fls64(__u64 x)
16119+static __always_inline __intentional_overflow(-1) int fls64(__u64 x)
16120 {
16121 int bitpos = -1;
16122 /*
16123diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
16124index 4fa687a..60f2d39 100644
16125--- a/arch/x86/include/asm/boot.h
16126+++ b/arch/x86/include/asm/boot.h
16127@@ -6,10 +6,15 @@
16128 #include <uapi/asm/boot.h>
16129
16130 /* Physical address where kernel should be loaded. */
16131-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16132+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16133 + (CONFIG_PHYSICAL_ALIGN - 1)) \
16134 & ~(CONFIG_PHYSICAL_ALIGN - 1))
16135
16136+#ifndef __ASSEMBLY__
16137+extern unsigned char __LOAD_PHYSICAL_ADDR[];
16138+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
16139+#endif
16140+
16141 /* Minimum kernel alignment, as a power of two */
16142 #ifdef CONFIG_X86_64
16143 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
16144diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
16145index 48f99f1..d78ebf9 100644
16146--- a/arch/x86/include/asm/cache.h
16147+++ b/arch/x86/include/asm/cache.h
16148@@ -5,12 +5,13 @@
16149
16150 /* L1 cache line size */
16151 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
16152-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
16153+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
16154
16155 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
16156+#define __read_only __attribute__((__section__(".data..read_only")))
16157
16158 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
16159-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
16160+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
16161
16162 #ifdef CONFIG_X86_VSMP
16163 #ifdef CONFIG_SMP
16164diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
16165index 9863ee3..4a1f8e1 100644
16166--- a/arch/x86/include/asm/cacheflush.h
16167+++ b/arch/x86/include/asm/cacheflush.h
16168@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
16169 unsigned long pg_flags = pg->flags & _PGMT_MASK;
16170
16171 if (pg_flags == _PGMT_DEFAULT)
16172- return -1;
16173+ return ~0UL;
16174 else if (pg_flags == _PGMT_WC)
16175 return _PAGE_CACHE_WC;
16176 else if (pg_flags == _PGMT_UC_MINUS)
16177diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
16178index 76659b6..72b8439 100644
16179--- a/arch/x86/include/asm/calling.h
16180+++ b/arch/x86/include/asm/calling.h
16181@@ -82,107 +82,117 @@ For 32-bit we have the following conventions - kernel is built with
16182 #define RSP 152
16183 #define SS 160
16184
16185-#define ARGOFFSET R11
16186-#define SWFRAME ORIG_RAX
16187+#define ARGOFFSET R15
16188
16189 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1, rax_enosys=0
16190- subq $9*8+\addskip, %rsp
16191- CFI_ADJUST_CFA_OFFSET 9*8+\addskip
16192- movq_cfi rdi, 8*8
16193- movq_cfi rsi, 7*8
16194- movq_cfi rdx, 6*8
16195+ subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
16196+ CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
16197+ movq_cfi rdi, RDI
16198+ movq_cfi rsi, RSI
16199+ movq_cfi rdx, RDX
16200
16201 .if \save_rcx
16202- movq_cfi rcx, 5*8
16203+ movq_cfi rcx, RCX
16204 .endif
16205
16206 .if \rax_enosys
16207- movq $-ENOSYS, 4*8(%rsp)
16208+ movq $-ENOSYS, RAX(%rsp)
16209 .else
16210- movq_cfi rax, 4*8
16211+ movq_cfi rax, RAX
16212 .endif
16213
16214 .if \save_r891011
16215- movq_cfi r8, 3*8
16216- movq_cfi r9, 2*8
16217- movq_cfi r10, 1*8
16218- movq_cfi r11, 0*8
16219+ movq_cfi r8, R8
16220+ movq_cfi r9, R9
16221+ movq_cfi r10, R10
16222+ movq_cfi r11, R11
16223 .endif
16224
16225+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16226+ movq_cfi r12, R12
16227+#endif
16228+
16229 .endm
16230
16231-#define ARG_SKIP (9*8)
16232+#define ARG_SKIP ORIG_RAX
16233
16234 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
16235 rstor_r8910=1, rstor_rdx=1
16236+
16237+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16238+ movq_cfi_restore R12, r12
16239+#endif
16240+
16241 .if \rstor_r11
16242- movq_cfi_restore 0*8, r11
16243+ movq_cfi_restore R11, r11
16244 .endif
16245
16246 .if \rstor_r8910
16247- movq_cfi_restore 1*8, r10
16248- movq_cfi_restore 2*8, r9
16249- movq_cfi_restore 3*8, r8
16250+ movq_cfi_restore R10, r10
16251+ movq_cfi_restore R9, r9
16252+ movq_cfi_restore R8, r8
16253 .endif
16254
16255 .if \rstor_rax
16256- movq_cfi_restore 4*8, rax
16257+ movq_cfi_restore RAX, rax
16258 .endif
16259
16260 .if \rstor_rcx
16261- movq_cfi_restore 5*8, rcx
16262+ movq_cfi_restore RCX, rcx
16263 .endif
16264
16265 .if \rstor_rdx
16266- movq_cfi_restore 6*8, rdx
16267+ movq_cfi_restore RDX, rdx
16268 .endif
16269
16270- movq_cfi_restore 7*8, rsi
16271- movq_cfi_restore 8*8, rdi
16272+ movq_cfi_restore RSI, rsi
16273+ movq_cfi_restore RDI, rdi
16274
16275- .if ARG_SKIP+\addskip > 0
16276- addq $ARG_SKIP+\addskip, %rsp
16277- CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
16278+ .if ORIG_RAX+\addskip > 0
16279+ addq $ORIG_RAX+\addskip, %rsp
16280+ CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
16281 .endif
16282 .endm
16283
16284- .macro LOAD_ARGS offset, skiprax=0
16285- movq \offset(%rsp), %r11
16286- movq \offset+8(%rsp), %r10
16287- movq \offset+16(%rsp), %r9
16288- movq \offset+24(%rsp), %r8
16289- movq \offset+40(%rsp), %rcx
16290- movq \offset+48(%rsp), %rdx
16291- movq \offset+56(%rsp), %rsi
16292- movq \offset+64(%rsp), %rdi
16293+ .macro LOAD_ARGS skiprax=0
16294+ movq R11(%rsp), %r11
16295+ movq R10(%rsp), %r10
16296+ movq R9(%rsp), %r9
16297+ movq R8(%rsp), %r8
16298+ movq RCX(%rsp), %rcx
16299+ movq RDX(%rsp), %rdx
16300+ movq RSI(%rsp), %rsi
16301+ movq RDI(%rsp), %rdi
16302 .if \skiprax
16303 .else
16304- movq \offset+72(%rsp), %rax
16305+ movq ORIG_RAX(%rsp), %rax
16306 .endif
16307 .endm
16308
16309-#define REST_SKIP (6*8)
16310-
16311 .macro SAVE_REST
16312- subq $REST_SKIP, %rsp
16313- CFI_ADJUST_CFA_OFFSET REST_SKIP
16314- movq_cfi rbx, 5*8
16315- movq_cfi rbp, 4*8
16316- movq_cfi r12, 3*8
16317- movq_cfi r13, 2*8
16318- movq_cfi r14, 1*8
16319- movq_cfi r15, 0*8
16320+ movq_cfi rbx, RBX
16321+ movq_cfi rbp, RBP
16322+
16323+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16324+ movq_cfi r12, R12
16325+#endif
16326+
16327+ movq_cfi r13, R13
16328+ movq_cfi r14, R14
16329+ movq_cfi r15, R15
16330 .endm
16331
16332 .macro RESTORE_REST
16333- movq_cfi_restore 0*8, r15
16334- movq_cfi_restore 1*8, r14
16335- movq_cfi_restore 2*8, r13
16336- movq_cfi_restore 3*8, r12
16337- movq_cfi_restore 4*8, rbp
16338- movq_cfi_restore 5*8, rbx
16339- addq $REST_SKIP, %rsp
16340- CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
16341+ movq_cfi_restore R15, r15
16342+ movq_cfi_restore R14, r14
16343+ movq_cfi_restore R13, r13
16344+
16345+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16346+ movq_cfi_restore R12, r12
16347+#endif
16348+
16349+ movq_cfi_restore RBP, rbp
16350+ movq_cfi_restore RBX, rbx
16351 .endm
16352
16353 .macro SAVE_ALL
16354diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
16355index f50de69..2b0a458 100644
16356--- a/arch/x86/include/asm/checksum_32.h
16357+++ b/arch/x86/include/asm/checksum_32.h
16358@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
16359 int len, __wsum sum,
16360 int *src_err_ptr, int *dst_err_ptr);
16361
16362+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
16363+ int len, __wsum sum,
16364+ int *src_err_ptr, int *dst_err_ptr);
16365+
16366+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
16367+ int len, __wsum sum,
16368+ int *src_err_ptr, int *dst_err_ptr);
16369+
16370 /*
16371 * Note: when you get a NULL pointer exception here this means someone
16372 * passed in an incorrect kernel address to one of these functions.
16373@@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
16374
16375 might_sleep();
16376 stac();
16377- ret = csum_partial_copy_generic((__force void *)src, dst,
16378+ ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
16379 len, sum, err_ptr, NULL);
16380 clac();
16381
16382@@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
16383 might_sleep();
16384 if (access_ok(VERIFY_WRITE, dst, len)) {
16385 stac();
16386- ret = csum_partial_copy_generic(src, (__force void *)dst,
16387+ ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
16388 len, sum, NULL, err_ptr);
16389 clac();
16390 return ret;
16391diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
16392index 99c105d7..2f667ac 100644
16393--- a/arch/x86/include/asm/cmpxchg.h
16394+++ b/arch/x86/include/asm/cmpxchg.h
16395@@ -16,8 +16,12 @@ extern void __cmpxchg_wrong_size(void)
16396 __compiletime_error("Bad argument size for cmpxchg");
16397 extern void __xadd_wrong_size(void)
16398 __compiletime_error("Bad argument size for xadd");
16399+extern void __xadd_check_overflow_wrong_size(void)
16400+ __compiletime_error("Bad argument size for xadd_check_overflow");
16401 extern void __add_wrong_size(void)
16402 __compiletime_error("Bad argument size for add");
16403+extern void __add_check_overflow_wrong_size(void)
16404+ __compiletime_error("Bad argument size for add_check_overflow");
16405
16406 /*
16407 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
16408@@ -69,6 +73,38 @@ extern void __add_wrong_size(void)
16409 __ret; \
16410 })
16411
16412+#ifdef CONFIG_PAX_REFCOUNT
16413+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
16414+ ({ \
16415+ __typeof__ (*(ptr)) __ret = (arg); \
16416+ switch (sizeof(*(ptr))) { \
16417+ case __X86_CASE_L: \
16418+ asm volatile (lock #op "l %0, %1\n" \
16419+ "jno 0f\n" \
16420+ "mov %0,%1\n" \
16421+ "int $4\n0:\n" \
16422+ _ASM_EXTABLE(0b, 0b) \
16423+ : "+r" (__ret), "+m" (*(ptr)) \
16424+ : : "memory", "cc"); \
16425+ break; \
16426+ case __X86_CASE_Q: \
16427+ asm volatile (lock #op "q %q0, %1\n" \
16428+ "jno 0f\n" \
16429+ "mov %0,%1\n" \
16430+ "int $4\n0:\n" \
16431+ _ASM_EXTABLE(0b, 0b) \
16432+ : "+r" (__ret), "+m" (*(ptr)) \
16433+ : : "memory", "cc"); \
16434+ break; \
16435+ default: \
16436+ __ ## op ## _check_overflow_wrong_size(); \
16437+ } \
16438+ __ret; \
16439+ })
16440+#else
16441+#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
16442+#endif
16443+
16444 /*
16445 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16446 * Since this is generally used to protect other memory information, we
16447@@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
16448 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16449 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16450
16451+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16452+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16453+
16454 #define __add(ptr, inc, lock) \
16455 ({ \
16456 __typeof__ (*(ptr)) __ret = (inc); \
16457diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16458index 59c6c40..5e0b22c 100644
16459--- a/arch/x86/include/asm/compat.h
16460+++ b/arch/x86/include/asm/compat.h
16461@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16462 typedef u32 compat_uint_t;
16463 typedef u32 compat_ulong_t;
16464 typedef u64 __attribute__((aligned(4))) compat_u64;
16465-typedef u32 compat_uptr_t;
16466+typedef u32 __user compat_uptr_t;
16467
16468 struct compat_timespec {
16469 compat_time_t tv_sec;
16470diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16471index 0bb1335..8f1aec7 100644
16472--- a/arch/x86/include/asm/cpufeature.h
16473+++ b/arch/x86/include/asm/cpufeature.h
16474@@ -207,7 +207,7 @@
16475 #define X86_FEATURE_PAUSEFILTER ( 8*32+13) /* AMD filtered pause intercept */
16476 #define X86_FEATURE_PFTHRESHOLD ( 8*32+14) /* AMD pause filter threshold */
16477 #define X86_FEATURE_VMMCALL ( 8*32+15) /* Prefer vmmcall to vmcall */
16478-
16479+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16480
16481 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16482 #define X86_FEATURE_FSGSBASE ( 9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16483@@ -215,7 +215,7 @@
16484 #define X86_FEATURE_BMI1 ( 9*32+ 3) /* 1st group bit manipulation extensions */
16485 #define X86_FEATURE_HLE ( 9*32+ 4) /* Hardware Lock Elision */
16486 #define X86_FEATURE_AVX2 ( 9*32+ 5) /* AVX2 instructions */
16487-#define X86_FEATURE_SMEP ( 9*32+ 7) /* Supervisor Mode Execution Protection */
16488+#define X86_FEATURE_SMEP ( 9*32+ 7) /* Supervisor Mode Execution Prevention */
16489 #define X86_FEATURE_BMI2 ( 9*32+ 8) /* 2nd group bit manipulation extensions */
16490 #define X86_FEATURE_ERMS ( 9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16491 #define X86_FEATURE_INVPCID ( 9*32+10) /* Invalidate Processor Context ID */
16492@@ -383,6 +383,7 @@ extern const char * const x86_bug_flags[NBUGINTS*32];
16493 #define cpu_has_cx16 boot_cpu_has(X86_FEATURE_CX16)
16494 #define cpu_has_eager_fpu boot_cpu_has(X86_FEATURE_EAGER_FPU)
16495 #define cpu_has_topoext boot_cpu_has(X86_FEATURE_TOPOEXT)
16496+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16497
16498 #if __GNUC__ >= 4
16499 extern void warn_pre_alternatives(void);
16500@@ -434,7 +435,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16501
16502 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16503 t_warn:
16504- warn_pre_alternatives();
16505+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16506+ warn_pre_alternatives();
16507 return false;
16508 #endif
16509
16510@@ -454,7 +456,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16511 ".section .discard,\"aw\",@progbits\n"
16512 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16513 ".previous\n"
16514- ".section .altinstr_replacement,\"ax\"\n"
16515+ ".section .altinstr_replacement,\"a\"\n"
16516 "3: movb $1,%0\n"
16517 "4:\n"
16518 ".previous\n"
16519@@ -491,7 +493,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16520 " .byte 2b - 1b\n" /* src len */
16521 " .byte 4f - 3f\n" /* repl len */
16522 ".previous\n"
16523- ".section .altinstr_replacement,\"ax\"\n"
16524+ ".section .altinstr_replacement,\"a\"\n"
16525 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16526 "4:\n"
16527 ".previous\n"
16528@@ -524,7 +526,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16529 ".section .discard,\"aw\",@progbits\n"
16530 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16531 ".previous\n"
16532- ".section .altinstr_replacement,\"ax\"\n"
16533+ ".section .altinstr_replacement,\"a\"\n"
16534 "3: movb $0,%0\n"
16535 "4:\n"
16536 ".previous\n"
16537@@ -538,7 +540,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16538 ".section .discard,\"aw\",@progbits\n"
16539 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16540 ".previous\n"
16541- ".section .altinstr_replacement,\"ax\"\n"
16542+ ".section .altinstr_replacement,\"a\"\n"
16543 "5: movb $1,%0\n"
16544 "6:\n"
16545 ".previous\n"
16546diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16547index 50d033a..37deb26 100644
16548--- a/arch/x86/include/asm/desc.h
16549+++ b/arch/x86/include/asm/desc.h
16550@@ -4,6 +4,7 @@
16551 #include <asm/desc_defs.h>
16552 #include <asm/ldt.h>
16553 #include <asm/mmu.h>
16554+#include <asm/pgtable.h>
16555
16556 #include <linux/smp.h>
16557 #include <linux/percpu.h>
16558@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16559
16560 desc->type = (info->read_exec_only ^ 1) << 1;
16561 desc->type |= info->contents << 2;
16562+ desc->type |= info->seg_not_present ^ 1;
16563
16564 desc->s = 1;
16565 desc->dpl = 0x3;
16566@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16567 }
16568
16569 extern struct desc_ptr idt_descr;
16570-extern gate_desc idt_table[];
16571-extern struct desc_ptr debug_idt_descr;
16572-extern gate_desc debug_idt_table[];
16573-
16574-struct gdt_page {
16575- struct desc_struct gdt[GDT_ENTRIES];
16576-} __attribute__((aligned(PAGE_SIZE)));
16577-
16578-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16579+extern gate_desc idt_table[IDT_ENTRIES];
16580+extern const struct desc_ptr debug_idt_descr;
16581+extern gate_desc debug_idt_table[IDT_ENTRIES];
16582
16583+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16584 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16585 {
16586- return per_cpu(gdt_page, cpu).gdt;
16587+ return cpu_gdt_table[cpu];
16588 }
16589
16590 #ifdef CONFIG_X86_64
16591@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16592 unsigned long base, unsigned dpl, unsigned flags,
16593 unsigned short seg)
16594 {
16595- gate->a = (seg << 16) | (base & 0xffff);
16596- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16597+ gate->gate.offset_low = base;
16598+ gate->gate.seg = seg;
16599+ gate->gate.reserved = 0;
16600+ gate->gate.type = type;
16601+ gate->gate.s = 0;
16602+ gate->gate.dpl = dpl;
16603+ gate->gate.p = 1;
16604+ gate->gate.offset_high = base >> 16;
16605 }
16606
16607 #endif
16608@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16609
16610 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16611 {
16612+ pax_open_kernel();
16613 memcpy(&idt[entry], gate, sizeof(*gate));
16614+ pax_close_kernel();
16615 }
16616
16617 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16618 {
16619+ pax_open_kernel();
16620 memcpy(&ldt[entry], desc, 8);
16621+ pax_close_kernel();
16622 }
16623
16624 static inline void
16625@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16626 default: size = sizeof(*gdt); break;
16627 }
16628
16629+ pax_open_kernel();
16630 memcpy(&gdt[entry], desc, size);
16631+ pax_close_kernel();
16632 }
16633
16634 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16635@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16636
16637 static inline void native_load_tr_desc(void)
16638 {
16639+ pax_open_kernel();
16640 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16641+ pax_close_kernel();
16642 }
16643
16644 static inline void native_load_gdt(const struct desc_ptr *dtr)
16645@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16646 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16647 unsigned int i;
16648
16649+ pax_open_kernel();
16650 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16651 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16652+ pax_close_kernel();
16653 }
16654
16655 #define _LDT_empty(info) \
16656@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16657 preempt_enable();
16658 }
16659
16660-static inline unsigned long get_desc_base(const struct desc_struct *desc)
16661+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16662 {
16663 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16664 }
16665@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16666 }
16667
16668 #ifdef CONFIG_X86_64
16669-static inline void set_nmi_gate(int gate, void *addr)
16670+static inline void set_nmi_gate(int gate, const void *addr)
16671 {
16672 gate_desc s;
16673
16674@@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16675 #endif
16676
16677 #ifdef CONFIG_TRACING
16678-extern struct desc_ptr trace_idt_descr;
16679-extern gate_desc trace_idt_table[];
16680+extern const struct desc_ptr trace_idt_descr;
16681+extern gate_desc trace_idt_table[IDT_ENTRIES];
16682 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16683 {
16684 write_idt_entry(trace_idt_table, entry, gate);
16685 }
16686
16687-static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16688+static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16689 unsigned dpl, unsigned ist, unsigned seg)
16690 {
16691 gate_desc s;
16692@@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16693 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16694 #endif
16695
16696-static inline void _set_gate(int gate, unsigned type, void *addr,
16697+static inline void _set_gate(int gate, unsigned type, const void *addr,
16698 unsigned dpl, unsigned ist, unsigned seg)
16699 {
16700 gate_desc s;
16701@@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16702 #define set_intr_gate(n, addr) \
16703 do { \
16704 BUG_ON((unsigned)n > 0xFF); \
16705- _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16706+ _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16707 __KERNEL_CS); \
16708- _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16709+ _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16710 0, 0, __KERNEL_CS); \
16711 } while (0)
16712
16713@@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16714 /*
16715 * This routine sets up an interrupt gate at directory privilege level 3.
16716 */
16717-static inline void set_system_intr_gate(unsigned int n, void *addr)
16718+static inline void set_system_intr_gate(unsigned int n, const void *addr)
16719 {
16720 BUG_ON((unsigned)n > 0xFF);
16721 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16722 }
16723
16724-static inline void set_system_trap_gate(unsigned int n, void *addr)
16725+static inline void set_system_trap_gate(unsigned int n, const void *addr)
16726 {
16727 BUG_ON((unsigned)n > 0xFF);
16728 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16729 }
16730
16731-static inline void set_trap_gate(unsigned int n, void *addr)
16732+static inline void set_trap_gate(unsigned int n, const void *addr)
16733 {
16734 BUG_ON((unsigned)n > 0xFF);
16735 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16736@@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16737 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16738 {
16739 BUG_ON((unsigned)n > 0xFF);
16740- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16741+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16742 }
16743
16744-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16745+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16746 {
16747 BUG_ON((unsigned)n > 0xFF);
16748 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16749 }
16750
16751-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16752+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16753 {
16754 BUG_ON((unsigned)n > 0xFF);
16755 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16756@@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16757 else
16758 load_idt((const struct desc_ptr *)&idt_descr);
16759 }
16760+
16761+#ifdef CONFIG_X86_32
16762+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16763+{
16764+ struct desc_struct d;
16765+
16766+ if (likely(limit))
16767+ limit = (limit - 1UL) >> PAGE_SHIFT;
16768+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
16769+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16770+}
16771+#endif
16772+
16773 #endif /* _ASM_X86_DESC_H */
16774diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16775index 278441f..b95a174 100644
16776--- a/arch/x86/include/asm/desc_defs.h
16777+++ b/arch/x86/include/asm/desc_defs.h
16778@@ -31,6 +31,12 @@ struct desc_struct {
16779 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16780 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16781 };
16782+ struct {
16783+ u16 offset_low;
16784+ u16 seg;
16785+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16786+ unsigned offset_high: 16;
16787+ } gate;
16788 };
16789 } __attribute__((packed));
16790
16791diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16792index ced283a..ffe04cc 100644
16793--- a/arch/x86/include/asm/div64.h
16794+++ b/arch/x86/include/asm/div64.h
16795@@ -39,7 +39,7 @@
16796 __mod; \
16797 })
16798
16799-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16800+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16801 {
16802 union {
16803 u64 v64;
16804diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16805index ca3347a..1a5082a 100644
16806--- a/arch/x86/include/asm/elf.h
16807+++ b/arch/x86/include/asm/elf.h
16808@@ -75,9 +75,6 @@ typedef struct user_fxsr_struct elf_fpxregset_t;
16809
16810 #include <asm/vdso.h>
16811
16812-#ifdef CONFIG_X86_64
16813-extern unsigned int vdso64_enabled;
16814-#endif
16815 #if defined(CONFIG_X86_32) || defined(CONFIG_COMPAT)
16816 extern unsigned int vdso32_enabled;
16817 #endif
16818@@ -249,7 +246,25 @@ extern int force_personality32;
16819 the loader. We need to make sure that it is out of the way of the program
16820 that it will "exec", and that there is sufficient room for the brk. */
16821
16822+#ifdef CONFIG_PAX_SEGMEXEC
16823+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16824+#else
16825 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16826+#endif
16827+
16828+#ifdef CONFIG_PAX_ASLR
16829+#ifdef CONFIG_X86_32
16830+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16831+
16832+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16833+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16834+#else
16835+#define PAX_ELF_ET_DYN_BASE 0x400000UL
16836+
16837+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16838+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16839+#endif
16840+#endif
16841
16842 /* This yields a mask that user programs can use to figure out what
16843 instruction set this CPU supports. This could be done in user space,
16844@@ -298,17 +313,13 @@ do { \
16845
16846 #define ARCH_DLINFO \
16847 do { \
16848- if (vdso64_enabled) \
16849- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16850- (unsigned long __force)current->mm->context.vdso); \
16851+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16852 } while (0)
16853
16854 /* As a historical oddity, the x32 and x86_64 vDSOs are controlled together. */
16855 #define ARCH_DLINFO_X32 \
16856 do { \
16857- if (vdso64_enabled) \
16858- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16859- (unsigned long __force)current->mm->context.vdso); \
16860+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16861 } while (0)
16862
16863 #define AT_SYSINFO 32
16864@@ -323,10 +334,10 @@ else \
16865
16866 #endif /* !CONFIG_X86_32 */
16867
16868-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16869+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16870
16871 #define VDSO_ENTRY \
16872- ((unsigned long)current->mm->context.vdso + \
16873+ (current->mm->context.vdso + \
16874 selected_vdso32->sym___kernel_vsyscall)
16875
16876 struct linux_binprm;
16877@@ -338,9 +349,6 @@ extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
16878 int uses_interp);
16879 #define compat_arch_setup_additional_pages compat_arch_setup_additional_pages
16880
16881-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16882-#define arch_randomize_brk arch_randomize_brk
16883-
16884 /*
16885 * True on X86_32 or when emulating IA32 on X86_64
16886 */
16887diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16888index 77a99ac..39ff7f5 100644
16889--- a/arch/x86/include/asm/emergency-restart.h
16890+++ b/arch/x86/include/asm/emergency-restart.h
16891@@ -1,6 +1,6 @@
16892 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16893 #define _ASM_X86_EMERGENCY_RESTART_H
16894
16895-extern void machine_emergency_restart(void);
16896+extern void machine_emergency_restart(void) __noreturn;
16897
16898 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16899diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16900index 1c7eefe..d0e4702 100644
16901--- a/arch/x86/include/asm/floppy.h
16902+++ b/arch/x86/include/asm/floppy.h
16903@@ -229,18 +229,18 @@ static struct fd_routine_l {
16904 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16905 } fd_routine[] = {
16906 {
16907- request_dma,
16908- free_dma,
16909- get_dma_residue,
16910- dma_mem_alloc,
16911- hard_dma_setup
16912+ ._request_dma = request_dma,
16913+ ._free_dma = free_dma,
16914+ ._get_dma_residue = get_dma_residue,
16915+ ._dma_mem_alloc = dma_mem_alloc,
16916+ ._dma_setup = hard_dma_setup
16917 },
16918 {
16919- vdma_request_dma,
16920- vdma_nop,
16921- vdma_get_dma_residue,
16922- vdma_mem_alloc,
16923- vdma_dma_setup
16924+ ._request_dma = vdma_request_dma,
16925+ ._free_dma = vdma_nop,
16926+ ._get_dma_residue = vdma_get_dma_residue,
16927+ ._dma_mem_alloc = vdma_mem_alloc,
16928+ ._dma_setup = vdma_dma_setup
16929 }
16930 };
16931
16932diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16933index e97622f..d0ba77a 100644
16934--- a/arch/x86/include/asm/fpu-internal.h
16935+++ b/arch/x86/include/asm/fpu-internal.h
16936@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16937 #define user_insn(insn, output, input...) \
16938 ({ \
16939 int err; \
16940+ pax_open_userland(); \
16941 asm volatile(ASM_STAC "\n" \
16942- "1:" #insn "\n\t" \
16943+ "1:" \
16944+ __copyuser_seg \
16945+ #insn "\n\t" \
16946 "2: " ASM_CLAC "\n" \
16947 ".section .fixup,\"ax\"\n" \
16948 "3: movl $-1,%[err]\n" \
16949@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16950 _ASM_EXTABLE(1b, 3b) \
16951 : [err] "=r" (err), output \
16952 : "0"(0), input); \
16953+ pax_close_userland(); \
16954 err; \
16955 })
16956
16957@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16958 "fnclex\n\t"
16959 "emms\n\t"
16960 "fildl %P[addr]" /* set F?P to defined value */
16961- : : [addr] "m" (tsk->thread.fpu.has_fpu));
16962+ : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16963 }
16964
16965 return fpu_restore_checking(&tsk->thread.fpu);
16966diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16967index b4c1f54..e290c08 100644
16968--- a/arch/x86/include/asm/futex.h
16969+++ b/arch/x86/include/asm/futex.h
16970@@ -12,6 +12,7 @@
16971 #include <asm/smap.h>
16972
16973 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16974+ typecheck(u32 __user *, uaddr); \
16975 asm volatile("\t" ASM_STAC "\n" \
16976 "1:\t" insn "\n" \
16977 "2:\t" ASM_CLAC "\n" \
16978@@ -20,15 +21,16 @@
16979 "\tjmp\t2b\n" \
16980 "\t.previous\n" \
16981 _ASM_EXTABLE(1b, 3b) \
16982- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16983+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16984 : "i" (-EFAULT), "0" (oparg), "1" (0))
16985
16986 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16987+ typecheck(u32 __user *, uaddr); \
16988 asm volatile("\t" ASM_STAC "\n" \
16989 "1:\tmovl %2, %0\n" \
16990 "\tmovl\t%0, %3\n" \
16991 "\t" insn "\n" \
16992- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16993+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16994 "\tjnz\t1b\n" \
16995 "3:\t" ASM_CLAC "\n" \
16996 "\t.section .fixup,\"ax\"\n" \
16997@@ -38,7 +40,7 @@
16998 _ASM_EXTABLE(1b, 4b) \
16999 _ASM_EXTABLE(2b, 4b) \
17000 : "=&a" (oldval), "=&r" (ret), \
17001- "+m" (*uaddr), "=&r" (tem) \
17002+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
17003 : "r" (oparg), "i" (-EFAULT), "1" (0))
17004
17005 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17006@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17007
17008 pagefault_disable();
17009
17010+ pax_open_userland();
17011 switch (op) {
17012 case FUTEX_OP_SET:
17013- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
17014+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
17015 break;
17016 case FUTEX_OP_ADD:
17017- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
17018+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
17019 uaddr, oparg);
17020 break;
17021 case FUTEX_OP_OR:
17022@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17023 default:
17024 ret = -ENOSYS;
17025 }
17026+ pax_close_userland();
17027
17028 pagefault_enable();
17029
17030diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
17031index 4615906..788c817 100644
17032--- a/arch/x86/include/asm/hw_irq.h
17033+++ b/arch/x86/include/asm/hw_irq.h
17034@@ -164,8 +164,8 @@ extern void setup_ioapic_dest(void);
17035 extern void enable_IO_APIC(void);
17036
17037 /* Statistics */
17038-extern atomic_t irq_err_count;
17039-extern atomic_t irq_mis_count;
17040+extern atomic_unchecked_t irq_err_count;
17041+extern atomic_unchecked_t irq_mis_count;
17042
17043 /* EISA */
17044 extern void eisa_set_level_irq(unsigned int irq);
17045diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
17046index ccffa53..3c90c87 100644
17047--- a/arch/x86/include/asm/i8259.h
17048+++ b/arch/x86/include/asm/i8259.h
17049@@ -62,7 +62,7 @@ struct legacy_pic {
17050 void (*init)(int auto_eoi);
17051 int (*irq_pending)(unsigned int irq);
17052 void (*make_irq)(unsigned int irq);
17053-};
17054+} __do_const;
17055
17056 extern struct legacy_pic *legacy_pic;
17057 extern struct legacy_pic null_legacy_pic;
17058diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
17059index b8237d8..3e8864e 100644
17060--- a/arch/x86/include/asm/io.h
17061+++ b/arch/x86/include/asm/io.h
17062@@ -52,12 +52,12 @@ static inline void name(type val, volatile void __iomem *addr) \
17063 "m" (*(volatile type __force *)addr) barrier); }
17064
17065 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
17066-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
17067-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
17068+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
17069+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
17070
17071 build_mmio_read(__readb, "b", unsigned char, "=q", )
17072-build_mmio_read(__readw, "w", unsigned short, "=r", )
17073-build_mmio_read(__readl, "l", unsigned int, "=r", )
17074+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
17075+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
17076
17077 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
17078 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
17079@@ -109,7 +109,7 @@ build_mmio_write(writeq, "q", unsigned long, "r", :"memory")
17080 * this function
17081 */
17082
17083-static inline phys_addr_t virt_to_phys(volatile void *address)
17084+static inline phys_addr_t __intentional_overflow(-1) virt_to_phys(volatile void *address)
17085 {
17086 return __pa(address);
17087 }
17088@@ -185,7 +185,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
17089 return ioremap_nocache(offset, size);
17090 }
17091
17092-extern void iounmap(volatile void __iomem *addr);
17093+extern void iounmap(const volatile void __iomem *addr);
17094
17095 extern void set_iounmap_nonlazy(void);
17096
17097@@ -195,6 +195,17 @@ extern void set_iounmap_nonlazy(void);
17098
17099 #include <linux/vmalloc.h>
17100
17101+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
17102+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
17103+{
17104+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17105+}
17106+
17107+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
17108+{
17109+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17110+}
17111+
17112 /*
17113 * Convert a virtual cached pointer to an uncached pointer
17114 */
17115diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
17116index 0a8b519..80e7d5b 100644
17117--- a/arch/x86/include/asm/irqflags.h
17118+++ b/arch/x86/include/asm/irqflags.h
17119@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
17120 sti; \
17121 sysexit
17122
17123+#define GET_CR0_INTO_RDI mov %cr0, %rdi
17124+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
17125+#define GET_CR3_INTO_RDI mov %cr3, %rdi
17126+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
17127+
17128 #else
17129 #define INTERRUPT_RETURN iret
17130 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
17131diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
17132index 4421b5d..8543006 100644
17133--- a/arch/x86/include/asm/kprobes.h
17134+++ b/arch/x86/include/asm/kprobes.h
17135@@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
17136 #define RELATIVEJUMP_SIZE 5
17137 #define RELATIVECALL_OPCODE 0xe8
17138 #define RELATIVE_ADDR_SIZE 4
17139-#define MAX_STACK_SIZE 64
17140-#define MIN_STACK_SIZE(ADDR) \
17141- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
17142- THREAD_SIZE - (unsigned long)(ADDR))) \
17143- ? (MAX_STACK_SIZE) \
17144- : (((unsigned long)current_thread_info()) + \
17145- THREAD_SIZE - (unsigned long)(ADDR)))
17146+#define MAX_STACK_SIZE 64UL
17147+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
17148
17149 #define flush_insn_slot(p) do { } while (0)
17150
17151diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
17152index 6ed0c30..74fb6c3 100644
17153--- a/arch/x86/include/asm/kvm_host.h
17154+++ b/arch/x86/include/asm/kvm_host.h
17155@@ -51,6 +51,7 @@
17156 | X86_CR0_NW | X86_CR0_CD | X86_CR0_PG))
17157
17158 #define CR3_L_MODE_RESERVED_BITS 0xFFFFFF0000000000ULL
17159+#define CR3_PCID_INVD (1UL << 63)
17160 #define CR4_RESERVED_BITS \
17161 (~(unsigned long)(X86_CR4_VME | X86_CR4_PVI | X86_CR4_TSD | X86_CR4_DE\
17162 | X86_CR4_PSE | X86_CR4_PAE | X86_CR4_MCE \
17163diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
17164index 4ad6560..75c7bdd 100644
17165--- a/arch/x86/include/asm/local.h
17166+++ b/arch/x86/include/asm/local.h
17167@@ -10,33 +10,97 @@ typedef struct {
17168 atomic_long_t a;
17169 } local_t;
17170
17171+typedef struct {
17172+ atomic_long_unchecked_t a;
17173+} local_unchecked_t;
17174+
17175 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
17176
17177 #define local_read(l) atomic_long_read(&(l)->a)
17178+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
17179 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
17180+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
17181
17182 static inline void local_inc(local_t *l)
17183 {
17184- asm volatile(_ASM_INC "%0"
17185+ asm volatile(_ASM_INC "%0\n"
17186+
17187+#ifdef CONFIG_PAX_REFCOUNT
17188+ "jno 0f\n"
17189+ _ASM_DEC "%0\n"
17190+ "int $4\n0:\n"
17191+ _ASM_EXTABLE(0b, 0b)
17192+#endif
17193+
17194+ : "+m" (l->a.counter));
17195+}
17196+
17197+static inline void local_inc_unchecked(local_unchecked_t *l)
17198+{
17199+ asm volatile(_ASM_INC "%0\n"
17200 : "+m" (l->a.counter));
17201 }
17202
17203 static inline void local_dec(local_t *l)
17204 {
17205- asm volatile(_ASM_DEC "%0"
17206+ asm volatile(_ASM_DEC "%0\n"
17207+
17208+#ifdef CONFIG_PAX_REFCOUNT
17209+ "jno 0f\n"
17210+ _ASM_INC "%0\n"
17211+ "int $4\n0:\n"
17212+ _ASM_EXTABLE(0b, 0b)
17213+#endif
17214+
17215+ : "+m" (l->a.counter));
17216+}
17217+
17218+static inline void local_dec_unchecked(local_unchecked_t *l)
17219+{
17220+ asm volatile(_ASM_DEC "%0\n"
17221 : "+m" (l->a.counter));
17222 }
17223
17224 static inline void local_add(long i, local_t *l)
17225 {
17226- asm volatile(_ASM_ADD "%1,%0"
17227+ asm volatile(_ASM_ADD "%1,%0\n"
17228+
17229+#ifdef CONFIG_PAX_REFCOUNT
17230+ "jno 0f\n"
17231+ _ASM_SUB "%1,%0\n"
17232+ "int $4\n0:\n"
17233+ _ASM_EXTABLE(0b, 0b)
17234+#endif
17235+
17236+ : "+m" (l->a.counter)
17237+ : "ir" (i));
17238+}
17239+
17240+static inline void local_add_unchecked(long i, local_unchecked_t *l)
17241+{
17242+ asm volatile(_ASM_ADD "%1,%0\n"
17243 : "+m" (l->a.counter)
17244 : "ir" (i));
17245 }
17246
17247 static inline void local_sub(long i, local_t *l)
17248 {
17249- asm volatile(_ASM_SUB "%1,%0"
17250+ asm volatile(_ASM_SUB "%1,%0\n"
17251+
17252+#ifdef CONFIG_PAX_REFCOUNT
17253+ "jno 0f\n"
17254+ _ASM_ADD "%1,%0\n"
17255+ "int $4\n0:\n"
17256+ _ASM_EXTABLE(0b, 0b)
17257+#endif
17258+
17259+ : "+m" (l->a.counter)
17260+ : "ir" (i));
17261+}
17262+
17263+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
17264+{
17265+ asm volatile(_ASM_SUB "%1,%0\n"
17266 : "+m" (l->a.counter)
17267 : "ir" (i));
17268 }
17269@@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
17270 */
17271 static inline int local_sub_and_test(long i, local_t *l)
17272 {
17273- GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
17274+ GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
17275 }
17276
17277 /**
17278@@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
17279 */
17280 static inline int local_dec_and_test(local_t *l)
17281 {
17282- GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
17283+ GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
17284 }
17285
17286 /**
17287@@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
17288 */
17289 static inline int local_inc_and_test(local_t *l)
17290 {
17291- GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
17292+ GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
17293 }
17294
17295 /**
17296@@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
17297 */
17298 static inline int local_add_negative(long i, local_t *l)
17299 {
17300- GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
17301+ GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
17302 }
17303
17304 /**
17305@@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
17306 static inline long local_add_return(long i, local_t *l)
17307 {
17308 long __i = i;
17309+ asm volatile(_ASM_XADD "%0, %1\n"
17310+
17311+#ifdef CONFIG_PAX_REFCOUNT
17312+ "jno 0f\n"
17313+ _ASM_MOV "%0,%1\n"
17314+ "int $4\n0:\n"
17315+ _ASM_EXTABLE(0b, 0b)
17316+#endif
17317+
17318+ : "+r" (i), "+m" (l->a.counter)
17319+ : : "memory");
17320+ return i + __i;
17321+}
17322+
17323+/**
17324+ * local_add_return_unchecked - add and return
17325+ * @i: integer value to add
17326+ * @l: pointer to type local_unchecked_t
17327+ *
17328+ * Atomically adds @i to @l and returns @i + @l
17329+ */
17330+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
17331+{
17332+ long __i = i;
17333 asm volatile(_ASM_XADD "%0, %1;"
17334 : "+r" (i), "+m" (l->a.counter)
17335 : : "memory");
17336@@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
17337
17338 #define local_cmpxchg(l, o, n) \
17339 (cmpxchg_local(&((l)->a.counter), (o), (n)))
17340+#define local_cmpxchg_unchecked(l, o, n) \
17341+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
17342 /* Always has a lock prefix */
17343 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
17344
17345diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
17346new file mode 100644
17347index 0000000..2bfd3ba
17348--- /dev/null
17349+++ b/arch/x86/include/asm/mman.h
17350@@ -0,0 +1,15 @@
17351+#ifndef _X86_MMAN_H
17352+#define _X86_MMAN_H
17353+
17354+#include <uapi/asm/mman.h>
17355+
17356+#ifdef __KERNEL__
17357+#ifndef __ASSEMBLY__
17358+#ifdef CONFIG_X86_32
17359+#define arch_mmap_check i386_mmap_check
17360+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
17361+#endif
17362+#endif
17363+#endif
17364+
17365+#endif /* X86_MMAN_H */
17366diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
17367index 876e74e..e20bfb1 100644
17368--- a/arch/x86/include/asm/mmu.h
17369+++ b/arch/x86/include/asm/mmu.h
17370@@ -9,7 +9,7 @@
17371 * we put the segment information here.
17372 */
17373 typedef struct {
17374- void *ldt;
17375+ struct desc_struct *ldt;
17376 int size;
17377
17378 #ifdef CONFIG_X86_64
17379@@ -18,7 +18,19 @@ typedef struct {
17380 #endif
17381
17382 struct mutex lock;
17383- void __user *vdso;
17384+ unsigned long vdso;
17385+
17386+#ifdef CONFIG_X86_32
17387+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17388+ unsigned long user_cs_base;
17389+ unsigned long user_cs_limit;
17390+
17391+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17392+ cpumask_t cpu_user_cs_mask;
17393+#endif
17394+
17395+#endif
17396+#endif
17397 } mm_context_t;
17398
17399 #ifdef CONFIG_SMP
17400diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
17401index 166af2a..648c200 100644
17402--- a/arch/x86/include/asm/mmu_context.h
17403+++ b/arch/x86/include/asm/mmu_context.h
17404@@ -28,6 +28,20 @@ void destroy_context(struct mm_struct *mm);
17405
17406 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17407 {
17408+
17409+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17410+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
17411+ unsigned int i;
17412+ pgd_t *pgd;
17413+
17414+ pax_open_kernel();
17415+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
17416+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17417+ set_pgd_batched(pgd+i, native_make_pgd(0));
17418+ pax_close_kernel();
17419+ }
17420+#endif
17421+
17422 #ifdef CONFIG_SMP
17423 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17424 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17425@@ -38,16 +52,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17426 struct task_struct *tsk)
17427 {
17428 unsigned cpu = smp_processor_id();
17429+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17430+ int tlbstate = TLBSTATE_OK;
17431+#endif
17432
17433 if (likely(prev != next)) {
17434 #ifdef CONFIG_SMP
17435+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17436+ tlbstate = this_cpu_read(cpu_tlbstate.state);
17437+#endif
17438 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17439 this_cpu_write(cpu_tlbstate.active_mm, next);
17440 #endif
17441 cpumask_set_cpu(cpu, mm_cpumask(next));
17442
17443 /* Re-load page tables */
17444+#ifdef CONFIG_PAX_PER_CPU_PGD
17445+ pax_open_kernel();
17446+
17447+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17448+ if (static_cpu_has(X86_FEATURE_PCID))
17449+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17450+ else
17451+#endif
17452+
17453+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17454+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17455+ pax_close_kernel();
17456+ BUG_ON((__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL) != (read_cr3() & __PHYSICAL_MASK) && (__pa(get_cpu_pgd(cpu, user)) | PCID_USER) != (read_cr3() & __PHYSICAL_MASK));
17457+
17458+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17459+ if (static_cpu_has(X86_FEATURE_PCID)) {
17460+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17461+ u64 descriptor[2];
17462+ descriptor[0] = PCID_USER;
17463+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17464+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17465+ descriptor[0] = PCID_KERNEL;
17466+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17467+ }
17468+ } else {
17469+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17470+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17471+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17472+ else
17473+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17474+ }
17475+ } else
17476+#endif
17477+
17478+ load_cr3(get_cpu_pgd(cpu, kernel));
17479+#else
17480 load_cr3(next->pgd);
17481+#endif
17482 trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
17483
17484 /* Stop flush ipis for the previous mm */
17485@@ -56,9 +113,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17486 /* Load the LDT, if the LDT is different: */
17487 if (unlikely(prev->context.ldt != next->context.ldt))
17488 load_LDT_nolock(&next->context);
17489+
17490+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17491+ if (!(__supported_pte_mask & _PAGE_NX)) {
17492+ smp_mb__before_atomic();
17493+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17494+ smp_mb__after_atomic();
17495+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17496+ }
17497+#endif
17498+
17499+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17500+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17501+ prev->context.user_cs_limit != next->context.user_cs_limit))
17502+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17503+#ifdef CONFIG_SMP
17504+ else if (unlikely(tlbstate != TLBSTATE_OK))
17505+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17506+#endif
17507+#endif
17508+
17509 }
17510+ else {
17511+
17512+#ifdef CONFIG_PAX_PER_CPU_PGD
17513+ pax_open_kernel();
17514+
17515+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17516+ if (static_cpu_has(X86_FEATURE_PCID))
17517+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17518+ else
17519+#endif
17520+
17521+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17522+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17523+ pax_close_kernel();
17524+ BUG_ON((__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL) != (read_cr3() & __PHYSICAL_MASK) && (__pa(get_cpu_pgd(cpu, user)) | PCID_USER) != (read_cr3() & __PHYSICAL_MASK));
17525+
17526+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17527+ if (static_cpu_has(X86_FEATURE_PCID)) {
17528+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17529+ u64 descriptor[2];
17530+ descriptor[0] = PCID_USER;
17531+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17532+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17533+ descriptor[0] = PCID_KERNEL;
17534+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17535+ }
17536+ } else {
17537+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17538+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17539+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17540+ else
17541+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17542+ }
17543+ } else
17544+#endif
17545+
17546+ load_cr3(get_cpu_pgd(cpu, kernel));
17547+#endif
17548+
17549 #ifdef CONFIG_SMP
17550- else {
17551 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17552 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17553
17554@@ -75,12 +190,29 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17555 * tlb flush IPI delivery. We must reload CR3
17556 * to make sure to use no freed page tables.
17557 */
17558+
17559+#ifndef CONFIG_PAX_PER_CPU_PGD
17560 load_cr3(next->pgd);
17561 trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
17562+#endif
17563+
17564 load_LDT_nolock(&next->context);
17565+
17566+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17567+ if (!(__supported_pte_mask & _PAGE_NX))
17568+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17569+#endif
17570+
17571+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17572+#ifdef CONFIG_PAX_PAGEEXEC
17573+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17574+#endif
17575+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17576+#endif
17577+
17578 }
17579+#endif
17580 }
17581-#endif
17582 }
17583
17584 #define activate_mm(prev, next) \
17585diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17586index e3b7819..b257c64 100644
17587--- a/arch/x86/include/asm/module.h
17588+++ b/arch/x86/include/asm/module.h
17589@@ -5,6 +5,7 @@
17590
17591 #ifdef CONFIG_X86_64
17592 /* X86_64 does not define MODULE_PROC_FAMILY */
17593+#define MODULE_PROC_FAMILY ""
17594 #elif defined CONFIG_M486
17595 #define MODULE_PROC_FAMILY "486 "
17596 #elif defined CONFIG_M586
17597@@ -57,8 +58,20 @@
17598 #error unknown processor family
17599 #endif
17600
17601-#ifdef CONFIG_X86_32
17602-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17603+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17604+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17605+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17606+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17607+#else
17608+#define MODULE_PAX_KERNEXEC ""
17609 #endif
17610
17611+#ifdef CONFIG_PAX_MEMORY_UDEREF
17612+#define MODULE_PAX_UDEREF "UDEREF "
17613+#else
17614+#define MODULE_PAX_UDEREF ""
17615+#endif
17616+
17617+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17618+
17619 #endif /* _ASM_X86_MODULE_H */
17620diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17621index 5f2fc44..106caa6 100644
17622--- a/arch/x86/include/asm/nmi.h
17623+++ b/arch/x86/include/asm/nmi.h
17624@@ -36,26 +36,35 @@ enum {
17625
17626 typedef int (*nmi_handler_t)(unsigned int, struct pt_regs *);
17627
17628+struct nmiaction;
17629+
17630+struct nmiwork {
17631+ const struct nmiaction *action;
17632+ u64 max_duration;
17633+ struct irq_work irq_work;
17634+};
17635+
17636 struct nmiaction {
17637 struct list_head list;
17638 nmi_handler_t handler;
17639- u64 max_duration;
17640- struct irq_work irq_work;
17641 unsigned long flags;
17642 const char *name;
17643-};
17644+ struct nmiwork *work;
17645+} __do_const;
17646
17647 #define register_nmi_handler(t, fn, fg, n, init...) \
17648 ({ \
17649- static struct nmiaction init fn##_na = { \
17650+ static struct nmiwork fn##_nw; \
17651+ static const struct nmiaction init fn##_na = { \
17652 .handler = (fn), \
17653 .name = (n), \
17654 .flags = (fg), \
17655+ .work = &fn##_nw, \
17656 }; \
17657 __register_nmi_handler((t), &fn##_na); \
17658 })
17659
17660-int __register_nmi_handler(unsigned int, struct nmiaction *);
17661+int __register_nmi_handler(unsigned int, const struct nmiaction *);
17662
17663 void unregister_nmi_handler(unsigned int, const char *);
17664
17665diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17666index 802dde3..9183e68 100644
17667--- a/arch/x86/include/asm/page.h
17668+++ b/arch/x86/include/asm/page.h
17669@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17670 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17671
17672 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17673+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17674
17675 #define __boot_va(x) __va(x)
17676 #define __boot_pa(x) __pa(x)
17677@@ -60,11 +61,21 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17678 * virt_to_page(kaddr) returns a valid pointer if and only if
17679 * virt_addr_valid(kaddr) returns true.
17680 */
17681-#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17682 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
17683 extern bool __virt_addr_valid(unsigned long kaddr);
17684 #define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long) (kaddr))
17685
17686+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
17687+#define virt_to_page(kaddr) \
17688+ ({ \
17689+ const void *__kaddr = (const void *)(kaddr); \
17690+ BUG_ON(!virt_addr_valid(__kaddr)); \
17691+ pfn_to_page(__pa(__kaddr) >> PAGE_SHIFT); \
17692+ })
17693+#else
17694+#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17695+#endif
17696+
17697 #endif /* __ASSEMBLY__ */
17698
17699 #include <asm-generic/memory_model.h>
17700diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17701index f408caf..4a0455e 100644
17702--- a/arch/x86/include/asm/page_64.h
17703+++ b/arch/x86/include/asm/page_64.h
17704@@ -7,9 +7,9 @@
17705
17706 /* duplicated to the one in bootmem.h */
17707 extern unsigned long max_pfn;
17708-extern unsigned long phys_base;
17709+extern const unsigned long phys_base;
17710
17711-static inline unsigned long __phys_addr_nodebug(unsigned long x)
17712+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17713 {
17714 unsigned long y = x - __START_KERNEL_map;
17715
17716diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17717index cd6e1610..70f4418 100644
17718--- a/arch/x86/include/asm/paravirt.h
17719+++ b/arch/x86/include/asm/paravirt.h
17720@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17721 return (pmd_t) { ret };
17722 }
17723
17724-static inline pmdval_t pmd_val(pmd_t pmd)
17725+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17726 {
17727 pmdval_t ret;
17728
17729@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17730 val);
17731 }
17732
17733+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17734+{
17735+ pgdval_t val = native_pgd_val(pgd);
17736+
17737+ if (sizeof(pgdval_t) > sizeof(long))
17738+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17739+ val, (u64)val >> 32);
17740+ else
17741+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17742+ val);
17743+}
17744+
17745 static inline void pgd_clear(pgd_t *pgdp)
17746 {
17747 set_pgd(pgdp, __pgd(0));
17748@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17749 pv_mmu_ops.set_fixmap(idx, phys, flags);
17750 }
17751
17752+#ifdef CONFIG_PAX_KERNEXEC
17753+static inline unsigned long pax_open_kernel(void)
17754+{
17755+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17756+}
17757+
17758+static inline unsigned long pax_close_kernel(void)
17759+{
17760+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17761+}
17762+#else
17763+static inline unsigned long pax_open_kernel(void) { return 0; }
17764+static inline unsigned long pax_close_kernel(void) { return 0; }
17765+#endif
17766+
17767 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17768
17769 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17770@@ -906,7 +933,7 @@ extern void default_banner(void);
17771
17772 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17773 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17774-#define PARA_INDIRECT(addr) *%cs:addr
17775+#define PARA_INDIRECT(addr) *%ss:addr
17776 #endif
17777
17778 #define INTERRUPT_RETURN \
17779@@ -981,6 +1008,21 @@ extern void default_banner(void);
17780 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17781 CLBR_NONE, \
17782 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17783+
17784+#define GET_CR0_INTO_RDI \
17785+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17786+ mov %rax,%rdi
17787+
17788+#define SET_RDI_INTO_CR0 \
17789+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17790+
17791+#define GET_CR3_INTO_RDI \
17792+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17793+ mov %rax,%rdi
17794+
17795+#define SET_RDI_INTO_CR3 \
17796+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17797+
17798 #endif /* CONFIG_X86_32 */
17799
17800 #endif /* __ASSEMBLY__ */
17801diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17802index 7549b8b..f0edfda 100644
17803--- a/arch/x86/include/asm/paravirt_types.h
17804+++ b/arch/x86/include/asm/paravirt_types.h
17805@@ -84,7 +84,7 @@ struct pv_init_ops {
17806 */
17807 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17808 unsigned long addr, unsigned len);
17809-};
17810+} __no_const __no_randomize_layout;
17811
17812
17813 struct pv_lazy_ops {
17814@@ -92,13 +92,13 @@ struct pv_lazy_ops {
17815 void (*enter)(void);
17816 void (*leave)(void);
17817 void (*flush)(void);
17818-};
17819+} __no_randomize_layout;
17820
17821 struct pv_time_ops {
17822 unsigned long long (*sched_clock)(void);
17823 unsigned long long (*steal_clock)(int cpu);
17824 unsigned long (*get_tsc_khz)(void);
17825-};
17826+} __no_const __no_randomize_layout;
17827
17828 struct pv_cpu_ops {
17829 /* hooks for various privileged instructions */
17830@@ -192,7 +192,7 @@ struct pv_cpu_ops {
17831
17832 void (*start_context_switch)(struct task_struct *prev);
17833 void (*end_context_switch)(struct task_struct *next);
17834-};
17835+} __no_const __no_randomize_layout;
17836
17837 struct pv_irq_ops {
17838 /*
17839@@ -215,7 +215,7 @@ struct pv_irq_ops {
17840 #ifdef CONFIG_X86_64
17841 void (*adjust_exception_frame)(void);
17842 #endif
17843-};
17844+} __no_randomize_layout;
17845
17846 struct pv_apic_ops {
17847 #ifdef CONFIG_X86_LOCAL_APIC
17848@@ -223,7 +223,7 @@ struct pv_apic_ops {
17849 unsigned long start_eip,
17850 unsigned long start_esp);
17851 #endif
17852-};
17853+} __no_const __no_randomize_layout;
17854
17855 struct pv_mmu_ops {
17856 unsigned long (*read_cr2)(void);
17857@@ -313,6 +313,7 @@ struct pv_mmu_ops {
17858 struct paravirt_callee_save make_pud;
17859
17860 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17861+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17862 #endif /* PAGETABLE_LEVELS == 4 */
17863 #endif /* PAGETABLE_LEVELS >= 3 */
17864
17865@@ -324,7 +325,13 @@ struct pv_mmu_ops {
17866 an mfn. We can tell which is which from the index. */
17867 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17868 phys_addr_t phys, pgprot_t flags);
17869-};
17870+
17871+#ifdef CONFIG_PAX_KERNEXEC
17872+ unsigned long (*pax_open_kernel)(void);
17873+ unsigned long (*pax_close_kernel)(void);
17874+#endif
17875+
17876+} __no_randomize_layout;
17877
17878 struct arch_spinlock;
17879 #ifdef CONFIG_SMP
17880@@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17881 struct pv_lock_ops {
17882 struct paravirt_callee_save lock_spinning;
17883 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17884-};
17885+} __no_randomize_layout;
17886
17887 /* This contains all the paravirt structures: we get a convenient
17888 * number for each function using the offset which we use to indicate
17889- * what to patch. */
17890+ * what to patch.
17891+ * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17892+ */
17893+
17894 struct paravirt_patch_template {
17895 struct pv_init_ops pv_init_ops;
17896 struct pv_time_ops pv_time_ops;
17897@@ -349,7 +359,7 @@ struct paravirt_patch_template {
17898 struct pv_apic_ops pv_apic_ops;
17899 struct pv_mmu_ops pv_mmu_ops;
17900 struct pv_lock_ops pv_lock_ops;
17901-};
17902+} __no_randomize_layout;
17903
17904 extern struct pv_info pv_info;
17905 extern struct pv_init_ops pv_init_ops;
17906diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17907index c4412e9..90e88c5 100644
17908--- a/arch/x86/include/asm/pgalloc.h
17909+++ b/arch/x86/include/asm/pgalloc.h
17910@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17911 pmd_t *pmd, pte_t *pte)
17912 {
17913 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17914+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17915+}
17916+
17917+static inline void pmd_populate_user(struct mm_struct *mm,
17918+ pmd_t *pmd, pte_t *pte)
17919+{
17920+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17921 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17922 }
17923
17924@@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17925
17926 #ifdef CONFIG_X86_PAE
17927 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17928+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17929+{
17930+ pud_populate(mm, pudp, pmd);
17931+}
17932 #else /* !CONFIG_X86_PAE */
17933 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17934 {
17935 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17936 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17937 }
17938+
17939+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17940+{
17941+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17942+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17943+}
17944 #endif /* CONFIG_X86_PAE */
17945
17946 #if PAGETABLE_LEVELS > 3
17947@@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17948 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17949 }
17950
17951+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17952+{
17953+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17954+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17955+}
17956+
17957 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17958 {
17959 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17960diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17961index 206a87f..1623b06 100644
17962--- a/arch/x86/include/asm/pgtable-2level.h
17963+++ b/arch/x86/include/asm/pgtable-2level.h
17964@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17965
17966 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17967 {
17968+ pax_open_kernel();
17969 *pmdp = pmd;
17970+ pax_close_kernel();
17971 }
17972
17973 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17974diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17975index 81bb91b..9392125 100644
17976--- a/arch/x86/include/asm/pgtable-3level.h
17977+++ b/arch/x86/include/asm/pgtable-3level.h
17978@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17979
17980 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17981 {
17982+ pax_open_kernel();
17983 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17984+ pax_close_kernel();
17985 }
17986
17987 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17988 {
17989+ pax_open_kernel();
17990 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17991+ pax_close_kernel();
17992 }
17993
17994 /*
17995diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17996index aa97a07..5c53c32 100644
17997--- a/arch/x86/include/asm/pgtable.h
17998+++ b/arch/x86/include/asm/pgtable.h
17999@@ -46,6 +46,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18000
18001 #ifndef __PAGETABLE_PUD_FOLDED
18002 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
18003+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
18004 #define pgd_clear(pgd) native_pgd_clear(pgd)
18005 #endif
18006
18007@@ -83,12 +84,53 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18008
18009 #define arch_end_context_switch(prev) do {} while(0)
18010
18011+#define pax_open_kernel() native_pax_open_kernel()
18012+#define pax_close_kernel() native_pax_close_kernel()
18013 #endif /* CONFIG_PARAVIRT */
18014
18015+#define __HAVE_ARCH_PAX_OPEN_KERNEL
18016+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
18017+
18018+#ifdef CONFIG_PAX_KERNEXEC
18019+static inline unsigned long native_pax_open_kernel(void)
18020+{
18021+ unsigned long cr0;
18022+
18023+ preempt_disable();
18024+ barrier();
18025+ cr0 = read_cr0() ^ X86_CR0_WP;
18026+ BUG_ON(cr0 & X86_CR0_WP);
18027+ write_cr0(cr0);
18028+ barrier();
18029+ return cr0 ^ X86_CR0_WP;
18030+}
18031+
18032+static inline unsigned long native_pax_close_kernel(void)
18033+{
18034+ unsigned long cr0;
18035+
18036+ barrier();
18037+ cr0 = read_cr0() ^ X86_CR0_WP;
18038+ BUG_ON(!(cr0 & X86_CR0_WP));
18039+ write_cr0(cr0);
18040+ barrier();
18041+ preempt_enable_no_resched();
18042+ return cr0 ^ X86_CR0_WP;
18043+}
18044+#else
18045+static inline unsigned long native_pax_open_kernel(void) { return 0; }
18046+static inline unsigned long native_pax_close_kernel(void) { return 0; }
18047+#endif
18048+
18049 /*
18050 * The following only work if pte_present() is true.
18051 * Undefined behaviour if not..
18052 */
18053+static inline int pte_user(pte_t pte)
18054+{
18055+ return pte_val(pte) & _PAGE_USER;
18056+}
18057+
18058 static inline int pte_dirty(pte_t pte)
18059 {
18060 return pte_flags(pte) & _PAGE_DIRTY;
18061@@ -155,6 +197,11 @@ static inline unsigned long pud_pfn(pud_t pud)
18062 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
18063 }
18064
18065+static inline unsigned long pgd_pfn(pgd_t pgd)
18066+{
18067+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
18068+}
18069+
18070 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
18071
18072 static inline int pmd_large(pmd_t pte)
18073@@ -208,9 +255,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
18074 return pte_clear_flags(pte, _PAGE_RW);
18075 }
18076
18077+static inline pte_t pte_mkread(pte_t pte)
18078+{
18079+ return __pte(pte_val(pte) | _PAGE_USER);
18080+}
18081+
18082 static inline pte_t pte_mkexec(pte_t pte)
18083 {
18084- return pte_clear_flags(pte, _PAGE_NX);
18085+#ifdef CONFIG_X86_PAE
18086+ if (__supported_pte_mask & _PAGE_NX)
18087+ return pte_clear_flags(pte, _PAGE_NX);
18088+ else
18089+#endif
18090+ return pte_set_flags(pte, _PAGE_USER);
18091+}
18092+
18093+static inline pte_t pte_exprotect(pte_t pte)
18094+{
18095+#ifdef CONFIG_X86_PAE
18096+ if (__supported_pte_mask & _PAGE_NX)
18097+ return pte_set_flags(pte, _PAGE_NX);
18098+ else
18099+#endif
18100+ return pte_clear_flags(pte, _PAGE_USER);
18101 }
18102
18103 static inline pte_t pte_mkdirty(pte_t pte)
18104@@ -440,6 +507,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
18105 #endif
18106
18107 #ifndef __ASSEMBLY__
18108+
18109+#ifdef CONFIG_PAX_PER_CPU_PGD
18110+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
18111+enum cpu_pgd_type {kernel = 0, user = 1};
18112+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
18113+{
18114+ return cpu_pgd[cpu][type];
18115+}
18116+#endif
18117+
18118 #include <linux/mm_types.h>
18119 #include <linux/mmdebug.h>
18120 #include <linux/log2.h>
18121@@ -586,7 +663,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
18122 * Currently stuck as a macro due to indirect forward reference to
18123 * linux/mmzone.h's __section_mem_map_addr() definition:
18124 */
18125-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
18126+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
18127
18128 /* Find an entry in the second-level page table.. */
18129 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
18130@@ -626,7 +703,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
18131 * Currently stuck as a macro due to indirect forward reference to
18132 * linux/mmzone.h's __section_mem_map_addr() definition:
18133 */
18134-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
18135+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
18136
18137 /* to find an entry in a page-table-directory. */
18138 static inline unsigned long pud_index(unsigned long address)
18139@@ -641,7 +718,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
18140
18141 static inline int pgd_bad(pgd_t pgd)
18142 {
18143- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
18144+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
18145 }
18146
18147 static inline int pgd_none(pgd_t pgd)
18148@@ -664,7 +741,12 @@ static inline int pgd_none(pgd_t pgd)
18149 * pgd_offset() returns a (pgd_t *)
18150 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
18151 */
18152-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
18153+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
18154+
18155+#ifdef CONFIG_PAX_PER_CPU_PGD
18156+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
18157+#endif
18158+
18159 /*
18160 * a shortcut which implies the use of the kernel's pgd, instead
18161 * of a process's
18162@@ -675,6 +757,23 @@ static inline int pgd_none(pgd_t pgd)
18163 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
18164 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
18165
18166+#ifdef CONFIG_X86_32
18167+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
18168+#else
18169+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
18170+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
18171+
18172+#ifdef CONFIG_PAX_MEMORY_UDEREF
18173+#ifdef __ASSEMBLY__
18174+#define pax_user_shadow_base pax_user_shadow_base(%rip)
18175+#else
18176+extern unsigned long pax_user_shadow_base;
18177+extern pgdval_t clone_pgd_mask;
18178+#endif
18179+#endif
18180+
18181+#endif
18182+
18183 #ifndef __ASSEMBLY__
18184
18185 extern int direct_gbpages;
18186@@ -841,11 +940,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
18187 * dst and src can be on the same page, but the range must not overlap,
18188 * and must not cross a page boundary.
18189 */
18190-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
18191+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
18192 {
18193- memcpy(dst, src, count * sizeof(pgd_t));
18194+ pax_open_kernel();
18195+ while (count--)
18196+ *dst++ = *src++;
18197+ pax_close_kernel();
18198 }
18199
18200+#ifdef CONFIG_PAX_PER_CPU_PGD
18201+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
18202+#endif
18203+
18204+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18205+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
18206+#else
18207+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
18208+#endif
18209+
18210 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
18211 static inline int page_level_shift(enum pg_level level)
18212 {
18213diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
18214index b6c0b40..3535d47 100644
18215--- a/arch/x86/include/asm/pgtable_32.h
18216+++ b/arch/x86/include/asm/pgtable_32.h
18217@@ -25,9 +25,6 @@
18218 struct mm_struct;
18219 struct vm_area_struct;
18220
18221-extern pgd_t swapper_pg_dir[1024];
18222-extern pgd_t initial_page_table[1024];
18223-
18224 static inline void pgtable_cache_init(void) { }
18225 static inline void check_pgt_cache(void) { }
18226 void paging_init(void);
18227@@ -45,6 +42,12 @@ void paging_init(void);
18228 # include <asm/pgtable-2level.h>
18229 #endif
18230
18231+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
18232+extern pgd_t initial_page_table[PTRS_PER_PGD];
18233+#ifdef CONFIG_X86_PAE
18234+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
18235+#endif
18236+
18237 #if defined(CONFIG_HIGHPTE)
18238 #define pte_offset_map(dir, address) \
18239 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
18240@@ -59,12 +62,17 @@ void paging_init(void);
18241 /* Clear a kernel PTE and flush it from the TLB */
18242 #define kpte_clear_flush(ptep, vaddr) \
18243 do { \
18244+ pax_open_kernel(); \
18245 pte_clear(&init_mm, (vaddr), (ptep)); \
18246+ pax_close_kernel(); \
18247 __flush_tlb_one((vaddr)); \
18248 } while (0)
18249
18250 #endif /* !__ASSEMBLY__ */
18251
18252+#define HAVE_ARCH_UNMAPPED_AREA
18253+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
18254+
18255 /*
18256 * kern_addr_valid() is (1) for FLATMEM and (0) for
18257 * SPARSEMEM and DISCONTIGMEM
18258diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
18259index ed5903b..c7fe163 100644
18260--- a/arch/x86/include/asm/pgtable_32_types.h
18261+++ b/arch/x86/include/asm/pgtable_32_types.h
18262@@ -8,7 +8,7 @@
18263 */
18264 #ifdef CONFIG_X86_PAE
18265 # include <asm/pgtable-3level_types.h>
18266-# define PMD_SIZE (1UL << PMD_SHIFT)
18267+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
18268 # define PMD_MASK (~(PMD_SIZE - 1))
18269 #else
18270 # include <asm/pgtable-2level_types.h>
18271@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
18272 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
18273 #endif
18274
18275+#ifdef CONFIG_PAX_KERNEXEC
18276+#ifndef __ASSEMBLY__
18277+extern unsigned char MODULES_EXEC_VADDR[];
18278+extern unsigned char MODULES_EXEC_END[];
18279+#endif
18280+#include <asm/boot.h>
18281+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
18282+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
18283+#else
18284+#define ktla_ktva(addr) (addr)
18285+#define ktva_ktla(addr) (addr)
18286+#endif
18287+
18288 #define MODULES_VADDR VMALLOC_START
18289 #define MODULES_END VMALLOC_END
18290 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
18291diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
18292index 4572b2f..4430113 100644
18293--- a/arch/x86/include/asm/pgtable_64.h
18294+++ b/arch/x86/include/asm/pgtable_64.h
18295@@ -16,11 +16,16 @@
18296
18297 extern pud_t level3_kernel_pgt[512];
18298 extern pud_t level3_ident_pgt[512];
18299+extern pud_t level3_vmalloc_start_pgt[512];
18300+extern pud_t level3_vmalloc_end_pgt[512];
18301+extern pud_t level3_vmemmap_pgt[512];
18302+extern pud_t level2_vmemmap_pgt[512];
18303 extern pmd_t level2_kernel_pgt[512];
18304 extern pmd_t level2_fixmap_pgt[512];
18305-extern pmd_t level2_ident_pgt[512];
18306+extern pmd_t level2_ident_pgt[512*2];
18307 extern pte_t level1_fixmap_pgt[512];
18308-extern pgd_t init_level4_pgt[];
18309+extern pte_t level1_vsyscall_pgt[512];
18310+extern pgd_t init_level4_pgt[512];
18311
18312 #define swapper_pg_dir init_level4_pgt
18313
18314@@ -62,7 +67,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18315
18316 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18317 {
18318+ pax_open_kernel();
18319 *pmdp = pmd;
18320+ pax_close_kernel();
18321 }
18322
18323 static inline void native_pmd_clear(pmd_t *pmd)
18324@@ -98,7 +105,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
18325
18326 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18327 {
18328+ pax_open_kernel();
18329 *pudp = pud;
18330+ pax_close_kernel();
18331 }
18332
18333 static inline void native_pud_clear(pud_t *pud)
18334@@ -108,6 +117,13 @@ static inline void native_pud_clear(pud_t *pud)
18335
18336 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
18337 {
18338+ pax_open_kernel();
18339+ *pgdp = pgd;
18340+ pax_close_kernel();
18341+}
18342+
18343+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18344+{
18345 *pgdp = pgd;
18346 }
18347
18348diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
18349index 7166e25..baaa6fe 100644
18350--- a/arch/x86/include/asm/pgtable_64_types.h
18351+++ b/arch/x86/include/asm/pgtable_64_types.h
18352@@ -61,9 +61,14 @@ typedef struct { pteval_t pte; } pte_t;
18353 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
18354 #define MODULES_END _AC(0xffffffffff000000, UL)
18355 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
18356+#define MODULES_EXEC_VADDR MODULES_VADDR
18357+#define MODULES_EXEC_END MODULES_END
18358 #define ESPFIX_PGD_ENTRY _AC(-2, UL)
18359 #define ESPFIX_BASE_ADDR (ESPFIX_PGD_ENTRY << PGDIR_SHIFT)
18360
18361+#define ktla_ktva(addr) (addr)
18362+#define ktva_ktla(addr) (addr)
18363+
18364 #define EARLY_DYNAMIC_PAGE_TABLES 64
18365
18366 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
18367diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
18368index 0778964..0e94758 100644
18369--- a/arch/x86/include/asm/pgtable_types.h
18370+++ b/arch/x86/include/asm/pgtable_types.h
18371@@ -110,8 +110,10 @@
18372
18373 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
18374 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
18375-#else
18376+#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
18377 #define _PAGE_NX (_AT(pteval_t, 0))
18378+#else
18379+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
18380 #endif
18381
18382 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
18383@@ -150,6 +152,9 @@
18384 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
18385 _PAGE_ACCESSED)
18386
18387+#define PAGE_READONLY_NOEXEC PAGE_READONLY
18388+#define PAGE_SHARED_NOEXEC PAGE_SHARED
18389+
18390 #define __PAGE_KERNEL_EXEC \
18391 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
18392 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
18393@@ -160,7 +165,7 @@
18394 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
18395 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
18396 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
18397-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
18398+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
18399 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
18400 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
18401 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
18402@@ -217,7 +222,7 @@
18403 #ifdef CONFIG_X86_64
18404 #define __PAGE_KERNEL_IDENT_LARGE_EXEC __PAGE_KERNEL_LARGE_EXEC
18405 #else
18406-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
18407+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18408 #define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18409 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
18410 #endif
18411@@ -256,7 +261,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
18412 {
18413 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
18414 }
18415+#endif
18416
18417+#if PAGETABLE_LEVELS == 3
18418+#include <asm-generic/pgtable-nopud.h>
18419+#endif
18420+
18421+#if PAGETABLE_LEVELS == 2
18422+#include <asm-generic/pgtable-nopmd.h>
18423+#endif
18424+
18425+#ifndef __ASSEMBLY__
18426 #if PAGETABLE_LEVELS > 3
18427 typedef struct { pudval_t pud; } pud_t;
18428
18429@@ -270,8 +285,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18430 return pud.pud;
18431 }
18432 #else
18433-#include <asm-generic/pgtable-nopud.h>
18434-
18435 static inline pudval_t native_pud_val(pud_t pud)
18436 {
18437 return native_pgd_val(pud.pgd);
18438@@ -291,8 +304,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18439 return pmd.pmd;
18440 }
18441 #else
18442-#include <asm-generic/pgtable-nopmd.h>
18443-
18444 static inline pmdval_t native_pmd_val(pmd_t pmd)
18445 {
18446 return native_pgd_val(pmd.pud.pgd);
18447@@ -346,7 +357,6 @@ typedef struct page *pgtable_t;
18448
18449 extern pteval_t __supported_pte_mask;
18450 extern void set_nx(void);
18451-extern int nx_enabled;
18452
18453 #define pgprot_writecombine pgprot_writecombine
18454 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18455diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18456index 4008734..48f0d81 100644
18457--- a/arch/x86/include/asm/preempt.h
18458+++ b/arch/x86/include/asm/preempt.h
18459@@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
18460 */
18461 static __always_inline bool __preempt_count_dec_and_test(void)
18462 {
18463- GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18464+ GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18465 }
18466
18467 /*
18468diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18469index eb71ec7..f06532a 100644
18470--- a/arch/x86/include/asm/processor.h
18471+++ b/arch/x86/include/asm/processor.h
18472@@ -127,7 +127,7 @@ struct cpuinfo_x86 {
18473 /* Index into per_cpu list: */
18474 u16 cpu_index;
18475 u32 microcode;
18476-} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18477+} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18478
18479 #define X86_VENDOR_INTEL 0
18480 #define X86_VENDOR_CYRIX 1
18481@@ -198,9 +198,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18482 : "memory");
18483 }
18484
18485+/* invpcid (%rdx),%rax */
18486+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18487+
18488+#define INVPCID_SINGLE_ADDRESS 0UL
18489+#define INVPCID_SINGLE_CONTEXT 1UL
18490+#define INVPCID_ALL_GLOBAL 2UL
18491+#define INVPCID_ALL_NONGLOBAL 3UL
18492+
18493+#define PCID_KERNEL 0UL
18494+#define PCID_USER 1UL
18495+#define PCID_NOFLUSH (1UL << 63)
18496+
18497 static inline void load_cr3(pgd_t *pgdir)
18498 {
18499- write_cr3(__pa(pgdir));
18500+ write_cr3(__pa(pgdir) | PCID_KERNEL);
18501 }
18502
18503 #ifdef CONFIG_X86_32
18504@@ -282,7 +294,7 @@ struct tss_struct {
18505
18506 } ____cacheline_aligned;
18507
18508-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18509+extern struct tss_struct init_tss[NR_CPUS];
18510
18511 /*
18512 * Save the original ist values for checking stack pointers during debugging
18513@@ -478,6 +490,7 @@ struct thread_struct {
18514 unsigned short ds;
18515 unsigned short fsindex;
18516 unsigned short gsindex;
18517+ unsigned short ss;
18518 #endif
18519 #ifdef CONFIG_X86_32
18520 unsigned long ip;
18521@@ -587,29 +600,8 @@ static inline void load_sp0(struct tss_struct *tss,
18522 extern unsigned long mmu_cr4_features;
18523 extern u32 *trampoline_cr4_features;
18524
18525-static inline void set_in_cr4(unsigned long mask)
18526-{
18527- unsigned long cr4;
18528-
18529- mmu_cr4_features |= mask;
18530- if (trampoline_cr4_features)
18531- *trampoline_cr4_features = mmu_cr4_features;
18532- cr4 = read_cr4();
18533- cr4 |= mask;
18534- write_cr4(cr4);
18535-}
18536-
18537-static inline void clear_in_cr4(unsigned long mask)
18538-{
18539- unsigned long cr4;
18540-
18541- mmu_cr4_features &= ~mask;
18542- if (trampoline_cr4_features)
18543- *trampoline_cr4_features = mmu_cr4_features;
18544- cr4 = read_cr4();
18545- cr4 &= ~mask;
18546- write_cr4(cr4);
18547-}
18548+extern void set_in_cr4(unsigned long mask);
18549+extern void clear_in_cr4(unsigned long mask);
18550
18551 typedef struct {
18552 unsigned long seg;
18553@@ -837,11 +829,18 @@ static inline void spin_lock_prefetch(const void *x)
18554 */
18555 #define TASK_SIZE PAGE_OFFSET
18556 #define TASK_SIZE_MAX TASK_SIZE
18557+
18558+#ifdef CONFIG_PAX_SEGMEXEC
18559+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18560+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18561+#else
18562 #define STACK_TOP TASK_SIZE
18563-#define STACK_TOP_MAX STACK_TOP
18564+#endif
18565+
18566+#define STACK_TOP_MAX TASK_SIZE
18567
18568 #define INIT_THREAD { \
18569- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18570+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18571 .vm86_info = NULL, \
18572 .sysenter_cs = __KERNEL_CS, \
18573 .io_bitmap_ptr = NULL, \
18574@@ -855,7 +854,7 @@ static inline void spin_lock_prefetch(const void *x)
18575 */
18576 #define INIT_TSS { \
18577 .x86_tss = { \
18578- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18579+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18580 .ss0 = __KERNEL_DS, \
18581 .ss1 = __KERNEL_CS, \
18582 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18583@@ -866,11 +865,7 @@ static inline void spin_lock_prefetch(const void *x)
18584 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18585
18586 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18587-#define KSTK_TOP(info) \
18588-({ \
18589- unsigned long *__ptr = (unsigned long *)(info); \
18590- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18591-})
18592+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18593
18594 /*
18595 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18596@@ -885,7 +880,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18597 #define task_pt_regs(task) \
18598 ({ \
18599 struct pt_regs *__regs__; \
18600- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18601+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18602 __regs__ - 1; \
18603 })
18604
18605@@ -895,13 +890,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18606 /*
18607 * User space process size. 47bits minus one guard page.
18608 */
18609-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18610+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18611
18612 /* This decides where the kernel will search for a free chunk of vm
18613 * space during mmap's.
18614 */
18615 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18616- 0xc0000000 : 0xFFFFe000)
18617+ 0xc0000000 : 0xFFFFf000)
18618
18619 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18620 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18621@@ -912,11 +907,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18622 #define STACK_TOP_MAX TASK_SIZE_MAX
18623
18624 #define INIT_THREAD { \
18625- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18626+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18627 }
18628
18629 #define INIT_TSS { \
18630- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18631+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18632 }
18633
18634 /*
18635@@ -944,6 +939,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18636 */
18637 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18638
18639+#ifdef CONFIG_PAX_SEGMEXEC
18640+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18641+#endif
18642+
18643 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18644
18645 /* Get/set a process' ability to use the timestamp counter instruction */
18646@@ -970,7 +969,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18647 return 0;
18648 }
18649
18650-extern unsigned long arch_align_stack(unsigned long sp);
18651+#define arch_align_stack(x) ((x) & ~0xfUL)
18652 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18653
18654 void default_idle(void);
18655@@ -980,6 +979,6 @@ bool xen_set_default_idle(void);
18656 #define xen_set_default_idle 0
18657 #endif
18658
18659-void stop_this_cpu(void *dummy);
18660+void stop_this_cpu(void *dummy) __noreturn;
18661 void df_debug(struct pt_regs *regs, long error_code);
18662 #endif /* _ASM_X86_PROCESSOR_H */
18663diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18664index 86fc2bb..bd5049a 100644
18665--- a/arch/x86/include/asm/ptrace.h
18666+++ b/arch/x86/include/asm/ptrace.h
18667@@ -89,28 +89,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18668 }
18669
18670 /*
18671- * user_mode_vm(regs) determines whether a register set came from user mode.
18672+ * user_mode(regs) determines whether a register set came from user mode.
18673 * This is true if V8086 mode was enabled OR if the register set was from
18674 * protected mode with RPL-3 CS value. This tricky test checks that with
18675 * one comparison. Many places in the kernel can bypass this full check
18676- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18677+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18678+ * be used.
18679 */
18680-static inline int user_mode(struct pt_regs *regs)
18681+static inline int user_mode_novm(struct pt_regs *regs)
18682 {
18683 #ifdef CONFIG_X86_32
18684 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18685 #else
18686- return !!(regs->cs & 3);
18687+ return !!(regs->cs & SEGMENT_RPL_MASK);
18688 #endif
18689 }
18690
18691-static inline int user_mode_vm(struct pt_regs *regs)
18692+static inline int user_mode(struct pt_regs *regs)
18693 {
18694 #ifdef CONFIG_X86_32
18695 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18696 USER_RPL;
18697 #else
18698- return user_mode(regs);
18699+ return user_mode_novm(regs);
18700 #endif
18701 }
18702
18703@@ -126,15 +127,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18704 #ifdef CONFIG_X86_64
18705 static inline bool user_64bit_mode(struct pt_regs *regs)
18706 {
18707+ unsigned long cs = regs->cs & 0xffff;
18708 #ifndef CONFIG_PARAVIRT
18709 /*
18710 * On non-paravirt systems, this is the only long mode CPL 3
18711 * selector. We do not allow long mode selectors in the LDT.
18712 */
18713- return regs->cs == __USER_CS;
18714+ return cs == __USER_CS;
18715 #else
18716 /* Headers are too twisted for this to go in paravirt.h. */
18717- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18718+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18719 #endif
18720 }
18721
18722@@ -185,9 +187,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18723 * Traps from the kernel do not save sp and ss.
18724 * Use the helper function to retrieve sp.
18725 */
18726- if (offset == offsetof(struct pt_regs, sp) &&
18727- regs->cs == __KERNEL_CS)
18728- return kernel_stack_pointer(regs);
18729+ if (offset == offsetof(struct pt_regs, sp)) {
18730+ unsigned long cs = regs->cs & 0xffff;
18731+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18732+ return kernel_stack_pointer(regs);
18733+ }
18734 #endif
18735 return *(unsigned long *)((unsigned long)regs + offset);
18736 }
18737diff --git a/arch/x86/include/asm/qrwlock.h b/arch/x86/include/asm/qrwlock.h
18738index ae0e241..e80b10b 100644
18739--- a/arch/x86/include/asm/qrwlock.h
18740+++ b/arch/x86/include/asm/qrwlock.h
18741@@ -7,8 +7,8 @@
18742 #define queue_write_unlock queue_write_unlock
18743 static inline void queue_write_unlock(struct qrwlock *lock)
18744 {
18745- barrier();
18746- ACCESS_ONCE(*(u8 *)&lock->cnts) = 0;
18747+ barrier();
18748+ ACCESS_ONCE_RW(*(u8 *)&lock->cnts) = 0;
18749 }
18750 #endif
18751
18752diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18753index 9c6b890..5305f53 100644
18754--- a/arch/x86/include/asm/realmode.h
18755+++ b/arch/x86/include/asm/realmode.h
18756@@ -22,16 +22,14 @@ struct real_mode_header {
18757 #endif
18758 /* APM/BIOS reboot */
18759 u32 machine_real_restart_asm;
18760-#ifdef CONFIG_X86_64
18761 u32 machine_real_restart_seg;
18762-#endif
18763 };
18764
18765 /* This must match data at trampoline_32/64.S */
18766 struct trampoline_header {
18767 #ifdef CONFIG_X86_32
18768 u32 start;
18769- u16 gdt_pad;
18770+ u16 boot_cs;
18771 u16 gdt_limit;
18772 u32 gdt_base;
18773 #else
18774diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18775index a82c4f1..ac45053 100644
18776--- a/arch/x86/include/asm/reboot.h
18777+++ b/arch/x86/include/asm/reboot.h
18778@@ -6,13 +6,13 @@
18779 struct pt_regs;
18780
18781 struct machine_ops {
18782- void (*restart)(char *cmd);
18783- void (*halt)(void);
18784- void (*power_off)(void);
18785+ void (* __noreturn restart)(char *cmd);
18786+ void (* __noreturn halt)(void);
18787+ void (* __noreturn power_off)(void);
18788 void (*shutdown)(void);
18789 void (*crash_shutdown)(struct pt_regs *);
18790- void (*emergency_restart)(void);
18791-};
18792+ void (* __noreturn emergency_restart)(void);
18793+} __no_const;
18794
18795 extern struct machine_ops machine_ops;
18796
18797diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18798index 8f7866a..e442f20 100644
18799--- a/arch/x86/include/asm/rmwcc.h
18800+++ b/arch/x86/include/asm/rmwcc.h
18801@@ -3,7 +3,34 @@
18802
18803 #ifdef CC_HAVE_ASM_GOTO
18804
18805-#define __GEN_RMWcc(fullop, var, cc, ...) \
18806+#ifdef CONFIG_PAX_REFCOUNT
18807+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18808+do { \
18809+ asm_volatile_goto (fullop \
18810+ ";jno 0f\n" \
18811+ fullantiop \
18812+ ";int $4\n0:\n" \
18813+ _ASM_EXTABLE(0b, 0b) \
18814+ ";j" cc " %l[cc_label]" \
18815+ : : "m" (var), ## __VA_ARGS__ \
18816+ : "memory" : cc_label); \
18817+ return 0; \
18818+cc_label: \
18819+ return 1; \
18820+} while (0)
18821+#else
18822+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18823+do { \
18824+ asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18825+ : : "m" (var), ## __VA_ARGS__ \
18826+ : "memory" : cc_label); \
18827+ return 0; \
18828+cc_label: \
18829+ return 1; \
18830+} while (0)
18831+#endif
18832+
18833+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18834 do { \
18835 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18836 : : "m" (var), ## __VA_ARGS__ \
18837@@ -13,15 +40,46 @@ cc_label: \
18838 return 1; \
18839 } while (0)
18840
18841-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18842- __GEN_RMWcc(op " " arg0, var, cc)
18843+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18844+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18845
18846-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18847- __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18848+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18849+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18850+
18851+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18852+ __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18853+
18854+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18855+ __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18856
18857 #else /* !CC_HAVE_ASM_GOTO */
18858
18859-#define __GEN_RMWcc(fullop, var, cc, ...) \
18860+#ifdef CONFIG_PAX_REFCOUNT
18861+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18862+do { \
18863+ char c; \
18864+ asm volatile (fullop \
18865+ ";jno 0f\n" \
18866+ fullantiop \
18867+ ";int $4\n0:\n" \
18868+ _ASM_EXTABLE(0b, 0b) \
18869+ "; set" cc " %1" \
18870+ : "+m" (var), "=qm" (c) \
18871+ : __VA_ARGS__ : "memory"); \
18872+ return c != 0; \
18873+} while (0)
18874+#else
18875+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18876+do { \
18877+ char c; \
18878+ asm volatile (fullop "; set" cc " %1" \
18879+ : "+m" (var), "=qm" (c) \
18880+ : __VA_ARGS__ : "memory"); \
18881+ return c != 0; \
18882+} while (0)
18883+#endif
18884+
18885+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18886 do { \
18887 char c; \
18888 asm volatile (fullop "; set" cc " %1" \
18889@@ -30,11 +88,17 @@ do { \
18890 return c != 0; \
18891 } while (0)
18892
18893-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18894- __GEN_RMWcc(op " " arg0, var, cc)
18895+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18896+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18897+
18898+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18899+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18900+
18901+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18902+ __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18903
18904-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18905- __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18906+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18907+ __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18908
18909 #endif /* CC_HAVE_ASM_GOTO */
18910
18911diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18912index cad82c9..2e5c5c1 100644
18913--- a/arch/x86/include/asm/rwsem.h
18914+++ b/arch/x86/include/asm/rwsem.h
18915@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18916 {
18917 asm volatile("# beginning down_read\n\t"
18918 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18919+
18920+#ifdef CONFIG_PAX_REFCOUNT
18921+ "jno 0f\n"
18922+ LOCK_PREFIX _ASM_DEC "(%1)\n"
18923+ "int $4\n0:\n"
18924+ _ASM_EXTABLE(0b, 0b)
18925+#endif
18926+
18927 /* adds 0x00000001 */
18928 " jns 1f\n"
18929 " call call_rwsem_down_read_failed\n"
18930@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18931 "1:\n\t"
18932 " mov %1,%2\n\t"
18933 " add %3,%2\n\t"
18934+
18935+#ifdef CONFIG_PAX_REFCOUNT
18936+ "jno 0f\n"
18937+ "sub %3,%2\n"
18938+ "int $4\n0:\n"
18939+ _ASM_EXTABLE(0b, 0b)
18940+#endif
18941+
18942 " jle 2f\n\t"
18943 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18944 " jnz 1b\n\t"
18945@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18946 long tmp;
18947 asm volatile("# beginning down_write\n\t"
18948 LOCK_PREFIX " xadd %1,(%2)\n\t"
18949+
18950+#ifdef CONFIG_PAX_REFCOUNT
18951+ "jno 0f\n"
18952+ "mov %1,(%2)\n"
18953+ "int $4\n0:\n"
18954+ _ASM_EXTABLE(0b, 0b)
18955+#endif
18956+
18957 /* adds 0xffff0001, returns the old value */
18958 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18959 /* was the active mask 0 before? */
18960@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18961 long tmp;
18962 asm volatile("# beginning __up_read\n\t"
18963 LOCK_PREFIX " xadd %1,(%2)\n\t"
18964+
18965+#ifdef CONFIG_PAX_REFCOUNT
18966+ "jno 0f\n"
18967+ "mov %1,(%2)\n"
18968+ "int $4\n0:\n"
18969+ _ASM_EXTABLE(0b, 0b)
18970+#endif
18971+
18972 /* subtracts 1, returns the old value */
18973 " jns 1f\n\t"
18974 " call call_rwsem_wake\n" /* expects old value in %edx */
18975@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18976 long tmp;
18977 asm volatile("# beginning __up_write\n\t"
18978 LOCK_PREFIX " xadd %1,(%2)\n\t"
18979+
18980+#ifdef CONFIG_PAX_REFCOUNT
18981+ "jno 0f\n"
18982+ "mov %1,(%2)\n"
18983+ "int $4\n0:\n"
18984+ _ASM_EXTABLE(0b, 0b)
18985+#endif
18986+
18987 /* subtracts 0xffff0001, returns the old value */
18988 " jns 1f\n\t"
18989 " call call_rwsem_wake\n" /* expects old value in %edx */
18990@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18991 {
18992 asm volatile("# beginning __downgrade_write\n\t"
18993 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18994+
18995+#ifdef CONFIG_PAX_REFCOUNT
18996+ "jno 0f\n"
18997+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18998+ "int $4\n0:\n"
18999+ _ASM_EXTABLE(0b, 0b)
19000+#endif
19001+
19002 /*
19003 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
19004 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
19005@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19006 */
19007 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19008 {
19009- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
19010+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
19011+
19012+#ifdef CONFIG_PAX_REFCOUNT
19013+ "jno 0f\n"
19014+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
19015+ "int $4\n0:\n"
19016+ _ASM_EXTABLE(0b, 0b)
19017+#endif
19018+
19019 : "+m" (sem->count)
19020 : "er" (delta));
19021 }
19022@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19023 */
19024 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
19025 {
19026- return delta + xadd(&sem->count, delta);
19027+ return delta + xadd_check_overflow(&sem->count, delta);
19028 }
19029
19030 #endif /* __KERNEL__ */
19031diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
19032index 6f1c3a8..7744f19 100644
19033--- a/arch/x86/include/asm/segment.h
19034+++ b/arch/x86/include/asm/segment.h
19035@@ -64,10 +64,15 @@
19036 * 26 - ESPFIX small SS
19037 * 27 - per-cpu [ offset to per-cpu data area ]
19038 * 28 - stack_canary-20 [ for stack protector ]
19039- * 29 - unused
19040- * 30 - unused
19041+ * 29 - PCI BIOS CS
19042+ * 30 - PCI BIOS DS
19043 * 31 - TSS for double fault handler
19044 */
19045+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
19046+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
19047+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
19048+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
19049+
19050 #define GDT_ENTRY_TLS_MIN 6
19051 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
19052
19053@@ -79,6 +84,8 @@
19054
19055 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
19056
19057+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
19058+
19059 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
19060
19061 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
19062@@ -104,6 +111,12 @@
19063 #define __KERNEL_STACK_CANARY 0
19064 #endif
19065
19066+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
19067+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
19068+
19069+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
19070+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
19071+
19072 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
19073
19074 /*
19075@@ -141,7 +154,7 @@
19076 */
19077
19078 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
19079-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
19080+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
19081
19082
19083 #else
19084@@ -165,6 +178,8 @@
19085 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
19086 #define __USER32_DS __USER_DS
19087
19088+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
19089+
19090 #define GDT_ENTRY_TSS 8 /* needs two entries */
19091 #define GDT_ENTRY_LDT 10 /* needs two entries */
19092 #define GDT_ENTRY_TLS_MIN 12
19093@@ -173,6 +188,8 @@
19094 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
19095 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
19096
19097+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
19098+
19099 /* TLS indexes for 64bit - hardcoded in arch_prctl */
19100 #define FS_TLS 0
19101 #define GS_TLS 1
19102@@ -180,12 +197,14 @@
19103 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
19104 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
19105
19106-#define GDT_ENTRIES 16
19107+#define GDT_ENTRIES 17
19108
19109 #endif
19110
19111 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
19112+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
19113 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
19114+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
19115 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
19116 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
19117 #ifndef CONFIG_PARAVIRT
19118@@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
19119 {
19120 unsigned long __limit;
19121 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
19122- return __limit + 1;
19123+ return __limit;
19124 }
19125
19126 #endif /* !__ASSEMBLY__ */
19127diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
19128index 8d3120f..352b440 100644
19129--- a/arch/x86/include/asm/smap.h
19130+++ b/arch/x86/include/asm/smap.h
19131@@ -25,11 +25,40 @@
19132
19133 #include <asm/alternative-asm.h>
19134
19135+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19136+#define ASM_PAX_OPEN_USERLAND \
19137+ 661: jmp 663f; \
19138+ .pushsection .altinstr_replacement, "a" ; \
19139+ 662: pushq %rax; nop; \
19140+ .popsection ; \
19141+ .pushsection .altinstructions, "a" ; \
19142+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19143+ .popsection ; \
19144+ call __pax_open_userland; \
19145+ popq %rax; \
19146+ 663:
19147+
19148+#define ASM_PAX_CLOSE_USERLAND \
19149+ 661: jmp 663f; \
19150+ .pushsection .altinstr_replacement, "a" ; \
19151+ 662: pushq %rax; nop; \
19152+ .popsection; \
19153+ .pushsection .altinstructions, "a" ; \
19154+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19155+ .popsection; \
19156+ call __pax_close_userland; \
19157+ popq %rax; \
19158+ 663:
19159+#else
19160+#define ASM_PAX_OPEN_USERLAND
19161+#define ASM_PAX_CLOSE_USERLAND
19162+#endif
19163+
19164 #ifdef CONFIG_X86_SMAP
19165
19166 #define ASM_CLAC \
19167 661: ASM_NOP3 ; \
19168- .pushsection .altinstr_replacement, "ax" ; \
19169+ .pushsection .altinstr_replacement, "a" ; \
19170 662: __ASM_CLAC ; \
19171 .popsection ; \
19172 .pushsection .altinstructions, "a" ; \
19173@@ -38,7 +67,7 @@
19174
19175 #define ASM_STAC \
19176 661: ASM_NOP3 ; \
19177- .pushsection .altinstr_replacement, "ax" ; \
19178+ .pushsection .altinstr_replacement, "a" ; \
19179 662: __ASM_STAC ; \
19180 .popsection ; \
19181 .pushsection .altinstructions, "a" ; \
19182@@ -56,6 +85,37 @@
19183
19184 #include <asm/alternative.h>
19185
19186+#define __HAVE_ARCH_PAX_OPEN_USERLAND
19187+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
19188+
19189+extern void __pax_open_userland(void);
19190+static __always_inline unsigned long pax_open_userland(void)
19191+{
19192+
19193+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19194+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
19195+ :
19196+ : [open] "i" (__pax_open_userland)
19197+ : "memory", "rax");
19198+#endif
19199+
19200+ return 0;
19201+}
19202+
19203+extern void __pax_close_userland(void);
19204+static __always_inline unsigned long pax_close_userland(void)
19205+{
19206+
19207+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19208+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
19209+ :
19210+ : [close] "i" (__pax_close_userland)
19211+ : "memory", "rax");
19212+#endif
19213+
19214+ return 0;
19215+}
19216+
19217 #ifdef CONFIG_X86_SMAP
19218
19219 static __always_inline void clac(void)
19220diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
19221index 8cd1cc3..827e09e 100644
19222--- a/arch/x86/include/asm/smp.h
19223+++ b/arch/x86/include/asm/smp.h
19224@@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
19225 /* cpus sharing the last level cache: */
19226 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
19227 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
19228-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
19229+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19230
19231 static inline struct cpumask *cpu_sibling_mask(int cpu)
19232 {
19233@@ -78,7 +78,7 @@ struct smp_ops {
19234
19235 void (*send_call_func_ipi)(const struct cpumask *mask);
19236 void (*send_call_func_single_ipi)(int cpu);
19237-};
19238+} __no_const;
19239
19240 /* Globals due to paravirt */
19241 extern void set_cpu_sibling_map(int cpu);
19242@@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
19243 extern int safe_smp_processor_id(void);
19244
19245 #elif defined(CONFIG_X86_64_SMP)
19246-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19247-
19248-#define stack_smp_processor_id() \
19249-({ \
19250- struct thread_info *ti; \
19251- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
19252- ti->cpu; \
19253-})
19254+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19255+#define stack_smp_processor_id() raw_smp_processor_id()
19256 #define safe_smp_processor_id() smp_processor_id()
19257
19258 #endif
19259diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
19260index 6a99859..03cb807 100644
19261--- a/arch/x86/include/asm/stackprotector.h
19262+++ b/arch/x86/include/asm/stackprotector.h
19263@@ -47,7 +47,7 @@
19264 * head_32 for boot CPU and setup_per_cpu_areas() for others.
19265 */
19266 #define GDT_STACK_CANARY_INIT \
19267- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
19268+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
19269
19270 /*
19271 * Initialize the stackprotector canary value.
19272@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
19273
19274 static inline void load_stack_canary_segment(void)
19275 {
19276-#ifdef CONFIG_X86_32
19277+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19278 asm volatile ("mov %0, %%gs" : : "r" (0));
19279 #endif
19280 }
19281diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
19282index 70bbe39..4ae2bd4 100644
19283--- a/arch/x86/include/asm/stacktrace.h
19284+++ b/arch/x86/include/asm/stacktrace.h
19285@@ -11,28 +11,20 @@
19286
19287 extern int kstack_depth_to_print;
19288
19289-struct thread_info;
19290+struct task_struct;
19291 struct stacktrace_ops;
19292
19293-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
19294- unsigned long *stack,
19295- unsigned long bp,
19296- const struct stacktrace_ops *ops,
19297- void *data,
19298- unsigned long *end,
19299- int *graph);
19300+typedef unsigned long walk_stack_t(struct task_struct *task,
19301+ void *stack_start,
19302+ unsigned long *stack,
19303+ unsigned long bp,
19304+ const struct stacktrace_ops *ops,
19305+ void *data,
19306+ unsigned long *end,
19307+ int *graph);
19308
19309-extern unsigned long
19310-print_context_stack(struct thread_info *tinfo,
19311- unsigned long *stack, unsigned long bp,
19312- const struct stacktrace_ops *ops, void *data,
19313- unsigned long *end, int *graph);
19314-
19315-extern unsigned long
19316-print_context_stack_bp(struct thread_info *tinfo,
19317- unsigned long *stack, unsigned long bp,
19318- const struct stacktrace_ops *ops, void *data,
19319- unsigned long *end, int *graph);
19320+extern walk_stack_t print_context_stack;
19321+extern walk_stack_t print_context_stack_bp;
19322
19323 /* Generic stack tracer with callbacks */
19324
19325@@ -40,7 +32,7 @@ struct stacktrace_ops {
19326 void (*address)(void *data, unsigned long address, int reliable);
19327 /* On negative return stop dumping */
19328 int (*stack)(void *data, char *name);
19329- walk_stack_t walk_stack;
19330+ walk_stack_t *walk_stack;
19331 };
19332
19333 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
19334diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
19335index d7f3b3b..3cc39f1 100644
19336--- a/arch/x86/include/asm/switch_to.h
19337+++ b/arch/x86/include/asm/switch_to.h
19338@@ -108,7 +108,7 @@ do { \
19339 "call __switch_to\n\t" \
19340 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
19341 __switch_canary \
19342- "movq %P[thread_info](%%rsi),%%r8\n\t" \
19343+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
19344 "movq %%rax,%%rdi\n\t" \
19345 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
19346 "jnz ret_from_fork\n\t" \
19347@@ -119,7 +119,7 @@ do { \
19348 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
19349 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
19350 [_tif_fork] "i" (_TIF_FORK), \
19351- [thread_info] "i" (offsetof(struct task_struct, stack)), \
19352+ [thread_info] "m" (current_tinfo), \
19353 [current_task] "m" (current_task) \
19354 __switch_canary_iparam \
19355 : "memory", "cc" __EXTRA_CLOBBER)
19356diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19357index 547e344..6be1175 100644
19358--- a/arch/x86/include/asm/thread_info.h
19359+++ b/arch/x86/include/asm/thread_info.h
19360@@ -24,7 +24,6 @@ struct exec_domain;
19361 #include <linux/atomic.h>
19362
19363 struct thread_info {
19364- struct task_struct *task; /* main task structure */
19365 struct exec_domain *exec_domain; /* execution domain */
19366 __u32 flags; /* low level flags */
19367 __u32 status; /* thread synchronous flags */
19368@@ -33,13 +32,13 @@ struct thread_info {
19369 mm_segment_t addr_limit;
19370 struct restart_block restart_block;
19371 void __user *sysenter_return;
19372+ unsigned long lowest_stack;
19373 unsigned int sig_on_uaccess_error:1;
19374 unsigned int uaccess_err:1; /* uaccess failed */
19375 };
19376
19377-#define INIT_THREAD_INFO(tsk) \
19378+#define INIT_THREAD_INFO \
19379 { \
19380- .task = &tsk, \
19381 .exec_domain = &default_exec_domain, \
19382 .flags = 0, \
19383 .cpu = 0, \
19384@@ -50,7 +49,7 @@ struct thread_info {
19385 }, \
19386 }
19387
19388-#define init_thread_info (init_thread_union.thread_info)
19389+#define init_thread_info (init_thread_union.stack)
19390 #define init_stack (init_thread_union.stack)
19391
19392 #else /* !__ASSEMBLY__ */
19393@@ -91,6 +90,7 @@ struct thread_info {
19394 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19395 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19396 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19397+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19398
19399 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19400 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19401@@ -115,17 +115,18 @@ struct thread_info {
19402 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19403 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19404 #define _TIF_X32 (1 << TIF_X32)
19405+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19406
19407 /* work to do in syscall_trace_enter() */
19408 #define _TIF_WORK_SYSCALL_ENTRY \
19409 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19410 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19411- _TIF_NOHZ)
19412+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19413
19414 /* work to do in syscall_trace_leave() */
19415 #define _TIF_WORK_SYSCALL_EXIT \
19416 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19417- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19418+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19419
19420 /* work to do on interrupt/exception return */
19421 #define _TIF_WORK_MASK \
19422@@ -136,7 +137,7 @@ struct thread_info {
19423 /* work to do on any return to user space */
19424 #define _TIF_ALLWORK_MASK \
19425 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19426- _TIF_NOHZ)
19427+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19428
19429 /* Only used for 64 bit */
19430 #define _TIF_DO_NOTIFY_MASK \
19431@@ -151,7 +152,6 @@ struct thread_info {
19432 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19433
19434 #define STACK_WARN (THREAD_SIZE/8)
19435-#define KERNEL_STACK_OFFSET (5*(BITS_PER_LONG/8))
19436
19437 /*
19438 * macros/functions for gaining access to the thread information structure
19439@@ -162,26 +162,18 @@ struct thread_info {
19440
19441 DECLARE_PER_CPU(unsigned long, kernel_stack);
19442
19443+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19444+
19445 static inline struct thread_info *current_thread_info(void)
19446 {
19447- struct thread_info *ti;
19448- ti = (void *)(this_cpu_read_stable(kernel_stack) +
19449- KERNEL_STACK_OFFSET - THREAD_SIZE);
19450- return ti;
19451+ return this_cpu_read_stable(current_tinfo);
19452 }
19453
19454 #else /* !__ASSEMBLY__ */
19455
19456 /* how to get the thread information struct from ASM */
19457 #define GET_THREAD_INFO(reg) \
19458- _ASM_MOV PER_CPU_VAR(kernel_stack),reg ; \
19459- _ASM_SUB $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg ;
19460-
19461-/*
19462- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19463- * a certain register (to be used in assembler memory operands).
19464- */
19465-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19466+ _ASM_MOV PER_CPU_VAR(current_tinfo),reg ;
19467
19468 #endif
19469
19470@@ -237,5 +229,12 @@ static inline bool is_ia32_task(void)
19471 extern void arch_task_cache_init(void);
19472 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19473 extern void arch_release_task_struct(struct task_struct *tsk);
19474+
19475+#define __HAVE_THREAD_FUNCTIONS
19476+#define task_thread_info(task) (&(task)->tinfo)
19477+#define task_stack_page(task) ((task)->stack)
19478+#define setup_thread_stack(p, org) do {} while (0)
19479+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19480+
19481 #endif
19482 #endif /* _ASM_X86_THREAD_INFO_H */
19483diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19484index 04905bf..1178cdf 100644
19485--- a/arch/x86/include/asm/tlbflush.h
19486+++ b/arch/x86/include/asm/tlbflush.h
19487@@ -17,18 +17,44 @@
19488
19489 static inline void __native_flush_tlb(void)
19490 {
19491+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19492+ u64 descriptor[2];
19493+
19494+ descriptor[0] = PCID_KERNEL;
19495+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_NONGLOBAL) : "memory");
19496+ return;
19497+ }
19498+
19499+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19500+ if (static_cpu_has(X86_FEATURE_PCID)) {
19501+ unsigned int cpu = raw_get_cpu();
19502+
19503+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19504+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19505+ raw_put_cpu_no_resched();
19506+ return;
19507+ }
19508+#endif
19509+
19510 native_write_cr3(native_read_cr3());
19511 }
19512
19513 static inline void __native_flush_tlb_global_irq_disabled(void)
19514 {
19515- unsigned long cr4;
19516+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19517+ u64 descriptor[2];
19518
19519- cr4 = native_read_cr4();
19520- /* clear PGE */
19521- native_write_cr4(cr4 & ~X86_CR4_PGE);
19522- /* write old PGE again and flush TLBs */
19523- native_write_cr4(cr4);
19524+ descriptor[0] = PCID_KERNEL;
19525+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19526+ } else {
19527+ unsigned long cr4;
19528+
19529+ cr4 = native_read_cr4();
19530+ /* clear PGE */
19531+ native_write_cr4(cr4 & ~X86_CR4_PGE);
19532+ /* write old PGE again and flush TLBs */
19533+ native_write_cr4(cr4);
19534+ }
19535 }
19536
19537 static inline void __native_flush_tlb_global(void)
19538@@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19539
19540 static inline void __native_flush_tlb_single(unsigned long addr)
19541 {
19542+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19543+ u64 descriptor[2];
19544+
19545+ descriptor[0] = PCID_KERNEL;
19546+ descriptor[1] = addr;
19547+
19548+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19549+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19550+ if (addr < TASK_SIZE_MAX)
19551+ descriptor[1] += pax_user_shadow_base;
19552+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19553+ }
19554+
19555+ descriptor[0] = PCID_USER;
19556+ descriptor[1] = addr;
19557+#endif
19558+
19559+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19560+ return;
19561+ }
19562+
19563+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19564+ if (static_cpu_has(X86_FEATURE_PCID)) {
19565+ unsigned int cpu = raw_get_cpu();
19566+
19567+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19568+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19569+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19570+ raw_put_cpu_no_resched();
19571+
19572+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19573+ addr += pax_user_shadow_base;
19574+ }
19575+#endif
19576+
19577 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19578 }
19579
19580diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19581index 0d592e0..526f797 100644
19582--- a/arch/x86/include/asm/uaccess.h
19583+++ b/arch/x86/include/asm/uaccess.h
19584@@ -7,6 +7,7 @@
19585 #include <linux/compiler.h>
19586 #include <linux/thread_info.h>
19587 #include <linux/string.h>
19588+#include <linux/spinlock.h>
19589 #include <asm/asm.h>
19590 #include <asm/page.h>
19591 #include <asm/smap.h>
19592@@ -29,7 +30,12 @@
19593
19594 #define get_ds() (KERNEL_DS)
19595 #define get_fs() (current_thread_info()->addr_limit)
19596+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19597+void __set_fs(mm_segment_t x);
19598+void set_fs(mm_segment_t x);
19599+#else
19600 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19601+#endif
19602
19603 #define segment_eq(a, b) ((a).seg == (b).seg)
19604
19605@@ -85,8 +91,36 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19606 * checks that the pointer is in the user space range - after calling
19607 * this function, memory access functions may still return -EFAULT.
19608 */
19609-#define access_ok(type, addr, size) \
19610- likely(!__range_not_ok(addr, size, user_addr_max()))
19611+extern int _cond_resched(void);
19612+#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19613+#define access_ok(type, addr, size) \
19614+({ \
19615+ unsigned long __size = size; \
19616+ unsigned long __addr = (unsigned long)addr; \
19617+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19618+ if (__ret_ao && __size) { \
19619+ unsigned long __addr_ao = __addr & PAGE_MASK; \
19620+ unsigned long __end_ao = __addr + __size - 1; \
19621+ if (unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19622+ while (__addr_ao <= __end_ao) { \
19623+ char __c_ao; \
19624+ __addr_ao += PAGE_SIZE; \
19625+ if (__size > PAGE_SIZE) \
19626+ _cond_resched(); \
19627+ if (__get_user(__c_ao, (char __user *)__addr)) \
19628+ break; \
19629+ if (type != VERIFY_WRITE) { \
19630+ __addr = __addr_ao; \
19631+ continue; \
19632+ } \
19633+ if (__put_user(__c_ao, (char __user *)__addr)) \
19634+ break; \
19635+ __addr = __addr_ao; \
19636+ } \
19637+ } \
19638+ } \
19639+ __ret_ao; \
19640+})
19641
19642 /*
19643 * The exception table consists of pairs of addresses relative to the
19644@@ -176,10 +210,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19645 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19646 __chk_user_ptr(ptr); \
19647 might_fault(); \
19648+ pax_open_userland(); \
19649 asm volatile("call __get_user_%P3" \
19650 : "=a" (__ret_gu), "=r" (__val_gu) \
19651 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19652 (x) = (__typeof__(*(ptr))) __val_gu; \
19653+ pax_close_userland(); \
19654 __ret_gu; \
19655 })
19656
19657@@ -187,13 +223,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19658 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19659 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19660
19661-
19662+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19663+#define __copyuser_seg "gs;"
19664+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19665+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19666+#else
19667+#define __copyuser_seg
19668+#define __COPYUSER_SET_ES
19669+#define __COPYUSER_RESTORE_ES
19670+#endif
19671
19672 #ifdef CONFIG_X86_32
19673 #define __put_user_asm_u64(x, addr, err, errret) \
19674 asm volatile(ASM_STAC "\n" \
19675- "1: movl %%eax,0(%2)\n" \
19676- "2: movl %%edx,4(%2)\n" \
19677+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19678+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19679 "3: " ASM_CLAC "\n" \
19680 ".section .fixup,\"ax\"\n" \
19681 "4: movl %3,%0\n" \
19682@@ -206,8 +250,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19683
19684 #define __put_user_asm_ex_u64(x, addr) \
19685 asm volatile(ASM_STAC "\n" \
19686- "1: movl %%eax,0(%1)\n" \
19687- "2: movl %%edx,4(%1)\n" \
19688+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19689+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19690 "3: " ASM_CLAC "\n" \
19691 _ASM_EXTABLE_EX(1b, 2b) \
19692 _ASM_EXTABLE_EX(2b, 3b) \
19693@@ -257,7 +301,8 @@ extern void __put_user_8(void);
19694 __typeof__(*(ptr)) __pu_val; \
19695 __chk_user_ptr(ptr); \
19696 might_fault(); \
19697- __pu_val = x; \
19698+ __pu_val = (x); \
19699+ pax_open_userland(); \
19700 switch (sizeof(*(ptr))) { \
19701 case 1: \
19702 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19703@@ -275,6 +320,7 @@ extern void __put_user_8(void);
19704 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19705 break; \
19706 } \
19707+ pax_close_userland(); \
19708 __ret_pu; \
19709 })
19710
19711@@ -355,8 +401,10 @@ do { \
19712 } while (0)
19713
19714 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19715+do { \
19716+ pax_open_userland(); \
19717 asm volatile(ASM_STAC "\n" \
19718- "1: mov"itype" %2,%"rtype"1\n" \
19719+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19720 "2: " ASM_CLAC "\n" \
19721 ".section .fixup,\"ax\"\n" \
19722 "3: mov %3,%0\n" \
19723@@ -364,8 +412,10 @@ do { \
19724 " jmp 2b\n" \
19725 ".previous\n" \
19726 _ASM_EXTABLE(1b, 3b) \
19727- : "=r" (err), ltype(x) \
19728- : "m" (__m(addr)), "i" (errret), "0" (err))
19729+ : "=r" (err), ltype (x) \
19730+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
19731+ pax_close_userland(); \
19732+} while (0)
19733
19734 #define __get_user_size_ex(x, ptr, size) \
19735 do { \
19736@@ -389,7 +439,7 @@ do { \
19737 } while (0)
19738
19739 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19740- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19741+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19742 "2:\n" \
19743 _ASM_EXTABLE_EX(1b, 2b) \
19744 : ltype(x) : "m" (__m(addr)))
19745@@ -406,13 +456,24 @@ do { \
19746 int __gu_err; \
19747 unsigned long __gu_val; \
19748 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19749- (x) = (__force __typeof__(*(ptr)))__gu_val; \
19750+ (x) = (__typeof__(*(ptr)))__gu_val; \
19751 __gu_err; \
19752 })
19753
19754 /* FIXME: this hack is definitely wrong -AK */
19755 struct __large_struct { unsigned long buf[100]; };
19756-#define __m(x) (*(struct __large_struct __user *)(x))
19757+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19758+#define ____m(x) \
19759+({ \
19760+ unsigned long ____x = (unsigned long)(x); \
19761+ if (____x < pax_user_shadow_base) \
19762+ ____x += pax_user_shadow_base; \
19763+ (typeof(x))____x; \
19764+})
19765+#else
19766+#define ____m(x) (x)
19767+#endif
19768+#define __m(x) (*(struct __large_struct __user *)____m(x))
19769
19770 /*
19771 * Tell gcc we read from memory instead of writing: this is because
19772@@ -420,8 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
19773 * aliasing issues.
19774 */
19775 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19776+do { \
19777+ pax_open_userland(); \
19778 asm volatile(ASM_STAC "\n" \
19779- "1: mov"itype" %"rtype"1,%2\n" \
19780+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19781 "2: " ASM_CLAC "\n" \
19782 ".section .fixup,\"ax\"\n" \
19783 "3: mov %3,%0\n" \
19784@@ -429,10 +492,12 @@ struct __large_struct { unsigned long buf[100]; };
19785 ".previous\n" \
19786 _ASM_EXTABLE(1b, 3b) \
19787 : "=r"(err) \
19788- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19789+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19790+ pax_close_userland(); \
19791+} while (0)
19792
19793 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19794- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19795+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19796 "2:\n" \
19797 _ASM_EXTABLE_EX(1b, 2b) \
19798 : : ltype(x), "m" (__m(addr)))
19799@@ -442,11 +507,13 @@ struct __large_struct { unsigned long buf[100]; };
19800 */
19801 #define uaccess_try do { \
19802 current_thread_info()->uaccess_err = 0; \
19803+ pax_open_userland(); \
19804 stac(); \
19805 barrier();
19806
19807 #define uaccess_catch(err) \
19808 clac(); \
19809+ pax_close_userland(); \
19810 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19811 } while (0)
19812
19813@@ -471,8 +538,12 @@ struct __large_struct { unsigned long buf[100]; };
19814 * On error, the variable @x is set to zero.
19815 */
19816
19817+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19818+#define __get_user(x, ptr) get_user((x), (ptr))
19819+#else
19820 #define __get_user(x, ptr) \
19821 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19822+#endif
19823
19824 /**
19825 * __put_user: - Write a simple value into user space, with less checking.
19826@@ -494,8 +565,12 @@ struct __large_struct { unsigned long buf[100]; };
19827 * Returns zero on success, or -EFAULT on error.
19828 */
19829
19830+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19831+#define __put_user(x, ptr) put_user((x), (ptr))
19832+#else
19833 #define __put_user(x, ptr) \
19834 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19835+#endif
19836
19837 #define __get_user_unaligned __get_user
19838 #define __put_user_unaligned __put_user
19839@@ -513,7 +588,7 @@ struct __large_struct { unsigned long buf[100]; };
19840 #define get_user_ex(x, ptr) do { \
19841 unsigned long __gue_val; \
19842 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19843- (x) = (__force __typeof__(*(ptr)))__gue_val; \
19844+ (x) = (__typeof__(*(ptr)))__gue_val; \
19845 } while (0)
19846
19847 #define put_user_try uaccess_try
19848@@ -542,18 +617,19 @@ extern void __cmpxchg_wrong_size(void)
19849 __typeof__(ptr) __uval = (uval); \
19850 __typeof__(*(ptr)) __old = (old); \
19851 __typeof__(*(ptr)) __new = (new); \
19852+ pax_open_userland(); \
19853 switch (size) { \
19854 case 1: \
19855 { \
19856 asm volatile("\t" ASM_STAC "\n" \
19857- "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
19858+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
19859 "2:\t" ASM_CLAC "\n" \
19860 "\t.section .fixup, \"ax\"\n" \
19861 "3:\tmov %3, %0\n" \
19862 "\tjmp 2b\n" \
19863 "\t.previous\n" \
19864 _ASM_EXTABLE(1b, 3b) \
19865- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19866+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19867 : "i" (-EFAULT), "q" (__new), "1" (__old) \
19868 : "memory" \
19869 ); \
19870@@ -562,14 +638,14 @@ extern void __cmpxchg_wrong_size(void)
19871 case 2: \
19872 { \
19873 asm volatile("\t" ASM_STAC "\n" \
19874- "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
19875+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
19876 "2:\t" ASM_CLAC "\n" \
19877 "\t.section .fixup, \"ax\"\n" \
19878 "3:\tmov %3, %0\n" \
19879 "\tjmp 2b\n" \
19880 "\t.previous\n" \
19881 _ASM_EXTABLE(1b, 3b) \
19882- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19883+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19884 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19885 : "memory" \
19886 ); \
19887@@ -578,14 +654,14 @@ extern void __cmpxchg_wrong_size(void)
19888 case 4: \
19889 { \
19890 asm volatile("\t" ASM_STAC "\n" \
19891- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
19892+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
19893 "2:\t" ASM_CLAC "\n" \
19894 "\t.section .fixup, \"ax\"\n" \
19895 "3:\tmov %3, %0\n" \
19896 "\tjmp 2b\n" \
19897 "\t.previous\n" \
19898 _ASM_EXTABLE(1b, 3b) \
19899- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19900+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19901 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19902 : "memory" \
19903 ); \
19904@@ -597,14 +673,14 @@ extern void __cmpxchg_wrong_size(void)
19905 __cmpxchg_wrong_size(); \
19906 \
19907 asm volatile("\t" ASM_STAC "\n" \
19908- "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
19909+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
19910 "2:\t" ASM_CLAC "\n" \
19911 "\t.section .fixup, \"ax\"\n" \
19912 "3:\tmov %3, %0\n" \
19913 "\tjmp 2b\n" \
19914 "\t.previous\n" \
19915 _ASM_EXTABLE(1b, 3b) \
19916- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19917+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19918 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19919 : "memory" \
19920 ); \
19921@@ -613,6 +689,7 @@ extern void __cmpxchg_wrong_size(void)
19922 default: \
19923 __cmpxchg_wrong_size(); \
19924 } \
19925+ pax_close_userland(); \
19926 *__uval = __old; \
19927 __ret; \
19928 })
19929@@ -636,17 +713,6 @@ extern struct movsl_mask {
19930
19931 #define ARCH_HAS_NOCACHE_UACCESS 1
19932
19933-#ifdef CONFIG_X86_32
19934-# include <asm/uaccess_32.h>
19935-#else
19936-# include <asm/uaccess_64.h>
19937-#endif
19938-
19939-unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19940- unsigned n);
19941-unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19942- unsigned n);
19943-
19944 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19945 # define copy_user_diag __compiletime_error
19946 #else
19947@@ -656,7 +722,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19948 extern void copy_user_diag("copy_from_user() buffer size is too small")
19949 copy_from_user_overflow(void);
19950 extern void copy_user_diag("copy_to_user() buffer size is too small")
19951-copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19952+copy_to_user_overflow(void);
19953
19954 #undef copy_user_diag
19955
19956@@ -669,7 +735,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19957
19958 extern void
19959 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19960-__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19961+__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19962 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19963
19964 #else
19965@@ -684,10 +750,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19966
19967 #endif
19968
19969+#ifdef CONFIG_X86_32
19970+# include <asm/uaccess_32.h>
19971+#else
19972+# include <asm/uaccess_64.h>
19973+#endif
19974+
19975 static inline unsigned long __must_check
19976 copy_from_user(void *to, const void __user *from, unsigned long n)
19977 {
19978- int sz = __compiletime_object_size(to);
19979+ size_t sz = __compiletime_object_size(to);
19980
19981 might_fault();
19982
19983@@ -709,12 +781,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19984 * case, and do only runtime checking for non-constant sizes.
19985 */
19986
19987- if (likely(sz < 0 || sz >= n))
19988- n = _copy_from_user(to, from, n);
19989- else if(__builtin_constant_p(n))
19990- copy_from_user_overflow();
19991- else
19992- __copy_from_user_overflow(sz, n);
19993+ if (likely(sz != (size_t)-1 && sz < n)) {
19994+ if(__builtin_constant_p(n))
19995+ copy_from_user_overflow();
19996+ else
19997+ __copy_from_user_overflow(sz, n);
19998+ } else if (access_ok(VERIFY_READ, from, n))
19999+ n = __copy_from_user(to, from, n);
20000+ else if ((long)n > 0)
20001+ memset(to, 0, n);
20002
20003 return n;
20004 }
20005@@ -722,17 +797,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20006 static inline unsigned long __must_check
20007 copy_to_user(void __user *to, const void *from, unsigned long n)
20008 {
20009- int sz = __compiletime_object_size(from);
20010+ size_t sz = __compiletime_object_size(from);
20011
20012 might_fault();
20013
20014 /* See the comment in copy_from_user() above. */
20015- if (likely(sz < 0 || sz >= n))
20016- n = _copy_to_user(to, from, n);
20017- else if(__builtin_constant_p(n))
20018- copy_to_user_overflow();
20019- else
20020- __copy_to_user_overflow(sz, n);
20021+ if (likely(sz != (size_t)-1 && sz < n)) {
20022+ if(__builtin_constant_p(n))
20023+ copy_to_user_overflow();
20024+ else
20025+ __copy_to_user_overflow(sz, n);
20026+ } else if (access_ok(VERIFY_WRITE, to, n))
20027+ n = __copy_to_user(to, from, n);
20028
20029 return n;
20030 }
20031diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
20032index 3c03a5d..1071638 100644
20033--- a/arch/x86/include/asm/uaccess_32.h
20034+++ b/arch/x86/include/asm/uaccess_32.h
20035@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
20036 static __always_inline unsigned long __must_check
20037 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
20038 {
20039+ if ((long)n < 0)
20040+ return n;
20041+
20042+ check_object_size(from, n, true);
20043+
20044 if (__builtin_constant_p(n)) {
20045 unsigned long ret;
20046
20047@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
20048 __copy_to_user(void __user *to, const void *from, unsigned long n)
20049 {
20050 might_fault();
20051+
20052 return __copy_to_user_inatomic(to, from, n);
20053 }
20054
20055 static __always_inline unsigned long
20056 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
20057 {
20058+ if ((long)n < 0)
20059+ return n;
20060+
20061 /* Avoid zeroing the tail if the copy fails..
20062 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
20063 * but as the zeroing behaviour is only significant when n is not
20064@@ -137,6 +146,12 @@ static __always_inline unsigned long
20065 __copy_from_user(void *to, const void __user *from, unsigned long n)
20066 {
20067 might_fault();
20068+
20069+ if ((long)n < 0)
20070+ return n;
20071+
20072+ check_object_size(to, n, false);
20073+
20074 if (__builtin_constant_p(n)) {
20075 unsigned long ret;
20076
20077@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
20078 const void __user *from, unsigned long n)
20079 {
20080 might_fault();
20081+
20082+ if ((long)n < 0)
20083+ return n;
20084+
20085 if (__builtin_constant_p(n)) {
20086 unsigned long ret;
20087
20088@@ -181,7 +200,10 @@ static __always_inline unsigned long
20089 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
20090 unsigned long n)
20091 {
20092- return __copy_from_user_ll_nocache_nozero(to, from, n);
20093+ if ((long)n < 0)
20094+ return n;
20095+
20096+ return __copy_from_user_ll_nocache_nozero(to, from, n);
20097 }
20098
20099 #endif /* _ASM_X86_UACCESS_32_H */
20100diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
20101index 12a26b9..206c200 100644
20102--- a/arch/x86/include/asm/uaccess_64.h
20103+++ b/arch/x86/include/asm/uaccess_64.h
20104@@ -10,6 +10,9 @@
20105 #include <asm/alternative.h>
20106 #include <asm/cpufeature.h>
20107 #include <asm/page.h>
20108+#include <asm/pgtable.h>
20109+
20110+#define set_fs(x) (current_thread_info()->addr_limit = (x))
20111
20112 /*
20113 * Copy To/From Userspace
20114@@ -17,14 +20,14 @@
20115
20116 /* Handles exceptions in both to and from, but doesn't do access_ok */
20117 __must_check unsigned long
20118-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
20119+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
20120 __must_check unsigned long
20121-copy_user_generic_string(void *to, const void *from, unsigned len);
20122+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
20123 __must_check unsigned long
20124-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
20125+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
20126
20127 static __always_inline __must_check unsigned long
20128-copy_user_generic(void *to, const void *from, unsigned len)
20129+copy_user_generic(void *to, const void *from, unsigned long len)
20130 {
20131 unsigned ret;
20132
20133@@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
20134 }
20135
20136 __must_check unsigned long
20137-copy_in_user(void __user *to, const void __user *from, unsigned len);
20138+copy_in_user(void __user *to, const void __user *from, unsigned long len);
20139
20140 static __always_inline __must_check
20141-int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
20142+unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
20143 {
20144- int ret = 0;
20145+ size_t sz = __compiletime_object_size(dst);
20146+ unsigned ret = 0;
20147+
20148+ if (size > INT_MAX)
20149+ return size;
20150+
20151+ check_object_size(dst, size, false);
20152+
20153+#ifdef CONFIG_PAX_MEMORY_UDEREF
20154+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20155+ return size;
20156+#endif
20157+
20158+ if (unlikely(sz != (size_t)-1 && sz < size)) {
20159+ if(__builtin_constant_p(size))
20160+ copy_from_user_overflow();
20161+ else
20162+ __copy_from_user_overflow(sz, size);
20163+ return size;
20164+ }
20165
20166 if (!__builtin_constant_p(size))
20167- return copy_user_generic(dst, (__force void *)src, size);
20168+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20169 switch (size) {
20170- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
20171+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
20172 ret, "b", "b", "=q", 1);
20173 return ret;
20174- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
20175+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
20176 ret, "w", "w", "=r", 2);
20177 return ret;
20178- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
20179+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
20180 ret, "l", "k", "=r", 4);
20181 return ret;
20182- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
20183+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20184 ret, "q", "", "=r", 8);
20185 return ret;
20186 case 10:
20187- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20188+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20189 ret, "q", "", "=r", 10);
20190 if (unlikely(ret))
20191 return ret;
20192 __get_user_asm(*(u16 *)(8 + (char *)dst),
20193- (u16 __user *)(8 + (char __user *)src),
20194+ (const u16 __user *)(8 + (const char __user *)src),
20195 ret, "w", "w", "=r", 2);
20196 return ret;
20197 case 16:
20198- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20199+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20200 ret, "q", "", "=r", 16);
20201 if (unlikely(ret))
20202 return ret;
20203 __get_user_asm(*(u64 *)(8 + (char *)dst),
20204- (u64 __user *)(8 + (char __user *)src),
20205+ (const u64 __user *)(8 + (const char __user *)src),
20206 ret, "q", "", "=r", 8);
20207 return ret;
20208 default:
20209- return copy_user_generic(dst, (__force void *)src, size);
20210+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20211 }
20212 }
20213
20214 static __always_inline __must_check
20215-int __copy_from_user(void *dst, const void __user *src, unsigned size)
20216+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
20217 {
20218 might_fault();
20219 return __copy_from_user_nocheck(dst, src, size);
20220 }
20221
20222 static __always_inline __must_check
20223-int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
20224+unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
20225 {
20226- int ret = 0;
20227+ size_t sz = __compiletime_object_size(src);
20228+ unsigned ret = 0;
20229+
20230+ if (size > INT_MAX)
20231+ return size;
20232+
20233+ check_object_size(src, size, true);
20234+
20235+#ifdef CONFIG_PAX_MEMORY_UDEREF
20236+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20237+ return size;
20238+#endif
20239+
20240+ if (unlikely(sz != (size_t)-1 && sz < size)) {
20241+ if(__builtin_constant_p(size))
20242+ copy_to_user_overflow();
20243+ else
20244+ __copy_to_user_overflow(sz, size);
20245+ return size;
20246+ }
20247
20248 if (!__builtin_constant_p(size))
20249- return copy_user_generic((__force void *)dst, src, size);
20250+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20251 switch (size) {
20252- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
20253+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
20254 ret, "b", "b", "iq", 1);
20255 return ret;
20256- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
20257+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
20258 ret, "w", "w", "ir", 2);
20259 return ret;
20260- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
20261+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
20262 ret, "l", "k", "ir", 4);
20263 return ret;
20264- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
20265+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20266 ret, "q", "", "er", 8);
20267 return ret;
20268 case 10:
20269- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20270+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20271 ret, "q", "", "er", 10);
20272 if (unlikely(ret))
20273 return ret;
20274 asm("":::"memory");
20275- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
20276+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
20277 ret, "w", "w", "ir", 2);
20278 return ret;
20279 case 16:
20280- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20281+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20282 ret, "q", "", "er", 16);
20283 if (unlikely(ret))
20284 return ret;
20285 asm("":::"memory");
20286- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
20287+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
20288 ret, "q", "", "er", 8);
20289 return ret;
20290 default:
20291- return copy_user_generic((__force void *)dst, src, size);
20292+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20293 }
20294 }
20295
20296 static __always_inline __must_check
20297-int __copy_to_user(void __user *dst, const void *src, unsigned size)
20298+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
20299 {
20300 might_fault();
20301 return __copy_to_user_nocheck(dst, src, size);
20302 }
20303
20304 static __always_inline __must_check
20305-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20306+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20307 {
20308- int ret = 0;
20309+ unsigned ret = 0;
20310
20311 might_fault();
20312+
20313+ if (size > INT_MAX)
20314+ return size;
20315+
20316+#ifdef CONFIG_PAX_MEMORY_UDEREF
20317+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20318+ return size;
20319+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20320+ return size;
20321+#endif
20322+
20323 if (!__builtin_constant_p(size))
20324- return copy_user_generic((__force void *)dst,
20325- (__force void *)src, size);
20326+ return copy_user_generic((__force_kernel void *)____m(dst),
20327+ (__force_kernel const void *)____m(src), size);
20328 switch (size) {
20329 case 1: {
20330 u8 tmp;
20331- __get_user_asm(tmp, (u8 __user *)src,
20332+ __get_user_asm(tmp, (const u8 __user *)src,
20333 ret, "b", "b", "=q", 1);
20334 if (likely(!ret))
20335 __put_user_asm(tmp, (u8 __user *)dst,
20336@@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20337 }
20338 case 2: {
20339 u16 tmp;
20340- __get_user_asm(tmp, (u16 __user *)src,
20341+ __get_user_asm(tmp, (const u16 __user *)src,
20342 ret, "w", "w", "=r", 2);
20343 if (likely(!ret))
20344 __put_user_asm(tmp, (u16 __user *)dst,
20345@@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20346
20347 case 4: {
20348 u32 tmp;
20349- __get_user_asm(tmp, (u32 __user *)src,
20350+ __get_user_asm(tmp, (const u32 __user *)src,
20351 ret, "l", "k", "=r", 4);
20352 if (likely(!ret))
20353 __put_user_asm(tmp, (u32 __user *)dst,
20354@@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20355 }
20356 case 8: {
20357 u64 tmp;
20358- __get_user_asm(tmp, (u64 __user *)src,
20359+ __get_user_asm(tmp, (const u64 __user *)src,
20360 ret, "q", "", "=r", 8);
20361 if (likely(!ret))
20362 __put_user_asm(tmp, (u64 __user *)dst,
20363@@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20364 return ret;
20365 }
20366 default:
20367- return copy_user_generic((__force void *)dst,
20368- (__force void *)src, size);
20369+ return copy_user_generic((__force_kernel void *)____m(dst),
20370+ (__force_kernel const void *)____m(src), size);
20371 }
20372 }
20373
20374-static __must_check __always_inline int
20375-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20376+static __must_check __always_inline unsigned long
20377+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20378 {
20379 return __copy_from_user_nocheck(dst, src, size);
20380 }
20381
20382-static __must_check __always_inline int
20383-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20384+static __must_check __always_inline unsigned long
20385+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20386 {
20387 return __copy_to_user_nocheck(dst, src, size);
20388 }
20389
20390-extern long __copy_user_nocache(void *dst, const void __user *src,
20391- unsigned size, int zerorest);
20392+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20393+ unsigned long size, int zerorest);
20394
20395-static inline int
20396-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20397+static inline unsigned long
20398+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20399 {
20400 might_fault();
20401+
20402+ if (size > INT_MAX)
20403+ return size;
20404+
20405+#ifdef CONFIG_PAX_MEMORY_UDEREF
20406+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20407+ return size;
20408+#endif
20409+
20410 return __copy_user_nocache(dst, src, size, 1);
20411 }
20412
20413-static inline int
20414+static inline unsigned long
20415 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20416- unsigned size)
20417+ unsigned long size)
20418 {
20419+ if (size > INT_MAX)
20420+ return size;
20421+
20422+#ifdef CONFIG_PAX_MEMORY_UDEREF
20423+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20424+ return size;
20425+#endif
20426+
20427 return __copy_user_nocache(dst, src, size, 0);
20428 }
20429
20430 unsigned long
20431-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20432+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20433
20434 #endif /* _ASM_X86_UACCESS_64_H */
20435diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20436index 5b238981..77fdd78 100644
20437--- a/arch/x86/include/asm/word-at-a-time.h
20438+++ b/arch/x86/include/asm/word-at-a-time.h
20439@@ -11,7 +11,7 @@
20440 * and shift, for example.
20441 */
20442 struct word_at_a_time {
20443- const unsigned long one_bits, high_bits;
20444+ unsigned long one_bits, high_bits;
20445 };
20446
20447 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20448diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20449index e45e4da..44e8572 100644
20450--- a/arch/x86/include/asm/x86_init.h
20451+++ b/arch/x86/include/asm/x86_init.h
20452@@ -129,7 +129,7 @@ struct x86_init_ops {
20453 struct x86_init_timers timers;
20454 struct x86_init_iommu iommu;
20455 struct x86_init_pci pci;
20456-};
20457+} __no_const;
20458
20459 /**
20460 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20461@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20462 void (*setup_percpu_clockev)(void);
20463 void (*early_percpu_clock_init)(void);
20464 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20465-};
20466+} __no_const;
20467
20468 struct timespec;
20469
20470@@ -168,7 +168,7 @@ struct x86_platform_ops {
20471 void (*save_sched_clock_state)(void);
20472 void (*restore_sched_clock_state)(void);
20473 void (*apic_post_init)(void);
20474-};
20475+} __no_const;
20476
20477 struct pci_dev;
20478 struct msi_msg;
20479@@ -185,7 +185,7 @@ struct x86_msi_ops {
20480 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20481 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20482 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20483-};
20484+} __no_const;
20485
20486 struct IO_APIC_route_entry;
20487 struct io_apic_irq_attr;
20488@@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20489 unsigned int destination, int vector,
20490 struct io_apic_irq_attr *attr);
20491 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20492-};
20493+} __no_const;
20494
20495 extern struct x86_init_ops x86_init;
20496 extern struct x86_cpuinit_ops x86_cpuinit;
20497diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20498index c949923..c22bfa4 100644
20499--- a/arch/x86/include/asm/xen/page.h
20500+++ b/arch/x86/include/asm/xen/page.h
20501@@ -63,7 +63,7 @@ extern int m2p_remove_override(struct page *page,
20502 extern struct page *m2p_find_override(unsigned long mfn);
20503 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20504
20505-static inline unsigned long pfn_to_mfn(unsigned long pfn)
20506+static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20507 {
20508 unsigned long mfn;
20509
20510diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20511index 7e7a79a..0824666 100644
20512--- a/arch/x86/include/asm/xsave.h
20513+++ b/arch/x86/include/asm/xsave.h
20514@@ -228,12 +228,16 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20515 if (unlikely(err))
20516 return -EFAULT;
20517
20518+ pax_open_userland();
20519 __asm__ __volatile__(ASM_STAC "\n"
20520- "1:"XSAVE"\n"
20521+ "1:"
20522+ __copyuser_seg
20523+ XSAVE"\n"
20524 "2: " ASM_CLAC "\n"
20525 xstate_fault
20526 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20527 : "memory");
20528+ pax_close_userland();
20529 return err;
20530 }
20531
20532@@ -243,16 +247,20 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20533 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20534 {
20535 int err = 0;
20536- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20537+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20538 u32 lmask = mask;
20539 u32 hmask = mask >> 32;
20540
20541+ pax_open_userland();
20542 __asm__ __volatile__(ASM_STAC "\n"
20543- "1:"XRSTOR"\n"
20544+ "1:"
20545+ __copyuser_seg
20546+ XRSTOR"\n"
20547 "2: " ASM_CLAC "\n"
20548 xstate_fault
20549 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20550 : "memory"); /* memory required? */
20551+ pax_close_userland();
20552 return err;
20553 }
20554
20555diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20556index d993e33..8db1b18 100644
20557--- a/arch/x86/include/uapi/asm/e820.h
20558+++ b/arch/x86/include/uapi/asm/e820.h
20559@@ -58,7 +58,7 @@ struct e820map {
20560 #define ISA_START_ADDRESS 0xa0000
20561 #define ISA_END_ADDRESS 0x100000
20562
20563-#define BIOS_BEGIN 0x000a0000
20564+#define BIOS_BEGIN 0x000c0000
20565 #define BIOS_END 0x00100000
20566
20567 #define BIOS_ROM_BASE 0xffe00000
20568diff --git a/arch/x86/include/uapi/asm/ldt.h b/arch/x86/include/uapi/asm/ldt.h
20569index 46727eb..6e1aaf7 100644
20570--- a/arch/x86/include/uapi/asm/ldt.h
20571+++ b/arch/x86/include/uapi/asm/ldt.h
20572@@ -28,6 +28,13 @@ struct user_desc {
20573 unsigned int seg_not_present:1;
20574 unsigned int useable:1;
20575 #ifdef __x86_64__
20576+ /*
20577+ * Because this bit is not present in 32-bit user code, user
20578+ * programs can pass uninitialized values here. Therefore, in
20579+ * any context in which a user_desc comes from a 32-bit program,
20580+ * the kernel must act as though lm == 0, regardless of the
20581+ * actual value.
20582+ */
20583 unsigned int lm:1;
20584 #endif
20585 };
20586diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20587index 7b0a55a..ad115bf 100644
20588--- a/arch/x86/include/uapi/asm/ptrace-abi.h
20589+++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20590@@ -49,7 +49,6 @@
20591 #define EFLAGS 144
20592 #define RSP 152
20593 #define SS 160
20594-#define ARGOFFSET R11
20595 #endif /* __ASSEMBLY__ */
20596
20597 /* top of stack page */
20598diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20599index 8f1e774..9b4c381 100644
20600--- a/arch/x86/kernel/Makefile
20601+++ b/arch/x86/kernel/Makefile
20602@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20603 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20604 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20605 obj-y += probe_roms.o
20606-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20607+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20608 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20609 obj-$(CONFIG_X86_64) += mcount_64.o
20610 obj-y += syscall_$(BITS).o vsyscall_gtod.o
20611diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20612index a142e77..6222cdd 100644
20613--- a/arch/x86/kernel/acpi/boot.c
20614+++ b/arch/x86/kernel/acpi/boot.c
20615@@ -1276,7 +1276,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20616 * If your system is blacklisted here, but you find that acpi=force
20617 * works for you, please contact linux-acpi@vger.kernel.org
20618 */
20619-static struct dmi_system_id __initdata acpi_dmi_table[] = {
20620+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20621 /*
20622 * Boxes that need ACPI disabled
20623 */
20624@@ -1351,7 +1351,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20625 };
20626
20627 /* second table for DMI checks that should run after early-quirks */
20628-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20629+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20630 /*
20631 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20632 * which includes some code which overrides all temperature
20633diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20634index 3136820..e2c6577 100644
20635--- a/arch/x86/kernel/acpi/sleep.c
20636+++ b/arch/x86/kernel/acpi/sleep.c
20637@@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20638 #else /* CONFIG_64BIT */
20639 #ifdef CONFIG_SMP
20640 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20641+
20642+ pax_open_kernel();
20643 early_gdt_descr.address =
20644 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20645+ pax_close_kernel();
20646+
20647 initial_gs = per_cpu_offset(smp_processor_id());
20648 #endif
20649 initial_code = (unsigned long)wakeup_long64;
20650diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20651index 665c6b7..eae4d56 100644
20652--- a/arch/x86/kernel/acpi/wakeup_32.S
20653+++ b/arch/x86/kernel/acpi/wakeup_32.S
20654@@ -29,13 +29,11 @@ wakeup_pmode_return:
20655 # and restore the stack ... but you need gdt for this to work
20656 movl saved_context_esp, %esp
20657
20658- movl %cs:saved_magic, %eax
20659- cmpl $0x12345678, %eax
20660+ cmpl $0x12345678, saved_magic
20661 jne bogus_magic
20662
20663 # jump to place where we left off
20664- movl saved_eip, %eax
20665- jmp *%eax
20666+ jmp *(saved_eip)
20667
20668 bogus_magic:
20669 jmp bogus_magic
20670diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20671index 703130f..27a155d 100644
20672--- a/arch/x86/kernel/alternative.c
20673+++ b/arch/x86/kernel/alternative.c
20674@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20675 */
20676 for (a = start; a < end; a++) {
20677 instr = (u8 *)&a->instr_offset + a->instr_offset;
20678+
20679+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20680+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20681+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20682+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20683+#endif
20684+
20685 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20686 BUG_ON(a->replacementlen > a->instrlen);
20687 BUG_ON(a->instrlen > sizeof(insnbuf));
20688@@ -284,6 +291,11 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20689 add_nops(insnbuf + a->replacementlen,
20690 a->instrlen - a->replacementlen);
20691
20692+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20693+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20694+ instr = ktva_ktla(instr);
20695+#endif
20696+
20697 text_poke_early(instr, insnbuf, a->instrlen);
20698 }
20699 }
20700@@ -299,10 +311,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20701 for (poff = start; poff < end; poff++) {
20702 u8 *ptr = (u8 *)poff + *poff;
20703
20704+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20705+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20706+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20707+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20708+#endif
20709+
20710 if (!*poff || ptr < text || ptr >= text_end)
20711 continue;
20712 /* turn DS segment override prefix into lock prefix */
20713- if (*ptr == 0x3e)
20714+ if (*ktla_ktva(ptr) == 0x3e)
20715 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20716 }
20717 mutex_unlock(&text_mutex);
20718@@ -317,10 +335,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20719 for (poff = start; poff < end; poff++) {
20720 u8 *ptr = (u8 *)poff + *poff;
20721
20722+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20723+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20724+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20725+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20726+#endif
20727+
20728 if (!*poff || ptr < text || ptr >= text_end)
20729 continue;
20730 /* turn lock prefix into DS segment override prefix */
20731- if (*ptr == 0xf0)
20732+ if (*ktla_ktva(ptr) == 0xf0)
20733 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20734 }
20735 mutex_unlock(&text_mutex);
20736@@ -457,7 +481,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20737
20738 BUG_ON(p->len > MAX_PATCH_LEN);
20739 /* prep the buffer with the original instructions */
20740- memcpy(insnbuf, p->instr, p->len);
20741+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20742 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20743 (unsigned long)p->instr, p->len);
20744
20745@@ -504,7 +528,7 @@ void __init alternative_instructions(void)
20746 if (!uniproc_patched || num_possible_cpus() == 1)
20747 free_init_pages("SMP alternatives",
20748 (unsigned long)__smp_locks,
20749- (unsigned long)__smp_locks_end);
20750+ PAGE_ALIGN((unsigned long)__smp_locks_end));
20751 #endif
20752
20753 apply_paravirt(__parainstructions, __parainstructions_end);
20754@@ -524,13 +548,17 @@ void __init alternative_instructions(void)
20755 * instructions. And on the local CPU you need to be protected again NMI or MCE
20756 * handlers seeing an inconsistent instruction while you patch.
20757 */
20758-void *__init_or_module text_poke_early(void *addr, const void *opcode,
20759+void *__kprobes text_poke_early(void *addr, const void *opcode,
20760 size_t len)
20761 {
20762 unsigned long flags;
20763 local_irq_save(flags);
20764- memcpy(addr, opcode, len);
20765+
20766+ pax_open_kernel();
20767+ memcpy(ktla_ktva(addr), opcode, len);
20768 sync_core();
20769+ pax_close_kernel();
20770+
20771 local_irq_restore(flags);
20772 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20773 that causes hangs on some VIA CPUs. */
20774@@ -552,36 +580,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20775 */
20776 void *text_poke(void *addr, const void *opcode, size_t len)
20777 {
20778- unsigned long flags;
20779- char *vaddr;
20780+ unsigned char *vaddr = ktla_ktva(addr);
20781 struct page *pages[2];
20782- int i;
20783+ size_t i;
20784
20785 if (!core_kernel_text((unsigned long)addr)) {
20786- pages[0] = vmalloc_to_page(addr);
20787- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20788+ pages[0] = vmalloc_to_page(vaddr);
20789+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20790 } else {
20791- pages[0] = virt_to_page(addr);
20792+ pages[0] = virt_to_page(vaddr);
20793 WARN_ON(!PageReserved(pages[0]));
20794- pages[1] = virt_to_page(addr + PAGE_SIZE);
20795+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20796 }
20797 BUG_ON(!pages[0]);
20798- local_irq_save(flags);
20799- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20800- if (pages[1])
20801- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20802- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20803- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20804- clear_fixmap(FIX_TEXT_POKE0);
20805- if (pages[1])
20806- clear_fixmap(FIX_TEXT_POKE1);
20807- local_flush_tlb();
20808- sync_core();
20809- /* Could also do a CLFLUSH here to speed up CPU recovery; but
20810- that causes hangs on some VIA CPUs. */
20811+ text_poke_early(addr, opcode, len);
20812 for (i = 0; i < len; i++)
20813- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20814- local_irq_restore(flags);
20815+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20816 return addr;
20817 }
20818
20819@@ -601,7 +615,7 @@ int poke_int3_handler(struct pt_regs *regs)
20820 if (likely(!bp_patching_in_progress))
20821 return 0;
20822
20823- if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20824+ if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20825 return 0;
20826
20827 /* set up the specified breakpoint handler */
20828@@ -635,7 +649,7 @@ int poke_int3_handler(struct pt_regs *regs)
20829 */
20830 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20831 {
20832- unsigned char int3 = 0xcc;
20833+ const unsigned char int3 = 0xcc;
20834
20835 bp_int3_handler = handler;
20836 bp_int3_addr = (u8 *)addr + sizeof(int3);
20837diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20838index ba6cc04..06fd971 100644
20839--- a/arch/x86/kernel/apic/apic.c
20840+++ b/arch/x86/kernel/apic/apic.c
20841@@ -201,7 +201,7 @@ int first_system_vector = 0xfe;
20842 /*
20843 * Debug level, exported for io_apic.c
20844 */
20845-unsigned int apic_verbosity;
20846+int apic_verbosity;
20847
20848 int pic_mode;
20849
20850@@ -1989,7 +1989,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20851 apic_write(APIC_ESR, 0);
20852 v = apic_read(APIC_ESR);
20853 ack_APIC_irq();
20854- atomic_inc(&irq_err_count);
20855+ atomic_inc_unchecked(&irq_err_count);
20856
20857 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
20858 smp_processor_id(), v);
20859diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20860index de918c4..32eed23 100644
20861--- a/arch/x86/kernel/apic/apic_flat_64.c
20862+++ b/arch/x86/kernel/apic/apic_flat_64.c
20863@@ -154,7 +154,7 @@ static int flat_probe(void)
20864 return 1;
20865 }
20866
20867-static struct apic apic_flat = {
20868+static struct apic apic_flat __read_only = {
20869 .name = "flat",
20870 .probe = flat_probe,
20871 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20872@@ -260,7 +260,7 @@ static int physflat_probe(void)
20873 return 0;
20874 }
20875
20876-static struct apic apic_physflat = {
20877+static struct apic apic_physflat __read_only = {
20878
20879 .name = "physical flat",
20880 .probe = physflat_probe,
20881diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20882index b205cdb..d8503ff 100644
20883--- a/arch/x86/kernel/apic/apic_noop.c
20884+++ b/arch/x86/kernel/apic/apic_noop.c
20885@@ -108,7 +108,7 @@ static void noop_apic_write(u32 reg, u32 v)
20886 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20887 }
20888
20889-struct apic apic_noop = {
20890+struct apic apic_noop __read_only = {
20891 .name = "noop",
20892 .probe = noop_probe,
20893 .acpi_madt_oem_check = NULL,
20894diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20895index c4a8d63..fe893ac 100644
20896--- a/arch/x86/kernel/apic/bigsmp_32.c
20897+++ b/arch/x86/kernel/apic/bigsmp_32.c
20898@@ -147,7 +147,7 @@ static int probe_bigsmp(void)
20899 return dmi_bigsmp;
20900 }
20901
20902-static struct apic apic_bigsmp = {
20903+static struct apic apic_bigsmp __read_only = {
20904
20905 .name = "bigsmp",
20906 .probe = probe_bigsmp,
20907diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20908index 1183d54..6158e47 100644
20909--- a/arch/x86/kernel/apic/io_apic.c
20910+++ b/arch/x86/kernel/apic/io_apic.c
20911@@ -1230,7 +1230,7 @@ out:
20912 }
20913 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20914
20915-void lock_vector_lock(void)
20916+void lock_vector_lock(void) __acquires(vector_lock)
20917 {
20918 /* Used to the online set of cpus does not change
20919 * during assign_irq_vector.
20920@@ -1238,7 +1238,7 @@ void lock_vector_lock(void)
20921 raw_spin_lock(&vector_lock);
20922 }
20923
20924-void unlock_vector_lock(void)
20925+void unlock_vector_lock(void) __releases(vector_lock)
20926 {
20927 raw_spin_unlock(&vector_lock);
20928 }
20929@@ -2465,7 +2465,7 @@ static void ack_apic_edge(struct irq_data *data)
20930 ack_APIC_irq();
20931 }
20932
20933-atomic_t irq_mis_count;
20934+atomic_unchecked_t irq_mis_count;
20935
20936 #ifdef CONFIG_GENERIC_PENDING_IRQ
20937 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20938@@ -2606,7 +2606,7 @@ static void ack_apic_level(struct irq_data *data)
20939 * at the cpu.
20940 */
20941 if (!(v & (1 << (i & 0x1f)))) {
20942- atomic_inc(&irq_mis_count);
20943+ atomic_inc_unchecked(&irq_mis_count);
20944
20945 eoi_ioapic_irq(irq, cfg);
20946 }
20947diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20948index bda4886..f9c7195 100644
20949--- a/arch/x86/kernel/apic/probe_32.c
20950+++ b/arch/x86/kernel/apic/probe_32.c
20951@@ -72,7 +72,7 @@ static int probe_default(void)
20952 return 1;
20953 }
20954
20955-static struct apic apic_default = {
20956+static struct apic apic_default __read_only = {
20957
20958 .name = "default",
20959 .probe = probe_default,
20960diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20961index e658f21..b695a1a 100644
20962--- a/arch/x86/kernel/apic/x2apic_cluster.c
20963+++ b/arch/x86/kernel/apic/x2apic_cluster.c
20964@@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20965 return notifier_from_errno(err);
20966 }
20967
20968-static struct notifier_block __refdata x2apic_cpu_notifier = {
20969+static struct notifier_block x2apic_cpu_notifier = {
20970 .notifier_call = update_clusterinfo,
20971 };
20972
20973@@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20974 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20975 }
20976
20977-static struct apic apic_x2apic_cluster = {
20978+static struct apic apic_x2apic_cluster __read_only = {
20979
20980 .name = "cluster x2apic",
20981 .probe = x2apic_cluster_probe,
20982diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20983index 6fae733..5ca17af 100644
20984--- a/arch/x86/kernel/apic/x2apic_phys.c
20985+++ b/arch/x86/kernel/apic/x2apic_phys.c
20986@@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
20987 return apic == &apic_x2apic_phys;
20988 }
20989
20990-static struct apic apic_x2apic_phys = {
20991+static struct apic apic_x2apic_phys __read_only = {
20992
20993 .name = "physical x2apic",
20994 .probe = x2apic_phys_probe,
20995diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
20996index 8e9dcfd..c61b3e4 100644
20997--- a/arch/x86/kernel/apic/x2apic_uv_x.c
20998+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
20999@@ -348,7 +348,7 @@ static int uv_probe(void)
21000 return apic == &apic_x2apic_uv_x;
21001 }
21002
21003-static struct apic __refdata apic_x2apic_uv_x = {
21004+static struct apic apic_x2apic_uv_x __read_only = {
21005
21006 .name = "UV large system",
21007 .probe = uv_probe,
21008diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
21009index 5848744..56cb598 100644
21010--- a/arch/x86/kernel/apm_32.c
21011+++ b/arch/x86/kernel/apm_32.c
21012@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
21013 * This is for buggy BIOS's that refer to (real mode) segment 0x40
21014 * even though they are called in protected mode.
21015 */
21016-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
21017+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
21018 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
21019
21020 static const char driver_version[] = "1.16ac"; /* no spaces */
21021@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
21022 BUG_ON(cpu != 0);
21023 gdt = get_cpu_gdt_table(cpu);
21024 save_desc_40 = gdt[0x40 / 8];
21025+
21026+ pax_open_kernel();
21027 gdt[0x40 / 8] = bad_bios_desc;
21028+ pax_close_kernel();
21029
21030 apm_irq_save(flags);
21031 APM_DO_SAVE_SEGS;
21032@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
21033 &call->esi);
21034 APM_DO_RESTORE_SEGS;
21035 apm_irq_restore(flags);
21036+
21037+ pax_open_kernel();
21038 gdt[0x40 / 8] = save_desc_40;
21039+ pax_close_kernel();
21040+
21041 put_cpu();
21042
21043 return call->eax & 0xff;
21044@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
21045 BUG_ON(cpu != 0);
21046 gdt = get_cpu_gdt_table(cpu);
21047 save_desc_40 = gdt[0x40 / 8];
21048+
21049+ pax_open_kernel();
21050 gdt[0x40 / 8] = bad_bios_desc;
21051+ pax_close_kernel();
21052
21053 apm_irq_save(flags);
21054 APM_DO_SAVE_SEGS;
21055@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
21056 &call->eax);
21057 APM_DO_RESTORE_SEGS;
21058 apm_irq_restore(flags);
21059+
21060+ pax_open_kernel();
21061 gdt[0x40 / 8] = save_desc_40;
21062+ pax_close_kernel();
21063+
21064 put_cpu();
21065 return error;
21066 }
21067@@ -2350,12 +2364,15 @@ static int __init apm_init(void)
21068 * code to that CPU.
21069 */
21070 gdt = get_cpu_gdt_table(0);
21071+
21072+ pax_open_kernel();
21073 set_desc_base(&gdt[APM_CS >> 3],
21074 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
21075 set_desc_base(&gdt[APM_CS_16 >> 3],
21076 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
21077 set_desc_base(&gdt[APM_DS >> 3],
21078 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
21079+ pax_close_kernel();
21080
21081 proc_create("apm", 0, NULL, &apm_file_ops);
21082
21083diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
21084index 9f6b934..cf5ffb3 100644
21085--- a/arch/x86/kernel/asm-offsets.c
21086+++ b/arch/x86/kernel/asm-offsets.c
21087@@ -32,6 +32,8 @@ void common(void) {
21088 OFFSET(TI_flags, thread_info, flags);
21089 OFFSET(TI_status, thread_info, status);
21090 OFFSET(TI_addr_limit, thread_info, addr_limit);
21091+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
21092+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
21093
21094 BLANK();
21095 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
21096@@ -52,8 +54,26 @@ void common(void) {
21097 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
21098 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
21099 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
21100+
21101+#ifdef CONFIG_PAX_KERNEXEC
21102+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
21103 #endif
21104
21105+#ifdef CONFIG_PAX_MEMORY_UDEREF
21106+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
21107+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
21108+#ifdef CONFIG_X86_64
21109+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
21110+#endif
21111+#endif
21112+
21113+#endif
21114+
21115+ BLANK();
21116+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
21117+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
21118+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
21119+
21120 #ifdef CONFIG_XEN
21121 BLANK();
21122 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
21123diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
21124index e7c798b..2b2019b 100644
21125--- a/arch/x86/kernel/asm-offsets_64.c
21126+++ b/arch/x86/kernel/asm-offsets_64.c
21127@@ -77,6 +77,7 @@ int main(void)
21128 BLANK();
21129 #undef ENTRY
21130
21131+ DEFINE(TSS_size, sizeof(struct tss_struct));
21132 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
21133 BLANK();
21134
21135diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
21136index e27b49d..85b106c 100644
21137--- a/arch/x86/kernel/cpu/Makefile
21138+++ b/arch/x86/kernel/cpu/Makefile
21139@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
21140 CFLAGS_REMOVE_perf_event.o = -pg
21141 endif
21142
21143-# Make sure load_percpu_segment has no stackprotector
21144-nostackp := $(call cc-option, -fno-stack-protector)
21145-CFLAGS_common.o := $(nostackp)
21146-
21147 obj-y := intel_cacheinfo.o scattered.o topology.o
21148 obj-y += common.o
21149 obj-y += rdrand.o
21150diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
21151index 813d29d..6e542d4 100644
21152--- a/arch/x86/kernel/cpu/amd.c
21153+++ b/arch/x86/kernel/cpu/amd.c
21154@@ -718,7 +718,7 @@ static void init_amd(struct cpuinfo_x86 *c)
21155 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
21156 {
21157 /* AMD errata T13 (order #21922) */
21158- if ((c->x86 == 6)) {
21159+ if (c->x86 == 6) {
21160 /* Duron Rev A0 */
21161 if (c->x86_model == 3 && c->x86_mask == 0)
21162 size = 64;
21163diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
21164index cfa9b5b..19b5084 100644
21165--- a/arch/x86/kernel/cpu/common.c
21166+++ b/arch/x86/kernel/cpu/common.c
21167@@ -90,60 +90,6 @@ static const struct cpu_dev default_cpu = {
21168
21169 static const struct cpu_dev *this_cpu = &default_cpu;
21170
21171-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
21172-#ifdef CONFIG_X86_64
21173- /*
21174- * We need valid kernel segments for data and code in long mode too
21175- * IRET will check the segment types kkeil 2000/10/28
21176- * Also sysret mandates a special GDT layout
21177- *
21178- * TLS descriptors are currently at a different place compared to i386.
21179- * Hopefully nobody expects them at a fixed place (Wine?)
21180- */
21181- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
21182- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
21183- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
21184- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
21185- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
21186- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
21187-#else
21188- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
21189- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21190- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
21191- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
21192- /*
21193- * Segments used for calling PnP BIOS have byte granularity.
21194- * They code segments and data segments have fixed 64k limits,
21195- * the transfer segment sizes are set at run time.
21196- */
21197- /* 32-bit code */
21198- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21199- /* 16-bit code */
21200- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21201- /* 16-bit data */
21202- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
21203- /* 16-bit data */
21204- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
21205- /* 16-bit data */
21206- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
21207- /*
21208- * The APM segments have byte granularity and their bases
21209- * are set at run time. All have 64k limits.
21210- */
21211- /* 32-bit code */
21212- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21213- /* 16-bit code */
21214- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21215- /* data */
21216- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
21217-
21218- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21219- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21220- GDT_STACK_CANARY_INIT
21221-#endif
21222-} };
21223-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
21224-
21225 static int __init x86_xsave_setup(char *s)
21226 {
21227 if (strlen(s))
21228@@ -305,6 +251,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
21229 }
21230 }
21231
21232+#ifdef CONFIG_X86_64
21233+static __init int setup_disable_pcid(char *arg)
21234+{
21235+ setup_clear_cpu_cap(X86_FEATURE_PCID);
21236+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
21237+
21238+#ifdef CONFIG_PAX_MEMORY_UDEREF
21239+ if (clone_pgd_mask != ~(pgdval_t)0UL)
21240+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21241+#endif
21242+
21243+ return 1;
21244+}
21245+__setup("nopcid", setup_disable_pcid);
21246+
21247+static void setup_pcid(struct cpuinfo_x86 *c)
21248+{
21249+ if (!cpu_has(c, X86_FEATURE_PCID)) {
21250+ clear_cpu_cap(c, X86_FEATURE_INVPCID);
21251+
21252+#ifdef CONFIG_PAX_MEMORY_UDEREF
21253+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
21254+ pax_open_kernel();
21255+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21256+ pax_close_kernel();
21257+ printk("PAX: slow and weak UDEREF enabled\n");
21258+ } else
21259+ printk("PAX: UDEREF disabled\n");
21260+#endif
21261+
21262+ return;
21263+ }
21264+
21265+ printk("PAX: PCID detected\n");
21266+ set_in_cr4(X86_CR4_PCIDE);
21267+
21268+#ifdef CONFIG_PAX_MEMORY_UDEREF
21269+ pax_open_kernel();
21270+ clone_pgd_mask = ~(pgdval_t)0UL;
21271+ pax_close_kernel();
21272+ if (pax_user_shadow_base)
21273+ printk("PAX: weak UDEREF enabled\n");
21274+ else {
21275+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
21276+ printk("PAX: strong UDEREF enabled\n");
21277+ }
21278+#endif
21279+
21280+ if (cpu_has(c, X86_FEATURE_INVPCID))
21281+ printk("PAX: INVPCID detected\n");
21282+}
21283+#endif
21284+
21285 /*
21286 * Some CPU features depend on higher CPUID levels, which may not always
21287 * be available due to CPUID level capping or broken virtualization
21288@@ -405,7 +404,7 @@ void switch_to_new_gdt(int cpu)
21289 {
21290 struct desc_ptr gdt_descr;
21291
21292- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
21293+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21294 gdt_descr.size = GDT_SIZE - 1;
21295 load_gdt(&gdt_descr);
21296 /* Reload the per-cpu base */
21297@@ -895,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21298 setup_smep(c);
21299 setup_smap(c);
21300
21301+#ifdef CONFIG_X86_64
21302+ setup_pcid(c);
21303+#endif
21304+
21305 /*
21306 * The vendor-specific functions might have changed features.
21307 * Now we do "generic changes."
21308@@ -903,6 +906,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21309 /* Filter out anything that depends on CPUID levels we don't have */
21310 filter_cpuid_features(c, true);
21311
21312+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21313+ setup_clear_cpu_cap(X86_FEATURE_SEP);
21314+#endif
21315+
21316 /* If the model name is still unset, do table lookup. */
21317 if (!c->x86_model_id[0]) {
21318 const char *p;
21319@@ -985,7 +992,7 @@ static void syscall32_cpu_init(void)
21320 void enable_sep_cpu(void)
21321 {
21322 int cpu = get_cpu();
21323- struct tss_struct *tss = &per_cpu(init_tss, cpu);
21324+ struct tss_struct *tss = init_tss + cpu;
21325
21326 if (!boot_cpu_has(X86_FEATURE_SEP)) {
21327 put_cpu();
21328@@ -1125,14 +1132,16 @@ static __init int setup_disablecpuid(char *arg)
21329 }
21330 __setup("clearcpuid=", setup_disablecpuid);
21331
21332+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
21333+EXPORT_PER_CPU_SYMBOL(current_tinfo);
21334+
21335 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21336- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21337+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21338 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21339
21340 #ifdef CONFIG_X86_64
21341-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21342-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
21343- (unsigned long) debug_idt_table };
21344+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21345+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
21346
21347 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21348 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21349@@ -1309,7 +1318,7 @@ void cpu_init(void)
21350 */
21351 load_ucode_ap();
21352
21353- t = &per_cpu(init_tss, cpu);
21354+ t = init_tss + cpu;
21355 oist = &per_cpu(orig_ist, cpu);
21356
21357 #ifdef CONFIG_NUMA
21358@@ -1341,7 +1350,6 @@ void cpu_init(void)
21359 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21360 barrier();
21361
21362- x86_configure_nx();
21363 enable_x2apic();
21364
21365 /*
21366@@ -1393,7 +1401,7 @@ void cpu_init(void)
21367 {
21368 int cpu = smp_processor_id();
21369 struct task_struct *curr = current;
21370- struct tss_struct *t = &per_cpu(init_tss, cpu);
21371+ struct tss_struct *t = init_tss + cpu;
21372 struct thread_struct *thread = &curr->thread;
21373
21374 wait_for_master_cpu(cpu);
21375diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21376index c703507..28535e3 100644
21377--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21378+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21379@@ -1026,6 +1026,22 @@ static struct attribute *default_attrs[] = {
21380 };
21381
21382 #ifdef CONFIG_AMD_NB
21383+static struct attribute *default_attrs_amd_nb[] = {
21384+ &type.attr,
21385+ &level.attr,
21386+ &coherency_line_size.attr,
21387+ &physical_line_partition.attr,
21388+ &ways_of_associativity.attr,
21389+ &number_of_sets.attr,
21390+ &size.attr,
21391+ &shared_cpu_map.attr,
21392+ &shared_cpu_list.attr,
21393+ NULL,
21394+ NULL,
21395+ NULL,
21396+ NULL
21397+};
21398+
21399 static struct attribute **amd_l3_attrs(void)
21400 {
21401 static struct attribute **attrs;
21402@@ -1036,18 +1052,7 @@ static struct attribute **amd_l3_attrs(void)
21403
21404 n = ARRAY_SIZE(default_attrs);
21405
21406- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21407- n += 2;
21408-
21409- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21410- n += 1;
21411-
21412- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21413- if (attrs == NULL)
21414- return attrs = default_attrs;
21415-
21416- for (n = 0; default_attrs[n]; n++)
21417- attrs[n] = default_attrs[n];
21418+ attrs = default_attrs_amd_nb;
21419
21420 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21421 attrs[n++] = &cache_disable_0.attr;
21422@@ -1098,6 +1103,13 @@ static struct kobj_type ktype_cache = {
21423 .default_attrs = default_attrs,
21424 };
21425
21426+#ifdef CONFIG_AMD_NB
21427+static struct kobj_type ktype_cache_amd_nb = {
21428+ .sysfs_ops = &sysfs_ops,
21429+ .default_attrs = default_attrs_amd_nb,
21430+};
21431+#endif
21432+
21433 static struct kobj_type ktype_percpu_entry = {
21434 .sysfs_ops = &sysfs_ops,
21435 };
21436@@ -1163,20 +1175,26 @@ static int cache_add_dev(struct device *dev)
21437 return retval;
21438 }
21439
21440+#ifdef CONFIG_AMD_NB
21441+ amd_l3_attrs();
21442+#endif
21443+
21444 for (i = 0; i < num_cache_leaves; i++) {
21445+ struct kobj_type *ktype;
21446+
21447 this_object = INDEX_KOBJECT_PTR(cpu, i);
21448 this_object->cpu = cpu;
21449 this_object->index = i;
21450
21451 this_leaf = CPUID4_INFO_IDX(cpu, i);
21452
21453- ktype_cache.default_attrs = default_attrs;
21454+ ktype = &ktype_cache;
21455 #ifdef CONFIG_AMD_NB
21456 if (this_leaf->base.nb)
21457- ktype_cache.default_attrs = amd_l3_attrs();
21458+ ktype = &ktype_cache_amd_nb;
21459 #endif
21460 retval = kobject_init_and_add(&(this_object->kobj),
21461- &ktype_cache,
21462+ ktype,
21463 per_cpu(ici_cache_kobject, cpu),
21464 "index%1lu", i);
21465 if (unlikely(retval)) {
21466diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21467index 61a9668ce..b446a37 100644
21468--- a/arch/x86/kernel/cpu/mcheck/mce.c
21469+++ b/arch/x86/kernel/cpu/mcheck/mce.c
21470@@ -45,6 +45,7 @@
21471 #include <asm/processor.h>
21472 #include <asm/mce.h>
21473 #include <asm/msr.h>
21474+#include <asm/local.h>
21475
21476 #include "mce-internal.h"
21477
21478@@ -259,7 +260,7 @@ static void print_mce(struct mce *m)
21479 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21480 m->cs, m->ip);
21481
21482- if (m->cs == __KERNEL_CS)
21483+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21484 print_symbol("{%s}", m->ip);
21485 pr_cont("\n");
21486 }
21487@@ -292,10 +293,10 @@ static void print_mce(struct mce *m)
21488
21489 #define PANIC_TIMEOUT 5 /* 5 seconds */
21490
21491-static atomic_t mce_paniced;
21492+static atomic_unchecked_t mce_paniced;
21493
21494 static int fake_panic;
21495-static atomic_t mce_fake_paniced;
21496+static atomic_unchecked_t mce_fake_paniced;
21497
21498 /* Panic in progress. Enable interrupts and wait for final IPI */
21499 static void wait_for_panic(void)
21500@@ -319,7 +320,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21501 /*
21502 * Make sure only one CPU runs in machine check panic
21503 */
21504- if (atomic_inc_return(&mce_paniced) > 1)
21505+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21506 wait_for_panic();
21507 barrier();
21508
21509@@ -327,7 +328,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21510 console_verbose();
21511 } else {
21512 /* Don't log too much for fake panic */
21513- if (atomic_inc_return(&mce_fake_paniced) > 1)
21514+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21515 return;
21516 }
21517 /* First print corrected ones that are still unlogged */
21518@@ -366,7 +367,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21519 if (!fake_panic) {
21520 if (panic_timeout == 0)
21521 panic_timeout = mca_cfg.panic_timeout;
21522- panic(msg);
21523+ panic("%s", msg);
21524 } else
21525 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21526 }
21527@@ -697,7 +698,7 @@ static int mce_timed_out(u64 *t)
21528 * might have been modified by someone else.
21529 */
21530 rmb();
21531- if (atomic_read(&mce_paniced))
21532+ if (atomic_read_unchecked(&mce_paniced))
21533 wait_for_panic();
21534 if (!mca_cfg.monarch_timeout)
21535 goto out;
21536@@ -1674,7 +1675,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21537 }
21538
21539 /* Call the installed machine check handler for this CPU setup. */
21540-void (*machine_check_vector)(struct pt_regs *, long error_code) =
21541+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21542 unexpected_machine_check;
21543
21544 /*
21545@@ -1697,7 +1698,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21546 return;
21547 }
21548
21549+ pax_open_kernel();
21550 machine_check_vector = do_machine_check;
21551+ pax_close_kernel();
21552
21553 __mcheck_cpu_init_generic();
21554 __mcheck_cpu_init_vendor(c);
21555@@ -1711,7 +1714,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21556 */
21557
21558 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21559-static int mce_chrdev_open_count; /* #times opened */
21560+static local_t mce_chrdev_open_count; /* #times opened */
21561 static int mce_chrdev_open_exclu; /* already open exclusive? */
21562
21563 static int mce_chrdev_open(struct inode *inode, struct file *file)
21564@@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21565 spin_lock(&mce_chrdev_state_lock);
21566
21567 if (mce_chrdev_open_exclu ||
21568- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21569+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21570 spin_unlock(&mce_chrdev_state_lock);
21571
21572 return -EBUSY;
21573@@ -1727,7 +1730,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21574
21575 if (file->f_flags & O_EXCL)
21576 mce_chrdev_open_exclu = 1;
21577- mce_chrdev_open_count++;
21578+ local_inc(&mce_chrdev_open_count);
21579
21580 spin_unlock(&mce_chrdev_state_lock);
21581
21582@@ -1738,7 +1741,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21583 {
21584 spin_lock(&mce_chrdev_state_lock);
21585
21586- mce_chrdev_open_count--;
21587+ local_dec(&mce_chrdev_open_count);
21588 mce_chrdev_open_exclu = 0;
21589
21590 spin_unlock(&mce_chrdev_state_lock);
21591@@ -2413,7 +2416,7 @@ static __init void mce_init_banks(void)
21592
21593 for (i = 0; i < mca_cfg.banks; i++) {
21594 struct mce_bank *b = &mce_banks[i];
21595- struct device_attribute *a = &b->attr;
21596+ device_attribute_no_const *a = &b->attr;
21597
21598 sysfs_attr_init(&a->attr);
21599 a->attr.name = b->attrname;
21600@@ -2520,7 +2523,7 @@ struct dentry *mce_get_debugfs_dir(void)
21601 static void mce_reset(void)
21602 {
21603 cpu_missing = 0;
21604- atomic_set(&mce_fake_paniced, 0);
21605+ atomic_set_unchecked(&mce_fake_paniced, 0);
21606 atomic_set(&mce_executing, 0);
21607 atomic_set(&mce_callin, 0);
21608 atomic_set(&global_nwo, 0);
21609diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21610index a304298..49b6d06 100644
21611--- a/arch/x86/kernel/cpu/mcheck/p5.c
21612+++ b/arch/x86/kernel/cpu/mcheck/p5.c
21613@@ -10,6 +10,7 @@
21614 #include <asm/processor.h>
21615 #include <asm/mce.h>
21616 #include <asm/msr.h>
21617+#include <asm/pgtable.h>
21618
21619 /* By default disabled */
21620 int mce_p5_enabled __read_mostly;
21621@@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21622 if (!cpu_has(c, X86_FEATURE_MCE))
21623 return;
21624
21625+ pax_open_kernel();
21626 machine_check_vector = pentium_machine_check;
21627+ pax_close_kernel();
21628 /* Make sure the vector pointer is visible before we enable MCEs: */
21629 wmb();
21630
21631diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21632index 7dc5564..1273569 100644
21633--- a/arch/x86/kernel/cpu/mcheck/winchip.c
21634+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21635@@ -9,6 +9,7 @@
21636 #include <asm/processor.h>
21637 #include <asm/mce.h>
21638 #include <asm/msr.h>
21639+#include <asm/pgtable.h>
21640
21641 /* Machine check handler for WinChip C6: */
21642 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21643@@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21644 {
21645 u32 lo, hi;
21646
21647+ pax_open_kernel();
21648 machine_check_vector = winchip_machine_check;
21649+ pax_close_kernel();
21650 /* Make sure the vector pointer is visible before we enable MCEs: */
21651 wmb();
21652
21653diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21654index 08fe6e8..35885b0 100644
21655--- a/arch/x86/kernel/cpu/microcode/core.c
21656+++ b/arch/x86/kernel/cpu/microcode/core.c
21657@@ -526,7 +526,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21658 return NOTIFY_OK;
21659 }
21660
21661-static struct notifier_block __refdata mc_cpu_notifier = {
21662+static struct notifier_block mc_cpu_notifier = {
21663 .notifier_call = mc_cpu_callback,
21664 };
21665
21666diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21667index c6826d1..ad18e14a 100644
21668--- a/arch/x86/kernel/cpu/microcode/intel.c
21669+++ b/arch/x86/kernel/cpu/microcode/intel.c
21670@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21671
21672 static int get_ucode_user(void *to, const void *from, size_t n)
21673 {
21674- return copy_from_user(to, from, n);
21675+ return copy_from_user(to, (const void __force_user *)from, n);
21676 }
21677
21678 static enum ucode_state
21679 request_microcode_user(int cpu, const void __user *buf, size_t size)
21680 {
21681- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21682+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21683 }
21684
21685 static void microcode_fini_cpu(int cpu)
21686diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21687index ea5f363..cb0e905 100644
21688--- a/arch/x86/kernel/cpu/mtrr/main.c
21689+++ b/arch/x86/kernel/cpu/mtrr/main.c
21690@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21691 u64 size_or_mask, size_and_mask;
21692 static bool mtrr_aps_delayed_init;
21693
21694-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21695+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21696
21697 const struct mtrr_ops *mtrr_if;
21698
21699diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21700index df5e41f..816c719 100644
21701--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21702+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21703@@ -25,7 +25,7 @@ struct mtrr_ops {
21704 int (*validate_add_page)(unsigned long base, unsigned long size,
21705 unsigned int type);
21706 int (*have_wrcomb)(void);
21707-};
21708+} __do_const;
21709
21710 extern int generic_get_free_region(unsigned long base, unsigned long size,
21711 int replace_reg);
21712diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21713index 143e5f5..5825081 100644
21714--- a/arch/x86/kernel/cpu/perf_event.c
21715+++ b/arch/x86/kernel/cpu/perf_event.c
21716@@ -1374,7 +1374,7 @@ static void __init pmu_check_apic(void)
21717
21718 }
21719
21720-static struct attribute_group x86_pmu_format_group = {
21721+static attribute_group_no_const x86_pmu_format_group = {
21722 .name = "format",
21723 .attrs = NULL,
21724 };
21725@@ -1473,7 +1473,7 @@ static struct attribute *events_attr[] = {
21726 NULL,
21727 };
21728
21729-static struct attribute_group x86_pmu_events_group = {
21730+static attribute_group_no_const x86_pmu_events_group = {
21731 .name = "events",
21732 .attrs = events_attr,
21733 };
21734@@ -1997,7 +1997,7 @@ static unsigned long get_segment_base(unsigned int segment)
21735 if (idx > GDT_ENTRIES)
21736 return 0;
21737
21738- desc = raw_cpu_ptr(gdt_page.gdt);
21739+ desc = get_cpu_gdt_table(smp_processor_id());
21740 }
21741
21742 return get_desc_base(desc + idx);
21743@@ -2087,7 +2087,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21744 break;
21745
21746 perf_callchain_store(entry, frame.return_address);
21747- fp = frame.next_frame;
21748+ fp = (const void __force_user *)frame.next_frame;
21749 }
21750 }
21751
21752diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21753index 639d128..e92d7e5 100644
21754--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21755+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21756@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21757 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21758 {
21759 struct attribute **attrs;
21760- struct attribute_group *attr_group;
21761+ attribute_group_no_const *attr_group;
21762 int i = 0, j;
21763
21764 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21765diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21766index 944bf01..4a4392f 100644
21767--- a/arch/x86/kernel/cpu/perf_event_intel.c
21768+++ b/arch/x86/kernel/cpu/perf_event_intel.c
21769@@ -2353,10 +2353,10 @@ __init int intel_pmu_init(void)
21770 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
21771
21772 if (boot_cpu_has(X86_FEATURE_PDCM)) {
21773- u64 capabilities;
21774+ u64 capabilities = x86_pmu.intel_cap.capabilities;
21775
21776- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21777- x86_pmu.intel_cap.capabilities = capabilities;
21778+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21779+ x86_pmu.intel_cap.capabilities = capabilities;
21780 }
21781
21782 intel_ds_init();
21783diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21784index d64f275..26522ff 100644
21785--- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21786+++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21787@@ -449,7 +449,7 @@ static struct attribute *rapl_events_hsw_attr[] = {
21788 NULL,
21789 };
21790
21791-static struct attribute_group rapl_pmu_events_group = {
21792+static attribute_group_no_const rapl_pmu_events_group __read_only = {
21793 .name = "events",
21794 .attrs = NULL, /* patched at runtime */
21795 };
21796diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21797index 9762dbd..53d5d21 100644
21798--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21799+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21800@@ -721,7 +721,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21801 static int __init uncore_type_init(struct intel_uncore_type *type)
21802 {
21803 struct intel_uncore_pmu *pmus;
21804- struct attribute_group *attr_group;
21805+ attribute_group_no_const *attr_group;
21806 struct attribute **attrs;
21807 int i, j;
21808
21809diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21810index 18eb78b..18747cc 100644
21811--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21812+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21813@@ -114,7 +114,7 @@ struct intel_uncore_box {
21814 struct uncore_event_desc {
21815 struct kobj_attribute attr;
21816 const char *config;
21817-};
21818+} __do_const;
21819
21820 ssize_t uncore_event_show(struct kobject *kobj,
21821 struct kobj_attribute *attr, char *buf);
21822diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21823index 3225ae6c..ee3c6db 100644
21824--- a/arch/x86/kernel/cpuid.c
21825+++ b/arch/x86/kernel/cpuid.c
21826@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21827 return notifier_from_errno(err);
21828 }
21829
21830-static struct notifier_block __refdata cpuid_class_cpu_notifier =
21831+static struct notifier_block cpuid_class_cpu_notifier =
21832 {
21833 .notifier_call = cpuid_class_cpu_callback,
21834 };
21835diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21836index f5ab56d..d3b201a 100644
21837--- a/arch/x86/kernel/crash.c
21838+++ b/arch/x86/kernel/crash.c
21839@@ -104,7 +104,7 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21840 #ifdef CONFIG_X86_32
21841 struct pt_regs fixed_regs;
21842
21843- if (!user_mode_vm(regs)) {
21844+ if (!user_mode(regs)) {
21845 crash_fixup_ss_esp(&fixed_regs, regs);
21846 regs = &fixed_regs;
21847 }
21848diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21849index afa64ad..dce67dd 100644
21850--- a/arch/x86/kernel/crash_dump_64.c
21851+++ b/arch/x86/kernel/crash_dump_64.c
21852@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21853 return -ENOMEM;
21854
21855 if (userbuf) {
21856- if (copy_to_user(buf, vaddr + offset, csize)) {
21857+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21858 iounmap(vaddr);
21859 return -EFAULT;
21860 }
21861diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21862index f6dfd93..892ade4 100644
21863--- a/arch/x86/kernel/doublefault.c
21864+++ b/arch/x86/kernel/doublefault.c
21865@@ -12,7 +12,7 @@
21866
21867 #define DOUBLEFAULT_STACKSIZE (1024)
21868 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21869-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21870+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21871
21872 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21873
21874@@ -22,7 +22,7 @@ static void doublefault_fn(void)
21875 unsigned long gdt, tss;
21876
21877 native_store_gdt(&gdt_desc);
21878- gdt = gdt_desc.address;
21879+ gdt = (unsigned long)gdt_desc.address;
21880
21881 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21882
21883@@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21884 /* 0x2 bit is always set */
21885 .flags = X86_EFLAGS_SF | 0x2,
21886 .sp = STACK_START,
21887- .es = __USER_DS,
21888+ .es = __KERNEL_DS,
21889 .cs = __KERNEL_CS,
21890 .ss = __KERNEL_DS,
21891- .ds = __USER_DS,
21892+ .ds = __KERNEL_DS,
21893 .fs = __KERNEL_PERCPU,
21894
21895 .__cr3 = __pa_nodebug(swapper_pg_dir),
21896diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21897index b74ebc7..2c95874 100644
21898--- a/arch/x86/kernel/dumpstack.c
21899+++ b/arch/x86/kernel/dumpstack.c
21900@@ -2,6 +2,9 @@
21901 * Copyright (C) 1991, 1992 Linus Torvalds
21902 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21903 */
21904+#ifdef CONFIG_GRKERNSEC_HIDESYM
21905+#define __INCLUDED_BY_HIDESYM 1
21906+#endif
21907 #include <linux/kallsyms.h>
21908 #include <linux/kprobes.h>
21909 #include <linux/uaccess.h>
21910@@ -33,23 +36,21 @@ static void printk_stack_address(unsigned long address, int reliable)
21911
21912 void printk_address(unsigned long address)
21913 {
21914- pr_cont(" [<%p>] %pS\n", (void *)address, (void *)address);
21915+ pr_cont(" [<%p>] %pA\n", (void *)address, (void *)address);
21916 }
21917
21918 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
21919 static void
21920 print_ftrace_graph_addr(unsigned long addr, void *data,
21921 const struct stacktrace_ops *ops,
21922- struct thread_info *tinfo, int *graph)
21923+ struct task_struct *task, int *graph)
21924 {
21925- struct task_struct *task;
21926 unsigned long ret_addr;
21927 int index;
21928
21929 if (addr != (unsigned long)return_to_handler)
21930 return;
21931
21932- task = tinfo->task;
21933 index = task->curr_ret_stack;
21934
21935 if (!task->ret_stack || index < *graph)
21936@@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21937 static inline void
21938 print_ftrace_graph_addr(unsigned long addr, void *data,
21939 const struct stacktrace_ops *ops,
21940- struct thread_info *tinfo, int *graph)
21941+ struct task_struct *task, int *graph)
21942 { }
21943 #endif
21944
21945@@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21946 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21947 */
21948
21949-static inline int valid_stack_ptr(struct thread_info *tinfo,
21950- void *p, unsigned int size, void *end)
21951+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21952 {
21953- void *t = tinfo;
21954 if (end) {
21955 if (p < end && p >= (end-THREAD_SIZE))
21956 return 1;
21957@@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21958 }
21959
21960 unsigned long
21961-print_context_stack(struct thread_info *tinfo,
21962+print_context_stack(struct task_struct *task, void *stack_start,
21963 unsigned long *stack, unsigned long bp,
21964 const struct stacktrace_ops *ops, void *data,
21965 unsigned long *end, int *graph)
21966 {
21967 struct stack_frame *frame = (struct stack_frame *)bp;
21968
21969- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21970+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21971 unsigned long addr;
21972
21973 addr = *stack;
21974@@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21975 } else {
21976 ops->address(data, addr, 0);
21977 }
21978- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21979+ print_ftrace_graph_addr(addr, data, ops, task, graph);
21980 }
21981 stack++;
21982 }
21983@@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
21984 EXPORT_SYMBOL_GPL(print_context_stack);
21985
21986 unsigned long
21987-print_context_stack_bp(struct thread_info *tinfo,
21988+print_context_stack_bp(struct task_struct *task, void *stack_start,
21989 unsigned long *stack, unsigned long bp,
21990 const struct stacktrace_ops *ops, void *data,
21991 unsigned long *end, int *graph)
21992@@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21993 struct stack_frame *frame = (struct stack_frame *)bp;
21994 unsigned long *ret_addr = &frame->return_address;
21995
21996- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
21997+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
21998 unsigned long addr = *ret_addr;
21999
22000 if (!__kernel_text_address(addr))
22001@@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22002 ops->address(data, addr, 1);
22003 frame = frame->next_frame;
22004 ret_addr = &frame->return_address;
22005- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22006+ print_ftrace_graph_addr(addr, data, ops, task, graph);
22007 }
22008
22009 return (unsigned long)frame;
22010@@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
22011 static void print_trace_address(void *data, unsigned long addr, int reliable)
22012 {
22013 touch_nmi_watchdog();
22014- printk(data);
22015+ printk("%s", (char *)data);
22016 printk_stack_address(addr, reliable);
22017 }
22018
22019@@ -225,6 +224,8 @@ unsigned long oops_begin(void)
22020 EXPORT_SYMBOL_GPL(oops_begin);
22021 NOKPROBE_SYMBOL(oops_begin);
22022
22023+extern void gr_handle_kernel_exploit(void);
22024+
22025 void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22026 {
22027 if (regs && kexec_should_crash(current))
22028@@ -246,7 +247,10 @@ void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22029 panic("Fatal exception in interrupt");
22030 if (panic_on_oops)
22031 panic("Fatal exception");
22032- do_exit(signr);
22033+
22034+ gr_handle_kernel_exploit();
22035+
22036+ do_group_exit(signr);
22037 }
22038 NOKPROBE_SYMBOL(oops_end);
22039
22040@@ -275,7 +279,7 @@ int __die(const char *str, struct pt_regs *regs, long err)
22041 print_modules();
22042 show_regs(regs);
22043 #ifdef CONFIG_X86_32
22044- if (user_mode_vm(regs)) {
22045+ if (user_mode(regs)) {
22046 sp = regs->sp;
22047 ss = regs->ss & 0xffff;
22048 } else {
22049@@ -304,7 +308,7 @@ void die(const char *str, struct pt_regs *regs, long err)
22050 unsigned long flags = oops_begin();
22051 int sig = SIGSEGV;
22052
22053- if (!user_mode_vm(regs))
22054+ if (!user_mode(regs))
22055 report_bug(regs->ip, regs);
22056
22057 if (__die(str, regs, err))
22058diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
22059index 5abd4cd..c65733b 100644
22060--- a/arch/x86/kernel/dumpstack_32.c
22061+++ b/arch/x86/kernel/dumpstack_32.c
22062@@ -61,15 +61,14 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22063 bp = stack_frame(task, regs);
22064
22065 for (;;) {
22066- struct thread_info *context;
22067+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22068 void *end_stack;
22069
22070 end_stack = is_hardirq_stack(stack, cpu);
22071 if (!end_stack)
22072 end_stack = is_softirq_stack(stack, cpu);
22073
22074- context = task_thread_info(task);
22075- bp = ops->walk_stack(context, stack, bp, ops, data,
22076+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data,
22077 end_stack, &graph);
22078
22079 /* Stop if not on irq stack */
22080@@ -123,27 +122,28 @@ void show_regs(struct pt_regs *regs)
22081 int i;
22082
22083 show_regs_print_info(KERN_EMERG);
22084- __show_regs(regs, !user_mode_vm(regs));
22085+ __show_regs(regs, !user_mode(regs));
22086
22087 /*
22088 * When in-kernel, we also print out the stack and code at the
22089 * time of the fault..
22090 */
22091- if (!user_mode_vm(regs)) {
22092+ if (!user_mode(regs)) {
22093 unsigned int code_prologue = code_bytes * 43 / 64;
22094 unsigned int code_len = code_bytes;
22095 unsigned char c;
22096 u8 *ip;
22097+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
22098
22099 pr_emerg("Stack:\n");
22100 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
22101
22102 pr_emerg("Code:");
22103
22104- ip = (u8 *)regs->ip - code_prologue;
22105+ ip = (u8 *)regs->ip - code_prologue + cs_base;
22106 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
22107 /* try starting at IP */
22108- ip = (u8 *)regs->ip;
22109+ ip = (u8 *)regs->ip + cs_base;
22110 code_len = code_len - code_prologue + 1;
22111 }
22112 for (i = 0; i < code_len; i++, ip++) {
22113@@ -152,7 +152,7 @@ void show_regs(struct pt_regs *regs)
22114 pr_cont(" Bad EIP value.");
22115 break;
22116 }
22117- if (ip == (u8 *)regs->ip)
22118+ if (ip == (u8 *)regs->ip + cs_base)
22119 pr_cont(" <%02x>", c);
22120 else
22121 pr_cont(" %02x", c);
22122@@ -165,6 +165,7 @@ int is_valid_bugaddr(unsigned long ip)
22123 {
22124 unsigned short ud2;
22125
22126+ ip = ktla_ktva(ip);
22127 if (ip < PAGE_OFFSET)
22128 return 0;
22129 if (probe_kernel_address((unsigned short *)ip, ud2))
22130@@ -172,3 +173,15 @@ int is_valid_bugaddr(unsigned long ip)
22131
22132 return ud2 == 0x0b0f;
22133 }
22134+
22135+#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22136+void pax_check_alloca(unsigned long size)
22137+{
22138+ unsigned long sp = (unsigned long)&sp, stack_left;
22139+
22140+ /* all kernel stacks are of the same size */
22141+ stack_left = sp & (THREAD_SIZE - 1);
22142+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22143+}
22144+EXPORT_SYMBOL(pax_check_alloca);
22145+#endif
22146diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
22147index ff86f19..a20c62c 100644
22148--- a/arch/x86/kernel/dumpstack_64.c
22149+++ b/arch/x86/kernel/dumpstack_64.c
22150@@ -153,12 +153,12 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22151 const struct stacktrace_ops *ops, void *data)
22152 {
22153 const unsigned cpu = get_cpu();
22154- struct thread_info *tinfo;
22155 unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
22156 unsigned long dummy;
22157 unsigned used = 0;
22158 int graph = 0;
22159 int done = 0;
22160+ void *stack_start;
22161
22162 if (!task)
22163 task = current;
22164@@ -179,7 +179,6 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22165 * current stack address. If the stacks consist of nested
22166 * exceptions
22167 */
22168- tinfo = task_thread_info(task);
22169 while (!done) {
22170 unsigned long *stack_end;
22171 enum stack_type stype;
22172@@ -202,7 +201,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22173 if (ops->stack(data, id) < 0)
22174 break;
22175
22176- bp = ops->walk_stack(tinfo, stack, bp, ops,
22177+ bp = ops->walk_stack(task, stack_end - EXCEPTION_STKSZ, stack, bp, ops,
22178 data, stack_end, &graph);
22179 ops->stack(data, "<EOE>");
22180 /*
22181@@ -210,6 +209,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22182 * second-to-last pointer (index -2 to end) in the
22183 * exception stack:
22184 */
22185+ if ((u16)stack_end[-1] != __KERNEL_DS)
22186+ goto out;
22187 stack = (unsigned long *) stack_end[-2];
22188 done = 0;
22189 break;
22190@@ -218,7 +219,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22191
22192 if (ops->stack(data, "IRQ") < 0)
22193 break;
22194- bp = ops->walk_stack(tinfo, stack, bp,
22195+ bp = ops->walk_stack(task, irq_stack, stack, bp,
22196 ops, data, stack_end, &graph);
22197 /*
22198 * We link to the next stack (which would be
22199@@ -240,7 +241,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22200 /*
22201 * This handles the process stack:
22202 */
22203- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
22204+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22205+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
22206+out:
22207 put_cpu();
22208 }
22209 EXPORT_SYMBOL(dump_trace);
22210@@ -349,3 +352,50 @@ int is_valid_bugaddr(unsigned long ip)
22211
22212 return ud2 == 0x0b0f;
22213 }
22214+
22215+#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22216+void pax_check_alloca(unsigned long size)
22217+{
22218+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
22219+ unsigned cpu, used;
22220+ char *id;
22221+
22222+ /* check the process stack first */
22223+ stack_start = (unsigned long)task_stack_page(current);
22224+ stack_end = stack_start + THREAD_SIZE;
22225+ if (likely(stack_start <= sp && sp < stack_end)) {
22226+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
22227+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22228+ return;
22229+ }
22230+
22231+ cpu = get_cpu();
22232+
22233+ /* check the irq stacks */
22234+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
22235+ stack_start = stack_end - IRQ_STACK_SIZE;
22236+ if (stack_start <= sp && sp < stack_end) {
22237+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
22238+ put_cpu();
22239+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22240+ return;
22241+ }
22242+
22243+ /* check the exception stacks */
22244+ used = 0;
22245+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
22246+ stack_start = stack_end - EXCEPTION_STKSZ;
22247+ if (stack_end && stack_start <= sp && sp < stack_end) {
22248+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
22249+ put_cpu();
22250+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22251+ return;
22252+ }
22253+
22254+ put_cpu();
22255+
22256+ /* unknown stack */
22257+ BUG();
22258+}
22259+EXPORT_SYMBOL(pax_check_alloca);
22260+#endif
22261diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
22262index 49f8864..1cc6d07 100644
22263--- a/arch/x86/kernel/e820.c
22264+++ b/arch/x86/kernel/e820.c
22265@@ -802,8 +802,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
22266
22267 static void early_panic(char *msg)
22268 {
22269- early_printk(msg);
22270- panic(msg);
22271+ early_printk("%s", msg);
22272+ panic("%s", msg);
22273 }
22274
22275 static int userdef __initdata;
22276diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
22277index 01d1c18..8073693 100644
22278--- a/arch/x86/kernel/early_printk.c
22279+++ b/arch/x86/kernel/early_printk.c
22280@@ -7,6 +7,7 @@
22281 #include <linux/pci_regs.h>
22282 #include <linux/pci_ids.h>
22283 #include <linux/errno.h>
22284+#include <linux/sched.h>
22285 #include <asm/io.h>
22286 #include <asm/processor.h>
22287 #include <asm/fcntl.h>
22288diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
22289index 344b63f..ccdac7a 100644
22290--- a/arch/x86/kernel/entry_32.S
22291+++ b/arch/x86/kernel/entry_32.S
22292@@ -177,13 +177,153 @@
22293 /*CFI_REL_OFFSET gs, PT_GS*/
22294 .endm
22295 .macro SET_KERNEL_GS reg
22296+
22297+#ifdef CONFIG_CC_STACKPROTECTOR
22298 movl $(__KERNEL_STACK_CANARY), \reg
22299+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22300+ movl $(__USER_DS), \reg
22301+#else
22302+ xorl \reg, \reg
22303+#endif
22304+
22305 movl \reg, %gs
22306 .endm
22307
22308 #endif /* CONFIG_X86_32_LAZY_GS */
22309
22310-.macro SAVE_ALL
22311+.macro pax_enter_kernel
22312+#ifdef CONFIG_PAX_KERNEXEC
22313+ call pax_enter_kernel
22314+#endif
22315+.endm
22316+
22317+.macro pax_exit_kernel
22318+#ifdef CONFIG_PAX_KERNEXEC
22319+ call pax_exit_kernel
22320+#endif
22321+.endm
22322+
22323+#ifdef CONFIG_PAX_KERNEXEC
22324+ENTRY(pax_enter_kernel)
22325+#ifdef CONFIG_PARAVIRT
22326+ pushl %eax
22327+ pushl %ecx
22328+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
22329+ mov %eax, %esi
22330+#else
22331+ mov %cr0, %esi
22332+#endif
22333+ bts $16, %esi
22334+ jnc 1f
22335+ mov %cs, %esi
22336+ cmp $__KERNEL_CS, %esi
22337+ jz 3f
22338+ ljmp $__KERNEL_CS, $3f
22339+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
22340+2:
22341+#ifdef CONFIG_PARAVIRT
22342+ mov %esi, %eax
22343+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
22344+#else
22345+ mov %esi, %cr0
22346+#endif
22347+3:
22348+#ifdef CONFIG_PARAVIRT
22349+ popl %ecx
22350+ popl %eax
22351+#endif
22352+ ret
22353+ENDPROC(pax_enter_kernel)
22354+
22355+ENTRY(pax_exit_kernel)
22356+#ifdef CONFIG_PARAVIRT
22357+ pushl %eax
22358+ pushl %ecx
22359+#endif
22360+ mov %cs, %esi
22361+ cmp $__KERNEXEC_KERNEL_CS, %esi
22362+ jnz 2f
22363+#ifdef CONFIG_PARAVIRT
22364+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
22365+ mov %eax, %esi
22366+#else
22367+ mov %cr0, %esi
22368+#endif
22369+ btr $16, %esi
22370+ ljmp $__KERNEL_CS, $1f
22371+1:
22372+#ifdef CONFIG_PARAVIRT
22373+ mov %esi, %eax
22374+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
22375+#else
22376+ mov %esi, %cr0
22377+#endif
22378+2:
22379+#ifdef CONFIG_PARAVIRT
22380+ popl %ecx
22381+ popl %eax
22382+#endif
22383+ ret
22384+ENDPROC(pax_exit_kernel)
22385+#endif
22386+
22387+ .macro pax_erase_kstack
22388+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22389+ call pax_erase_kstack
22390+#endif
22391+ .endm
22392+
22393+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22394+/*
22395+ * ebp: thread_info
22396+ */
22397+ENTRY(pax_erase_kstack)
22398+ pushl %edi
22399+ pushl %ecx
22400+ pushl %eax
22401+
22402+ mov TI_lowest_stack(%ebp), %edi
22403+ mov $-0xBEEF, %eax
22404+ std
22405+
22406+1: mov %edi, %ecx
22407+ and $THREAD_SIZE_asm - 1, %ecx
22408+ shr $2, %ecx
22409+ repne scasl
22410+ jecxz 2f
22411+
22412+ cmp $2*16, %ecx
22413+ jc 2f
22414+
22415+ mov $2*16, %ecx
22416+ repe scasl
22417+ jecxz 2f
22418+ jne 1b
22419+
22420+2: cld
22421+ mov %esp, %ecx
22422+ sub %edi, %ecx
22423+
22424+ cmp $THREAD_SIZE_asm, %ecx
22425+ jb 3f
22426+ ud2
22427+3:
22428+
22429+ shr $2, %ecx
22430+ rep stosl
22431+
22432+ mov TI_task_thread_sp0(%ebp), %edi
22433+ sub $128, %edi
22434+ mov %edi, TI_lowest_stack(%ebp)
22435+
22436+ popl %eax
22437+ popl %ecx
22438+ popl %edi
22439+ ret
22440+ENDPROC(pax_erase_kstack)
22441+#endif
22442+
22443+.macro __SAVE_ALL _DS
22444 cld
22445 PUSH_GS
22446 pushl_cfi %fs
22447@@ -206,7 +346,7 @@
22448 CFI_REL_OFFSET ecx, 0
22449 pushl_cfi %ebx
22450 CFI_REL_OFFSET ebx, 0
22451- movl $(__USER_DS), %edx
22452+ movl $\_DS, %edx
22453 movl %edx, %ds
22454 movl %edx, %es
22455 movl $(__KERNEL_PERCPU), %edx
22456@@ -214,6 +354,15 @@
22457 SET_KERNEL_GS %edx
22458 .endm
22459
22460+.macro SAVE_ALL
22461+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22462+ __SAVE_ALL __KERNEL_DS
22463+ pax_enter_kernel
22464+#else
22465+ __SAVE_ALL __USER_DS
22466+#endif
22467+.endm
22468+
22469 .macro RESTORE_INT_REGS
22470 popl_cfi %ebx
22471 CFI_RESTORE ebx
22472@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22473 popfl_cfi
22474 jmp syscall_exit
22475 CFI_ENDPROC
22476-END(ret_from_fork)
22477+ENDPROC(ret_from_fork)
22478
22479 ENTRY(ret_from_kernel_thread)
22480 CFI_STARTPROC
22481@@ -340,7 +489,15 @@ ret_from_intr:
22482 andl $SEGMENT_RPL_MASK, %eax
22483 #endif
22484 cmpl $USER_RPL, %eax
22485+
22486+#ifdef CONFIG_PAX_KERNEXEC
22487+ jae resume_userspace
22488+
22489+ pax_exit_kernel
22490+ jmp resume_kernel
22491+#else
22492 jb resume_kernel # not returning to v8086 or userspace
22493+#endif
22494
22495 ENTRY(resume_userspace)
22496 LOCKDEP_SYS_EXIT
22497@@ -352,8 +509,8 @@ ENTRY(resume_userspace)
22498 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22499 # int/exception return?
22500 jne work_pending
22501- jmp restore_all
22502-END(ret_from_exception)
22503+ jmp restore_all_pax
22504+ENDPROC(ret_from_exception)
22505
22506 #ifdef CONFIG_PREEMPT
22507 ENTRY(resume_kernel)
22508@@ -365,7 +522,7 @@ need_resched:
22509 jz restore_all
22510 call preempt_schedule_irq
22511 jmp need_resched
22512-END(resume_kernel)
22513+ENDPROC(resume_kernel)
22514 #endif
22515 CFI_ENDPROC
22516
22517@@ -395,30 +552,45 @@ sysenter_past_esp:
22518 /*CFI_REL_OFFSET cs, 0*/
22519 /*
22520 * Push current_thread_info()->sysenter_return to the stack.
22521- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22522- * pushed above; +8 corresponds to copy_thread's esp0 setting.
22523 */
22524- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22525+ pushl_cfi $0
22526 CFI_REL_OFFSET eip, 0
22527
22528 pushl_cfi %eax
22529 SAVE_ALL
22530+ GET_THREAD_INFO(%ebp)
22531+ movl TI_sysenter_return(%ebp),%ebp
22532+ movl %ebp,PT_EIP(%esp)
22533 ENABLE_INTERRUPTS(CLBR_NONE)
22534
22535 /*
22536 * Load the potential sixth argument from user stack.
22537 * Careful about security.
22538 */
22539+ movl PT_OLDESP(%esp),%ebp
22540+
22541+#ifdef CONFIG_PAX_MEMORY_UDEREF
22542+ mov PT_OLDSS(%esp),%ds
22543+1: movl %ds:(%ebp),%ebp
22544+ push %ss
22545+ pop %ds
22546+#else
22547 cmpl $__PAGE_OFFSET-3,%ebp
22548 jae syscall_fault
22549 ASM_STAC
22550 1: movl (%ebp),%ebp
22551 ASM_CLAC
22552+#endif
22553+
22554 movl %ebp,PT_EBP(%esp)
22555 _ASM_EXTABLE(1b,syscall_fault)
22556
22557 GET_THREAD_INFO(%ebp)
22558
22559+#ifdef CONFIG_PAX_RANDKSTACK
22560+ pax_erase_kstack
22561+#endif
22562+
22563 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22564 jnz sysenter_audit
22565 sysenter_do_call:
22566@@ -434,12 +606,24 @@ sysenter_after_call:
22567 testl $_TIF_ALLWORK_MASK, %ecx
22568 jne sysexit_audit
22569 sysenter_exit:
22570+
22571+#ifdef CONFIG_PAX_RANDKSTACK
22572+ pushl_cfi %eax
22573+ movl %esp, %eax
22574+ call pax_randomize_kstack
22575+ popl_cfi %eax
22576+#endif
22577+
22578+ pax_erase_kstack
22579+
22580 /* if something modifies registers it must also disable sysexit */
22581 movl PT_EIP(%esp), %edx
22582 movl PT_OLDESP(%esp), %ecx
22583 xorl %ebp,%ebp
22584 TRACE_IRQS_ON
22585 1: mov PT_FS(%esp), %fs
22586+2: mov PT_DS(%esp), %ds
22587+3: mov PT_ES(%esp), %es
22588 PTGS_TO_GS
22589 ENABLE_INTERRUPTS_SYSEXIT
22590
22591@@ -453,6 +637,9 @@ sysenter_audit:
22592 pushl_cfi PT_ESI(%esp) /* a3: 5th arg */
22593 pushl_cfi PT_EDX+4(%esp) /* a2: 4th arg */
22594 call __audit_syscall_entry
22595+
22596+ pax_erase_kstack
22597+
22598 popl_cfi %ecx /* get that remapped edx off the stack */
22599 popl_cfi %ecx /* get that remapped esi off the stack */
22600 movl PT_EAX(%esp),%eax /* reload syscall number */
22601@@ -479,10 +666,16 @@ sysexit_audit:
22602
22603 CFI_ENDPROC
22604 .pushsection .fixup,"ax"
22605-2: movl $0,PT_FS(%esp)
22606+4: movl $0,PT_FS(%esp)
22607+ jmp 1b
22608+5: movl $0,PT_DS(%esp)
22609+ jmp 1b
22610+6: movl $0,PT_ES(%esp)
22611 jmp 1b
22612 .popsection
22613- _ASM_EXTABLE(1b,2b)
22614+ _ASM_EXTABLE(1b,4b)
22615+ _ASM_EXTABLE(2b,5b)
22616+ _ASM_EXTABLE(3b,6b)
22617 PTGS_TO_GS_EX
22618 ENDPROC(ia32_sysenter_target)
22619
22620@@ -493,6 +686,11 @@ ENTRY(system_call)
22621 pushl_cfi %eax # save orig_eax
22622 SAVE_ALL
22623 GET_THREAD_INFO(%ebp)
22624+
22625+#ifdef CONFIG_PAX_RANDKSTACK
22626+ pax_erase_kstack
22627+#endif
22628+
22629 # system call tracing in operation / emulation
22630 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22631 jnz syscall_trace_entry
22632@@ -512,6 +710,15 @@ syscall_exit:
22633 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22634 jne syscall_exit_work
22635
22636+restore_all_pax:
22637+
22638+#ifdef CONFIG_PAX_RANDKSTACK
22639+ movl %esp, %eax
22640+ call pax_randomize_kstack
22641+#endif
22642+
22643+ pax_erase_kstack
22644+
22645 restore_all:
22646 TRACE_IRQS_IRET
22647 restore_all_notrace:
22648@@ -566,14 +773,34 @@ ldt_ss:
22649 * compensating for the offset by changing to the ESPFIX segment with
22650 * a base address that matches for the difference.
22651 */
22652-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22653+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22654 mov %esp, %edx /* load kernel esp */
22655 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22656 mov %dx, %ax /* eax: new kernel esp */
22657 sub %eax, %edx /* offset (low word is 0) */
22658+#ifdef CONFIG_SMP
22659+ movl PER_CPU_VAR(cpu_number), %ebx
22660+ shll $PAGE_SHIFT_asm, %ebx
22661+ addl $cpu_gdt_table, %ebx
22662+#else
22663+ movl $cpu_gdt_table, %ebx
22664+#endif
22665 shr $16, %edx
22666- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22667- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22668+
22669+#ifdef CONFIG_PAX_KERNEXEC
22670+ mov %cr0, %esi
22671+ btr $16, %esi
22672+ mov %esi, %cr0
22673+#endif
22674+
22675+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22676+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22677+
22678+#ifdef CONFIG_PAX_KERNEXEC
22679+ bts $16, %esi
22680+ mov %esi, %cr0
22681+#endif
22682+
22683 pushl_cfi $__ESPFIX_SS
22684 pushl_cfi %eax /* new kernel esp */
22685 /* Disable interrupts, but do not irqtrace this section: we
22686@@ -603,20 +830,18 @@ work_resched:
22687 movl TI_flags(%ebp), %ecx
22688 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22689 # than syscall tracing?
22690- jz restore_all
22691+ jz restore_all_pax
22692 testb $_TIF_NEED_RESCHED, %cl
22693 jnz work_resched
22694
22695 work_notifysig: # deal with pending signals and
22696 # notify-resume requests
22697+ movl %esp, %eax
22698 #ifdef CONFIG_VM86
22699 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22700- movl %esp, %eax
22701 jne work_notifysig_v86 # returning to kernel-space or
22702 # vm86-space
22703 1:
22704-#else
22705- movl %esp, %eax
22706 #endif
22707 TRACE_IRQS_ON
22708 ENABLE_INTERRUPTS(CLBR_NONE)
22709@@ -637,7 +862,7 @@ work_notifysig_v86:
22710 movl %eax, %esp
22711 jmp 1b
22712 #endif
22713-END(work_pending)
22714+ENDPROC(work_pending)
22715
22716 # perform syscall exit tracing
22717 ALIGN
22718@@ -645,11 +870,14 @@ syscall_trace_entry:
22719 movl $-ENOSYS,PT_EAX(%esp)
22720 movl %esp, %eax
22721 call syscall_trace_enter
22722+
22723+ pax_erase_kstack
22724+
22725 /* What it returned is what we'll actually use. */
22726 cmpl $(NR_syscalls), %eax
22727 jnae syscall_call
22728 jmp syscall_exit
22729-END(syscall_trace_entry)
22730+ENDPROC(syscall_trace_entry)
22731
22732 # perform syscall exit tracing
22733 ALIGN
22734@@ -662,26 +890,30 @@ syscall_exit_work:
22735 movl %esp, %eax
22736 call syscall_trace_leave
22737 jmp resume_userspace
22738-END(syscall_exit_work)
22739+ENDPROC(syscall_exit_work)
22740 CFI_ENDPROC
22741
22742 RING0_INT_FRAME # can't unwind into user space anyway
22743 syscall_fault:
22744+#ifdef CONFIG_PAX_MEMORY_UDEREF
22745+ push %ss
22746+ pop %ds
22747+#endif
22748 ASM_CLAC
22749 GET_THREAD_INFO(%ebp)
22750 movl $-EFAULT,PT_EAX(%esp)
22751 jmp resume_userspace
22752-END(syscall_fault)
22753+ENDPROC(syscall_fault)
22754
22755 syscall_badsys:
22756 movl $-ENOSYS,%eax
22757 jmp syscall_after_call
22758-END(syscall_badsys)
22759+ENDPROC(syscall_badsys)
22760
22761 sysenter_badsys:
22762 movl $-ENOSYS,%eax
22763 jmp sysenter_after_call
22764-END(sysenter_badsys)
22765+ENDPROC(sysenter_badsys)
22766 CFI_ENDPROC
22767
22768 .macro FIXUP_ESPFIX_STACK
22769@@ -694,8 +926,15 @@ END(sysenter_badsys)
22770 */
22771 #ifdef CONFIG_X86_ESPFIX32
22772 /* fixup the stack */
22773- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22774- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22775+#ifdef CONFIG_SMP
22776+ movl PER_CPU_VAR(cpu_number), %ebx
22777+ shll $PAGE_SHIFT_asm, %ebx
22778+ addl $cpu_gdt_table, %ebx
22779+#else
22780+ movl $cpu_gdt_table, %ebx
22781+#endif
22782+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22783+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22784 shl $16, %eax
22785 addl %esp, %eax /* the adjusted stack pointer */
22786 pushl_cfi $__KERNEL_DS
22787@@ -751,7 +990,7 @@ vector=vector+1
22788 .endr
22789 2: jmp common_interrupt
22790 .endr
22791-END(irq_entries_start)
22792+ENDPROC(irq_entries_start)
22793
22794 .previous
22795 END(interrupt)
22796@@ -808,7 +1047,7 @@ ENTRY(coprocessor_error)
22797 pushl_cfi $do_coprocessor_error
22798 jmp error_code
22799 CFI_ENDPROC
22800-END(coprocessor_error)
22801+ENDPROC(coprocessor_error)
22802
22803 ENTRY(simd_coprocessor_error)
22804 RING0_INT_FRAME
22805@@ -821,7 +1060,7 @@ ENTRY(simd_coprocessor_error)
22806 .section .altinstructions,"a"
22807 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22808 .previous
22809-.section .altinstr_replacement,"ax"
22810+.section .altinstr_replacement,"a"
22811 663: pushl $do_simd_coprocessor_error
22812 664:
22813 .previous
22814@@ -830,7 +1069,7 @@ ENTRY(simd_coprocessor_error)
22815 #endif
22816 jmp error_code
22817 CFI_ENDPROC
22818-END(simd_coprocessor_error)
22819+ENDPROC(simd_coprocessor_error)
22820
22821 ENTRY(device_not_available)
22822 RING0_INT_FRAME
22823@@ -839,18 +1078,18 @@ ENTRY(device_not_available)
22824 pushl_cfi $do_device_not_available
22825 jmp error_code
22826 CFI_ENDPROC
22827-END(device_not_available)
22828+ENDPROC(device_not_available)
22829
22830 #ifdef CONFIG_PARAVIRT
22831 ENTRY(native_iret)
22832 iret
22833 _ASM_EXTABLE(native_iret, iret_exc)
22834-END(native_iret)
22835+ENDPROC(native_iret)
22836
22837 ENTRY(native_irq_enable_sysexit)
22838 sti
22839 sysexit
22840-END(native_irq_enable_sysexit)
22841+ENDPROC(native_irq_enable_sysexit)
22842 #endif
22843
22844 ENTRY(overflow)
22845@@ -860,7 +1099,7 @@ ENTRY(overflow)
22846 pushl_cfi $do_overflow
22847 jmp error_code
22848 CFI_ENDPROC
22849-END(overflow)
22850+ENDPROC(overflow)
22851
22852 ENTRY(bounds)
22853 RING0_INT_FRAME
22854@@ -869,7 +1108,7 @@ ENTRY(bounds)
22855 pushl_cfi $do_bounds
22856 jmp error_code
22857 CFI_ENDPROC
22858-END(bounds)
22859+ENDPROC(bounds)
22860
22861 ENTRY(invalid_op)
22862 RING0_INT_FRAME
22863@@ -878,7 +1117,7 @@ ENTRY(invalid_op)
22864 pushl_cfi $do_invalid_op
22865 jmp error_code
22866 CFI_ENDPROC
22867-END(invalid_op)
22868+ENDPROC(invalid_op)
22869
22870 ENTRY(coprocessor_segment_overrun)
22871 RING0_INT_FRAME
22872@@ -887,7 +1126,7 @@ ENTRY(coprocessor_segment_overrun)
22873 pushl_cfi $do_coprocessor_segment_overrun
22874 jmp error_code
22875 CFI_ENDPROC
22876-END(coprocessor_segment_overrun)
22877+ENDPROC(coprocessor_segment_overrun)
22878
22879 ENTRY(invalid_TSS)
22880 RING0_EC_FRAME
22881@@ -895,7 +1134,7 @@ ENTRY(invalid_TSS)
22882 pushl_cfi $do_invalid_TSS
22883 jmp error_code
22884 CFI_ENDPROC
22885-END(invalid_TSS)
22886+ENDPROC(invalid_TSS)
22887
22888 ENTRY(segment_not_present)
22889 RING0_EC_FRAME
22890@@ -903,7 +1142,7 @@ ENTRY(segment_not_present)
22891 pushl_cfi $do_segment_not_present
22892 jmp error_code
22893 CFI_ENDPROC
22894-END(segment_not_present)
22895+ENDPROC(segment_not_present)
22896
22897 ENTRY(stack_segment)
22898 RING0_EC_FRAME
22899@@ -911,7 +1150,7 @@ ENTRY(stack_segment)
22900 pushl_cfi $do_stack_segment
22901 jmp error_code
22902 CFI_ENDPROC
22903-END(stack_segment)
22904+ENDPROC(stack_segment)
22905
22906 ENTRY(alignment_check)
22907 RING0_EC_FRAME
22908@@ -919,7 +1158,7 @@ ENTRY(alignment_check)
22909 pushl_cfi $do_alignment_check
22910 jmp error_code
22911 CFI_ENDPROC
22912-END(alignment_check)
22913+ENDPROC(alignment_check)
22914
22915 ENTRY(divide_error)
22916 RING0_INT_FRAME
22917@@ -928,7 +1167,7 @@ ENTRY(divide_error)
22918 pushl_cfi $do_divide_error
22919 jmp error_code
22920 CFI_ENDPROC
22921-END(divide_error)
22922+ENDPROC(divide_error)
22923
22924 #ifdef CONFIG_X86_MCE
22925 ENTRY(machine_check)
22926@@ -938,7 +1177,7 @@ ENTRY(machine_check)
22927 pushl_cfi machine_check_vector
22928 jmp error_code
22929 CFI_ENDPROC
22930-END(machine_check)
22931+ENDPROC(machine_check)
22932 #endif
22933
22934 ENTRY(spurious_interrupt_bug)
22935@@ -948,7 +1187,7 @@ ENTRY(spurious_interrupt_bug)
22936 pushl_cfi $do_spurious_interrupt_bug
22937 jmp error_code
22938 CFI_ENDPROC
22939-END(spurious_interrupt_bug)
22940+ENDPROC(spurious_interrupt_bug)
22941
22942 #ifdef CONFIG_XEN
22943 /* Xen doesn't set %esp to be precisely what the normal sysenter
22944@@ -1054,7 +1293,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22945
22946 ENTRY(mcount)
22947 ret
22948-END(mcount)
22949+ENDPROC(mcount)
22950
22951 ENTRY(ftrace_caller)
22952 pushl %eax
22953@@ -1084,7 +1323,7 @@ ftrace_graph_call:
22954 .globl ftrace_stub
22955 ftrace_stub:
22956 ret
22957-END(ftrace_caller)
22958+ENDPROC(ftrace_caller)
22959
22960 ENTRY(ftrace_regs_caller)
22961 pushf /* push flags before compare (in cs location) */
22962@@ -1182,7 +1421,7 @@ trace:
22963 popl %ecx
22964 popl %eax
22965 jmp ftrace_stub
22966-END(mcount)
22967+ENDPROC(mcount)
22968 #endif /* CONFIG_DYNAMIC_FTRACE */
22969 #endif /* CONFIG_FUNCTION_TRACER */
22970
22971@@ -1200,7 +1439,7 @@ ENTRY(ftrace_graph_caller)
22972 popl %ecx
22973 popl %eax
22974 ret
22975-END(ftrace_graph_caller)
22976+ENDPROC(ftrace_graph_caller)
22977
22978 .globl return_to_handler
22979 return_to_handler:
22980@@ -1261,15 +1500,18 @@ error_code:
22981 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
22982 REG_TO_PTGS %ecx
22983 SET_KERNEL_GS %ecx
22984- movl $(__USER_DS), %ecx
22985+ movl $(__KERNEL_DS), %ecx
22986 movl %ecx, %ds
22987 movl %ecx, %es
22988+
22989+ pax_enter_kernel
22990+
22991 TRACE_IRQS_OFF
22992 movl %esp,%eax # pt_regs pointer
22993 call *%edi
22994 jmp ret_from_exception
22995 CFI_ENDPROC
22996-END(page_fault)
22997+ENDPROC(page_fault)
22998
22999 /*
23000 * Debug traps and NMI can happen at the one SYSENTER instruction
23001@@ -1312,7 +1554,7 @@ debug_stack_correct:
23002 call do_debug
23003 jmp ret_from_exception
23004 CFI_ENDPROC
23005-END(debug)
23006+ENDPROC(debug)
23007
23008 /*
23009 * NMI is doubly nasty. It can happen _while_ we're handling
23010@@ -1352,6 +1594,9 @@ nmi_stack_correct:
23011 xorl %edx,%edx # zero error code
23012 movl %esp,%eax # pt_regs pointer
23013 call do_nmi
23014+
23015+ pax_exit_kernel
23016+
23017 jmp restore_all_notrace
23018 CFI_ENDPROC
23019
23020@@ -1389,13 +1634,16 @@ nmi_espfix_stack:
23021 FIXUP_ESPFIX_STACK # %eax == %esp
23022 xorl %edx,%edx # zero error code
23023 call do_nmi
23024+
23025+ pax_exit_kernel
23026+
23027 RESTORE_REGS
23028 lss 12+4(%esp), %esp # back to espfix stack
23029 CFI_ADJUST_CFA_OFFSET -24
23030 jmp irq_return
23031 #endif
23032 CFI_ENDPROC
23033-END(nmi)
23034+ENDPROC(nmi)
23035
23036 ENTRY(int3)
23037 RING0_INT_FRAME
23038@@ -1408,14 +1656,14 @@ ENTRY(int3)
23039 call do_int3
23040 jmp ret_from_exception
23041 CFI_ENDPROC
23042-END(int3)
23043+ENDPROC(int3)
23044
23045 ENTRY(general_protection)
23046 RING0_EC_FRAME
23047 pushl_cfi $do_general_protection
23048 jmp error_code
23049 CFI_ENDPROC
23050-END(general_protection)
23051+ENDPROC(general_protection)
23052
23053 #ifdef CONFIG_KVM_GUEST
23054 ENTRY(async_page_fault)
23055@@ -1424,6 +1672,6 @@ ENTRY(async_page_fault)
23056 pushl_cfi $do_async_page_fault
23057 jmp error_code
23058 CFI_ENDPROC
23059-END(async_page_fault)
23060+ENDPROC(async_page_fault)
23061 #endif
23062
23063diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
23064index c0226ab..96a8ab7 100644
23065--- a/arch/x86/kernel/entry_64.S
23066+++ b/arch/x86/kernel/entry_64.S
23067@@ -59,6 +59,8 @@
23068 #include <asm/smap.h>
23069 #include <asm/pgtable_types.h>
23070 #include <linux/err.h>
23071+#include <asm/pgtable.h>
23072+#include <asm/alternative-asm.h>
23073
23074 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
23075 #include <linux/elf-em.h>
23076@@ -81,6 +83,430 @@ ENTRY(native_usergs_sysret64)
23077 ENDPROC(native_usergs_sysret64)
23078 #endif /* CONFIG_PARAVIRT */
23079
23080+ .macro ljmpq sel, off
23081+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
23082+ .byte 0x48; ljmp *1234f(%rip)
23083+ .pushsection .rodata
23084+ .align 16
23085+ 1234: .quad \off; .word \sel
23086+ .popsection
23087+#else
23088+ pushq $\sel
23089+ pushq $\off
23090+ lretq
23091+#endif
23092+ .endm
23093+
23094+ .macro pax_enter_kernel
23095+ pax_set_fptr_mask
23096+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23097+ call pax_enter_kernel
23098+#endif
23099+ .endm
23100+
23101+ .macro pax_exit_kernel
23102+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23103+ call pax_exit_kernel
23104+#endif
23105+
23106+ .endm
23107+
23108+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23109+ENTRY(pax_enter_kernel)
23110+ pushq %rdi
23111+
23112+#ifdef CONFIG_PARAVIRT
23113+ PV_SAVE_REGS(CLBR_RDI)
23114+#endif
23115+
23116+#ifdef CONFIG_PAX_KERNEXEC
23117+ GET_CR0_INTO_RDI
23118+ bts $16,%rdi
23119+ jnc 3f
23120+ mov %cs,%edi
23121+ cmp $__KERNEL_CS,%edi
23122+ jnz 2f
23123+1:
23124+#endif
23125+
23126+#ifdef CONFIG_PAX_MEMORY_UDEREF
23127+ 661: jmp 111f
23128+ .pushsection .altinstr_replacement, "a"
23129+ 662: ASM_NOP2
23130+ .popsection
23131+ .pushsection .altinstructions, "a"
23132+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23133+ .popsection
23134+ GET_CR3_INTO_RDI
23135+ cmp $0,%dil
23136+ jnz 112f
23137+ mov $__KERNEL_DS,%edi
23138+ mov %edi,%ss
23139+ jmp 111f
23140+112: cmp $1,%dil
23141+ jz 113f
23142+ ud2
23143+113: sub $4097,%rdi
23144+ bts $63,%rdi
23145+ SET_RDI_INTO_CR3
23146+ mov $__UDEREF_KERNEL_DS,%edi
23147+ mov %edi,%ss
23148+111:
23149+#endif
23150+
23151+#ifdef CONFIG_PARAVIRT
23152+ PV_RESTORE_REGS(CLBR_RDI)
23153+#endif
23154+
23155+ popq %rdi
23156+ pax_force_retaddr
23157+ retq
23158+
23159+#ifdef CONFIG_PAX_KERNEXEC
23160+2: ljmpq __KERNEL_CS,1b
23161+3: ljmpq __KERNEXEC_KERNEL_CS,4f
23162+4: SET_RDI_INTO_CR0
23163+ jmp 1b
23164+#endif
23165+ENDPROC(pax_enter_kernel)
23166+
23167+ENTRY(pax_exit_kernel)
23168+ pushq %rdi
23169+
23170+#ifdef CONFIG_PARAVIRT
23171+ PV_SAVE_REGS(CLBR_RDI)
23172+#endif
23173+
23174+#ifdef CONFIG_PAX_KERNEXEC
23175+ mov %cs,%rdi
23176+ cmp $__KERNEXEC_KERNEL_CS,%edi
23177+ jz 2f
23178+ GET_CR0_INTO_RDI
23179+ bts $16,%rdi
23180+ jnc 4f
23181+1:
23182+#endif
23183+
23184+#ifdef CONFIG_PAX_MEMORY_UDEREF
23185+ 661: jmp 111f
23186+ .pushsection .altinstr_replacement, "a"
23187+ 662: ASM_NOP2
23188+ .popsection
23189+ .pushsection .altinstructions, "a"
23190+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23191+ .popsection
23192+ mov %ss,%edi
23193+ cmp $__UDEREF_KERNEL_DS,%edi
23194+ jnz 111f
23195+ GET_CR3_INTO_RDI
23196+ cmp $0,%dil
23197+ jz 112f
23198+ ud2
23199+112: add $4097,%rdi
23200+ bts $63,%rdi
23201+ SET_RDI_INTO_CR3
23202+ mov $__KERNEL_DS,%edi
23203+ mov %edi,%ss
23204+111:
23205+#endif
23206+
23207+#ifdef CONFIG_PARAVIRT
23208+ PV_RESTORE_REGS(CLBR_RDI);
23209+#endif
23210+
23211+ popq %rdi
23212+ pax_force_retaddr
23213+ retq
23214+
23215+#ifdef CONFIG_PAX_KERNEXEC
23216+2: GET_CR0_INTO_RDI
23217+ btr $16,%rdi
23218+ jnc 4f
23219+ ljmpq __KERNEL_CS,3f
23220+3: SET_RDI_INTO_CR0
23221+ jmp 1b
23222+4: ud2
23223+ jmp 4b
23224+#endif
23225+ENDPROC(pax_exit_kernel)
23226+#endif
23227+
23228+ .macro pax_enter_kernel_user
23229+ pax_set_fptr_mask
23230+#ifdef CONFIG_PAX_MEMORY_UDEREF
23231+ call pax_enter_kernel_user
23232+#endif
23233+ .endm
23234+
23235+ .macro pax_exit_kernel_user
23236+#ifdef CONFIG_PAX_MEMORY_UDEREF
23237+ call pax_exit_kernel_user
23238+#endif
23239+#ifdef CONFIG_PAX_RANDKSTACK
23240+ pushq %rax
23241+ pushq %r11
23242+ call pax_randomize_kstack
23243+ popq %r11
23244+ popq %rax
23245+#endif
23246+ .endm
23247+
23248+#ifdef CONFIG_PAX_MEMORY_UDEREF
23249+ENTRY(pax_enter_kernel_user)
23250+ pushq %rdi
23251+ pushq %rbx
23252+
23253+#ifdef CONFIG_PARAVIRT
23254+ PV_SAVE_REGS(CLBR_RDI)
23255+#endif
23256+
23257+ 661: jmp 111f
23258+ .pushsection .altinstr_replacement, "a"
23259+ 662: ASM_NOP2
23260+ .popsection
23261+ .pushsection .altinstructions, "a"
23262+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23263+ .popsection
23264+ GET_CR3_INTO_RDI
23265+ cmp $1,%dil
23266+ jnz 4f
23267+ sub $4097,%rdi
23268+ bts $63,%rdi
23269+ SET_RDI_INTO_CR3
23270+ jmp 3f
23271+111:
23272+
23273+ GET_CR3_INTO_RDI
23274+ mov %rdi,%rbx
23275+ add $__START_KERNEL_map,%rbx
23276+ sub phys_base(%rip),%rbx
23277+
23278+#ifdef CONFIG_PARAVIRT
23279+ cmpl $0, pv_info+PARAVIRT_enabled
23280+ jz 1f
23281+ pushq %rdi
23282+ i = 0
23283+ .rept USER_PGD_PTRS
23284+ mov i*8(%rbx),%rsi
23285+ mov $0,%sil
23286+ lea i*8(%rbx),%rdi
23287+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23288+ i = i + 1
23289+ .endr
23290+ popq %rdi
23291+ jmp 2f
23292+1:
23293+#endif
23294+
23295+ i = 0
23296+ .rept USER_PGD_PTRS
23297+ movb $0,i*8(%rbx)
23298+ i = i + 1
23299+ .endr
23300+
23301+2: SET_RDI_INTO_CR3
23302+
23303+#ifdef CONFIG_PAX_KERNEXEC
23304+ GET_CR0_INTO_RDI
23305+ bts $16,%rdi
23306+ SET_RDI_INTO_CR0
23307+#endif
23308+
23309+3:
23310+
23311+#ifdef CONFIG_PARAVIRT
23312+ PV_RESTORE_REGS(CLBR_RDI)
23313+#endif
23314+
23315+ popq %rbx
23316+ popq %rdi
23317+ pax_force_retaddr
23318+ retq
23319+4: ud2
23320+ENDPROC(pax_enter_kernel_user)
23321+
23322+ENTRY(pax_exit_kernel_user)
23323+ pushq %rdi
23324+ pushq %rbx
23325+
23326+#ifdef CONFIG_PARAVIRT
23327+ PV_SAVE_REGS(CLBR_RDI)
23328+#endif
23329+
23330+ GET_CR3_INTO_RDI
23331+ 661: jmp 1f
23332+ .pushsection .altinstr_replacement, "a"
23333+ 662: ASM_NOP2
23334+ .popsection
23335+ .pushsection .altinstructions, "a"
23336+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23337+ .popsection
23338+ cmp $0,%dil
23339+ jnz 3f
23340+ add $4097,%rdi
23341+ bts $63,%rdi
23342+ SET_RDI_INTO_CR3
23343+ jmp 2f
23344+1:
23345+
23346+ mov %rdi,%rbx
23347+
23348+#ifdef CONFIG_PAX_KERNEXEC
23349+ GET_CR0_INTO_RDI
23350+ btr $16,%rdi
23351+ jnc 3f
23352+ SET_RDI_INTO_CR0
23353+#endif
23354+
23355+ add $__START_KERNEL_map,%rbx
23356+ sub phys_base(%rip),%rbx
23357+
23358+#ifdef CONFIG_PARAVIRT
23359+ cmpl $0, pv_info+PARAVIRT_enabled
23360+ jz 1f
23361+ i = 0
23362+ .rept USER_PGD_PTRS
23363+ mov i*8(%rbx),%rsi
23364+ mov $0x67,%sil
23365+ lea i*8(%rbx),%rdi
23366+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23367+ i = i + 1
23368+ .endr
23369+ jmp 2f
23370+1:
23371+#endif
23372+
23373+ i = 0
23374+ .rept USER_PGD_PTRS
23375+ movb $0x67,i*8(%rbx)
23376+ i = i + 1
23377+ .endr
23378+2:
23379+
23380+#ifdef CONFIG_PARAVIRT
23381+ PV_RESTORE_REGS(CLBR_RDI)
23382+#endif
23383+
23384+ popq %rbx
23385+ popq %rdi
23386+ pax_force_retaddr
23387+ retq
23388+3: ud2
23389+ENDPROC(pax_exit_kernel_user)
23390+#endif
23391+
23392+ .macro pax_enter_kernel_nmi
23393+ pax_set_fptr_mask
23394+
23395+#ifdef CONFIG_PAX_KERNEXEC
23396+ GET_CR0_INTO_RDI
23397+ bts $16,%rdi
23398+ jc 110f
23399+ SET_RDI_INTO_CR0
23400+ or $2,%ebx
23401+110:
23402+#endif
23403+
23404+#ifdef CONFIG_PAX_MEMORY_UDEREF
23405+ 661: jmp 111f
23406+ .pushsection .altinstr_replacement, "a"
23407+ 662: ASM_NOP2
23408+ .popsection
23409+ .pushsection .altinstructions, "a"
23410+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23411+ .popsection
23412+ GET_CR3_INTO_RDI
23413+ cmp $0,%dil
23414+ jz 111f
23415+ sub $4097,%rdi
23416+ or $4,%ebx
23417+ bts $63,%rdi
23418+ SET_RDI_INTO_CR3
23419+ mov $__UDEREF_KERNEL_DS,%edi
23420+ mov %edi,%ss
23421+111:
23422+#endif
23423+ .endm
23424+
23425+ .macro pax_exit_kernel_nmi
23426+#ifdef CONFIG_PAX_KERNEXEC
23427+ btr $1,%ebx
23428+ jnc 110f
23429+ GET_CR0_INTO_RDI
23430+ btr $16,%rdi
23431+ SET_RDI_INTO_CR0
23432+110:
23433+#endif
23434+
23435+#ifdef CONFIG_PAX_MEMORY_UDEREF
23436+ btr $2,%ebx
23437+ jnc 111f
23438+ GET_CR3_INTO_RDI
23439+ add $4097,%rdi
23440+ bts $63,%rdi
23441+ SET_RDI_INTO_CR3
23442+ mov $__KERNEL_DS,%edi
23443+ mov %edi,%ss
23444+111:
23445+#endif
23446+ .endm
23447+
23448+ .macro pax_erase_kstack
23449+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23450+ call pax_erase_kstack
23451+#endif
23452+ .endm
23453+
23454+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23455+ENTRY(pax_erase_kstack)
23456+ pushq %rdi
23457+ pushq %rcx
23458+ pushq %rax
23459+ pushq %r11
23460+
23461+ GET_THREAD_INFO(%r11)
23462+ mov TI_lowest_stack(%r11), %rdi
23463+ mov $-0xBEEF, %rax
23464+ std
23465+
23466+1: mov %edi, %ecx
23467+ and $THREAD_SIZE_asm - 1, %ecx
23468+ shr $3, %ecx
23469+ repne scasq
23470+ jecxz 2f
23471+
23472+ cmp $2*8, %ecx
23473+ jc 2f
23474+
23475+ mov $2*8, %ecx
23476+ repe scasq
23477+ jecxz 2f
23478+ jne 1b
23479+
23480+2: cld
23481+ mov %esp, %ecx
23482+ sub %edi, %ecx
23483+
23484+ cmp $THREAD_SIZE_asm, %rcx
23485+ jb 3f
23486+ ud2
23487+3:
23488+
23489+ shr $3, %ecx
23490+ rep stosq
23491+
23492+ mov TI_task_thread_sp0(%r11), %rdi
23493+ sub $256, %rdi
23494+ mov %rdi, TI_lowest_stack(%r11)
23495+
23496+ popq %r11
23497+ popq %rax
23498+ popq %rcx
23499+ popq %rdi
23500+ pax_force_retaddr
23501+ ret
23502+ENDPROC(pax_erase_kstack)
23503+#endif
23504
23505 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23506 #ifdef CONFIG_TRACE_IRQFLAGS
23507@@ -117,7 +543,7 @@ ENDPROC(native_usergs_sysret64)
23508 .endm
23509
23510 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23511- bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23512+ bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23513 jnc 1f
23514 TRACE_IRQS_ON_DEBUG
23515 1:
23516@@ -155,27 +581,6 @@ ENDPROC(native_usergs_sysret64)
23517 movq \tmp,R11+\offset(%rsp)
23518 .endm
23519
23520- .macro FAKE_STACK_FRAME child_rip
23521- /* push in order ss, rsp, eflags, cs, rip */
23522- xorl %eax, %eax
23523- pushq_cfi $__KERNEL_DS /* ss */
23524- /*CFI_REL_OFFSET ss,0*/
23525- pushq_cfi %rax /* rsp */
23526- CFI_REL_OFFSET rsp,0
23527- pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23528- /*CFI_REL_OFFSET rflags,0*/
23529- pushq_cfi $__KERNEL_CS /* cs */
23530- /*CFI_REL_OFFSET cs,0*/
23531- pushq_cfi \child_rip /* rip */
23532- CFI_REL_OFFSET rip,0
23533- pushq_cfi %rax /* orig rax */
23534- .endm
23535-
23536- .macro UNFAKE_STACK_FRAME
23537- addq $8*6, %rsp
23538- CFI_ADJUST_CFA_OFFSET -(6*8)
23539- .endm
23540-
23541 /*
23542 * initial frame state for interrupts (and exceptions without error code)
23543 */
23544@@ -241,25 +646,26 @@ ENDPROC(native_usergs_sysret64)
23545 /* save partial stack frame */
23546 .macro SAVE_ARGS_IRQ
23547 cld
23548- /* start from rbp in pt_regs and jump over */
23549- movq_cfi rdi, (RDI-RBP)
23550- movq_cfi rsi, (RSI-RBP)
23551- movq_cfi rdx, (RDX-RBP)
23552- movq_cfi rcx, (RCX-RBP)
23553- movq_cfi rax, (RAX-RBP)
23554- movq_cfi r8, (R8-RBP)
23555- movq_cfi r9, (R9-RBP)
23556- movq_cfi r10, (R10-RBP)
23557- movq_cfi r11, (R11-RBP)
23558+ /* start from r15 in pt_regs and jump over */
23559+ movq_cfi rdi, RDI
23560+ movq_cfi rsi, RSI
23561+ movq_cfi rdx, RDX
23562+ movq_cfi rcx, RCX
23563+ movq_cfi rax, RAX
23564+ movq_cfi r8, R8
23565+ movq_cfi r9, R9
23566+ movq_cfi r10, R10
23567+ movq_cfi r11, R11
23568+ movq_cfi r12, R12
23569
23570 /* Save rbp so that we can unwind from get_irq_regs() */
23571- movq_cfi rbp, 0
23572+ movq_cfi rbp, RBP
23573
23574 /* Save previous stack value */
23575 movq %rsp, %rsi
23576
23577- leaq -RBP(%rsp),%rdi /* arg1 for handler */
23578- testl $3, CS-RBP(%rsi)
23579+ movq %rsp,%rdi /* arg1 for handler */
23580+ testb $3, CS(%rsi)
23581 je 1f
23582 SWAPGS
23583 /*
23584@@ -279,6 +685,18 @@ ENDPROC(native_usergs_sysret64)
23585 0x06 /* DW_OP_deref */, \
23586 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23587 0x22 /* DW_OP_plus */
23588+
23589+#ifdef CONFIG_PAX_MEMORY_UDEREF
23590+ testb $3, CS(%rdi)
23591+ jnz 1f
23592+ pax_enter_kernel
23593+ jmp 2f
23594+1: pax_enter_kernel_user
23595+2:
23596+#else
23597+ pax_enter_kernel
23598+#endif
23599+
23600 /* We entered an interrupt context - irqs are off: */
23601 TRACE_IRQS_OFF
23602 .endm
23603@@ -308,9 +726,52 @@ ENTRY(save_paranoid)
23604 js 1f /* negative -> in kernel */
23605 SWAPGS
23606 xorl %ebx,%ebx
23607-1: ret
23608+1:
23609+#ifdef CONFIG_PAX_MEMORY_UDEREF
23610+ testb $3, CS+8(%rsp)
23611+ jnz 1f
23612+ pax_enter_kernel
23613+ jmp 2f
23614+1: pax_enter_kernel_user
23615+2:
23616+#else
23617+ pax_enter_kernel
23618+#endif
23619+ pax_force_retaddr
23620+ ret
23621 CFI_ENDPROC
23622-END(save_paranoid)
23623+ENDPROC(save_paranoid)
23624+
23625+ENTRY(save_paranoid_nmi)
23626+ XCPT_FRAME 1 RDI+8
23627+ cld
23628+ movq_cfi rdi, RDI+8
23629+ movq_cfi rsi, RSI+8
23630+ movq_cfi rdx, RDX+8
23631+ movq_cfi rcx, RCX+8
23632+ movq_cfi rax, RAX+8
23633+ movq_cfi r8, R8+8
23634+ movq_cfi r9, R9+8
23635+ movq_cfi r10, R10+8
23636+ movq_cfi r11, R11+8
23637+ movq_cfi rbx, RBX+8
23638+ movq_cfi rbp, RBP+8
23639+ movq_cfi r12, R12+8
23640+ movq_cfi r13, R13+8
23641+ movq_cfi r14, R14+8
23642+ movq_cfi r15, R15+8
23643+ movl $1,%ebx
23644+ movl $MSR_GS_BASE,%ecx
23645+ rdmsr
23646+ testl %edx,%edx
23647+ js 1f /* negative -> in kernel */
23648+ SWAPGS
23649+ xorl %ebx,%ebx
23650+1: pax_enter_kernel_nmi
23651+ pax_force_retaddr
23652+ ret
23653+ CFI_ENDPROC
23654+ENDPROC(save_paranoid_nmi)
23655
23656 /*
23657 * A newly forked process directly context switches into this address.
23658@@ -331,7 +792,7 @@ ENTRY(ret_from_fork)
23659
23660 RESTORE_REST
23661
23662- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23663+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23664 jz 1f
23665
23666 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23667@@ -341,15 +802,13 @@ ENTRY(ret_from_fork)
23668 jmp ret_from_sys_call # go to the SYSRET fastpath
23669
23670 1:
23671- subq $REST_SKIP, %rsp # leave space for volatiles
23672- CFI_ADJUST_CFA_OFFSET REST_SKIP
23673 movq %rbp, %rdi
23674 call *%rbx
23675 movl $0, RAX(%rsp)
23676 RESTORE_REST
23677 jmp int_ret_from_sys_call
23678 CFI_ENDPROC
23679-END(ret_from_fork)
23680+ENDPROC(ret_from_fork)
23681
23682 /*
23683 * System call entry. Up to 6 arguments in registers are supported.
23684@@ -386,7 +845,7 @@ END(ret_from_fork)
23685 ENTRY(system_call)
23686 CFI_STARTPROC simple
23687 CFI_SIGNAL_FRAME
23688- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23689+ CFI_DEF_CFA rsp,0
23690 CFI_REGISTER rip,rcx
23691 /*CFI_REGISTER rflags,r11*/
23692 SWAPGS_UNSAFE_STACK
23693@@ -399,16 +858,23 @@ GLOBAL(system_call_after_swapgs)
23694
23695 movq %rsp,PER_CPU_VAR(old_rsp)
23696 movq PER_CPU_VAR(kernel_stack),%rsp
23697+ SAVE_ARGS 8*6, 0, rax_enosys=1
23698+ pax_enter_kernel_user
23699+
23700+#ifdef CONFIG_PAX_RANDKSTACK
23701+ pax_erase_kstack
23702+#endif
23703+
23704 /*
23705 * No need to follow this irqs off/on section - it's straight
23706 * and short:
23707 */
23708 ENABLE_INTERRUPTS(CLBR_NONE)
23709- SAVE_ARGS 8, 0, rax_enosys=1
23710 movq_cfi rax,(ORIG_RAX-ARGOFFSET)
23711 movq %rcx,RIP-ARGOFFSET(%rsp)
23712 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23713- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23714+ GET_THREAD_INFO(%rcx)
23715+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23716 jnz tracesys
23717 system_call_fastpath:
23718 #if __SYSCALL_MASK == ~0
23719@@ -432,10 +898,13 @@ sysret_check:
23720 LOCKDEP_SYS_EXIT
23721 DISABLE_INTERRUPTS(CLBR_NONE)
23722 TRACE_IRQS_OFF
23723- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23724+ GET_THREAD_INFO(%rcx)
23725+ movl TI_flags(%rcx),%edx
23726 andl %edi,%edx
23727 jnz sysret_careful
23728 CFI_REMEMBER_STATE
23729+ pax_exit_kernel_user
23730+ pax_erase_kstack
23731 /*
23732 * sysretq will re-enable interrupts:
23733 */
23734@@ -494,12 +963,15 @@ sysret_audit:
23735
23736 /* Do syscall tracing */
23737 tracesys:
23738- leaq -REST_SKIP(%rsp), %rdi
23739+ movq %rsp, %rdi
23740 movq $AUDIT_ARCH_X86_64, %rsi
23741 call syscall_trace_enter_phase1
23742 test %rax, %rax
23743 jnz tracesys_phase2 /* if needed, run the slow path */
23744- LOAD_ARGS 0 /* else restore clobbered regs */
23745+
23746+ pax_erase_kstack
23747+
23748+ LOAD_ARGS /* else restore clobbered regs */
23749 jmp system_call_fastpath /* and return to the fast path */
23750
23751 tracesys_phase2:
23752@@ -510,12 +982,14 @@ tracesys_phase2:
23753 movq %rax,%rdx
23754 call syscall_trace_enter_phase2
23755
23756+ pax_erase_kstack
23757+
23758 /*
23759 * Reload arg registers from stack in case ptrace changed them.
23760 * We don't reload %rax because syscall_trace_entry_phase2() returned
23761 * the value it wants us to use in the table lookup.
23762 */
23763- LOAD_ARGS ARGOFFSET, 1
23764+ LOAD_ARGS 1
23765 RESTORE_REST
23766 #if __SYSCALL_MASK == ~0
23767 cmpq $__NR_syscall_max,%rax
23768@@ -545,7 +1019,9 @@ GLOBAL(int_with_check)
23769 andl %edi,%edx
23770 jnz int_careful
23771 andl $~TS_COMPAT,TI_status(%rcx)
23772- jmp retint_swapgs
23773+ pax_exit_kernel_user
23774+ pax_erase_kstack
23775+ jmp retint_swapgs_pax
23776
23777 /* Either reschedule or signal or syscall exit tracking needed. */
23778 /* First do a reschedule test. */
23779@@ -591,7 +1067,7 @@ int_restore_rest:
23780 TRACE_IRQS_OFF
23781 jmp int_with_check
23782 CFI_ENDPROC
23783-END(system_call)
23784+ENDPROC(system_call)
23785
23786 .macro FORK_LIKE func
23787 ENTRY(stub_\func)
23788@@ -604,9 +1080,10 @@ ENTRY(stub_\func)
23789 DEFAULT_FRAME 0 8 /* offset 8: return address */
23790 call sys_\func
23791 RESTORE_TOP_OF_STACK %r11, 8
23792- ret $REST_SKIP /* pop extended registers */
23793+ pax_force_retaddr
23794+ ret
23795 CFI_ENDPROC
23796-END(stub_\func)
23797+ENDPROC(stub_\func)
23798 .endm
23799
23800 .macro FIXED_FRAME label,func
23801@@ -616,9 +1093,10 @@ ENTRY(\label)
23802 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23803 call \func
23804 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23805+ pax_force_retaddr
23806 ret
23807 CFI_ENDPROC
23808-END(\label)
23809+ENDPROC(\label)
23810 .endm
23811
23812 FORK_LIKE clone
23813@@ -626,19 +1104,6 @@ END(\label)
23814 FORK_LIKE vfork
23815 FIXED_FRAME stub_iopl, sys_iopl
23816
23817-ENTRY(ptregscall_common)
23818- DEFAULT_FRAME 1 8 /* offset 8: return address */
23819- RESTORE_TOP_OF_STACK %r11, 8
23820- movq_cfi_restore R15+8, r15
23821- movq_cfi_restore R14+8, r14
23822- movq_cfi_restore R13+8, r13
23823- movq_cfi_restore R12+8, r12
23824- movq_cfi_restore RBP+8, rbp
23825- movq_cfi_restore RBX+8, rbx
23826- ret $REST_SKIP /* pop extended registers */
23827- CFI_ENDPROC
23828-END(ptregscall_common)
23829-
23830 ENTRY(stub_execve)
23831 CFI_STARTPROC
23832 addq $8, %rsp
23833@@ -650,7 +1115,7 @@ ENTRY(stub_execve)
23834 RESTORE_REST
23835 jmp int_ret_from_sys_call
23836 CFI_ENDPROC
23837-END(stub_execve)
23838+ENDPROC(stub_execve)
23839
23840 /*
23841 * sigreturn is special because it needs to restore all registers on return.
23842@@ -667,7 +1132,7 @@ ENTRY(stub_rt_sigreturn)
23843 RESTORE_REST
23844 jmp int_ret_from_sys_call
23845 CFI_ENDPROC
23846-END(stub_rt_sigreturn)
23847+ENDPROC(stub_rt_sigreturn)
23848
23849 #ifdef CONFIG_X86_X32_ABI
23850 ENTRY(stub_x32_rt_sigreturn)
23851@@ -681,7 +1146,7 @@ ENTRY(stub_x32_rt_sigreturn)
23852 RESTORE_REST
23853 jmp int_ret_from_sys_call
23854 CFI_ENDPROC
23855-END(stub_x32_rt_sigreturn)
23856+ENDPROC(stub_x32_rt_sigreturn)
23857
23858 ENTRY(stub_x32_execve)
23859 CFI_STARTPROC
23860@@ -695,7 +1160,7 @@ ENTRY(stub_x32_execve)
23861 RESTORE_REST
23862 jmp int_ret_from_sys_call
23863 CFI_ENDPROC
23864-END(stub_x32_execve)
23865+ENDPROC(stub_x32_execve)
23866
23867 #endif
23868
23869@@ -732,7 +1197,7 @@ vector=vector+1
23870 2: jmp common_interrupt
23871 .endr
23872 CFI_ENDPROC
23873-END(irq_entries_start)
23874+ENDPROC(irq_entries_start)
23875
23876 .previous
23877 END(interrupt)
23878@@ -749,8 +1214,8 @@ END(interrupt)
23879 /* 0(%rsp): ~(interrupt number) */
23880 .macro interrupt func
23881 /* reserve pt_regs for scratch regs and rbp */
23882- subq $ORIG_RAX-RBP, %rsp
23883- CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23884+ subq $ORIG_RAX, %rsp
23885+ CFI_ADJUST_CFA_OFFSET ORIG_RAX
23886 SAVE_ARGS_IRQ
23887 call \func
23888 .endm
23889@@ -773,14 +1238,14 @@ ret_from_intr:
23890
23891 /* Restore saved previous stack */
23892 popq %rsi
23893- CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23894- leaq ARGOFFSET-RBP(%rsi), %rsp
23895+ CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23896+ movq %rsi, %rsp
23897 CFI_DEF_CFA_REGISTER rsp
23898- CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23899+ CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23900
23901 exit_intr:
23902 GET_THREAD_INFO(%rcx)
23903- testl $3,CS-ARGOFFSET(%rsp)
23904+ testb $3,CS-ARGOFFSET(%rsp)
23905 je retint_kernel
23906
23907 /* Interrupt came from user space */
23908@@ -802,12 +1267,35 @@ retint_swapgs: /* return to user-space */
23909 * The iretq could re-enable interrupts:
23910 */
23911 DISABLE_INTERRUPTS(CLBR_ANY)
23912+ pax_exit_kernel_user
23913+retint_swapgs_pax:
23914 TRACE_IRQS_IRETQ
23915 SWAPGS
23916 jmp restore_args
23917
23918 retint_restore_args: /* return to kernel space */
23919 DISABLE_INTERRUPTS(CLBR_ANY)
23920+ pax_exit_kernel
23921+
23922+#if defined(CONFIG_EFI) && defined(CONFIG_PAX_KERNEXEC)
23923+ /* This is a quirk to allow IRQs/NMIs/MCEs during early EFI setup,
23924+ * namely calling EFI runtime services with a phys mapping. We're
23925+ * starting off with NOPs and patch in the real instrumentation
23926+ * (BTS/OR) before starting any userland process; even before starting
23927+ * up the APs.
23928+ */
23929+ .pushsection .altinstr_replacement, "a"
23930+ 601: pax_force_retaddr (RIP-ARGOFFSET)
23931+ 602:
23932+ .popsection
23933+ 603: .fill 602b-601b, 1, 0x90
23934+ .pushsection .altinstructions, "a"
23935+ altinstruction_entry 603b, 601b, X86_FEATURE_ALWAYS, 602b-601b, 602b-601b
23936+ .popsection
23937+#else
23938+ pax_force_retaddr (RIP-ARGOFFSET)
23939+#endif
23940+
23941 /*
23942 * The iretq could re-enable interrupts:
23943 */
23944@@ -845,15 +1333,15 @@ native_irq_return_ldt:
23945 SWAPGS
23946 movq PER_CPU_VAR(espfix_waddr),%rdi
23947 movq %rax,(0*8)(%rdi) /* RAX */
23948- movq (2*8)(%rsp),%rax /* RIP */
23949+ movq (2*8 + RIP-RIP)(%rsp),%rax /* RIP */
23950 movq %rax,(1*8)(%rdi)
23951- movq (3*8)(%rsp),%rax /* CS */
23952+ movq (2*8 + CS-RIP)(%rsp),%rax /* CS */
23953 movq %rax,(2*8)(%rdi)
23954- movq (4*8)(%rsp),%rax /* RFLAGS */
23955+ movq (2*8 + EFLAGS-RIP)(%rsp),%rax /* RFLAGS */
23956 movq %rax,(3*8)(%rdi)
23957- movq (6*8)(%rsp),%rax /* SS */
23958+ movq (2*8 + SS-RIP)(%rsp),%rax /* SS */
23959 movq %rax,(5*8)(%rdi)
23960- movq (5*8)(%rsp),%rax /* RSP */
23961+ movq (2*8 + RSP-RIP)(%rsp),%rax /* RSP */
23962 movq %rax,(4*8)(%rdi)
23963 andl $0xffff0000,%eax
23964 popq_cfi %rdi
23965@@ -907,7 +1395,7 @@ ENTRY(retint_kernel)
23966 jmp exit_intr
23967 #endif
23968 CFI_ENDPROC
23969-END(common_interrupt)
23970+ENDPROC(common_interrupt)
23971
23972 /*
23973 * APIC interrupts.
23974@@ -921,7 +1409,7 @@ ENTRY(\sym)
23975 interrupt \do_sym
23976 jmp ret_from_intr
23977 CFI_ENDPROC
23978-END(\sym)
23979+ENDPROC(\sym)
23980 .endm
23981
23982 #ifdef CONFIG_TRACING
23983@@ -994,7 +1482,7 @@ apicinterrupt IRQ_WORK_VECTOR \
23984 /*
23985 * Exception entry points.
23986 */
23987-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
23988+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
23989
23990 .macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1
23991 ENTRY(\sym)
23992@@ -1045,6 +1533,12 @@ ENTRY(\sym)
23993 .endif
23994
23995 .if \shift_ist != -1
23996+#ifdef CONFIG_SMP
23997+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
23998+ lea init_tss(%r13), %r13
23999+#else
24000+ lea init_tss(%rip), %r13
24001+#endif
24002 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\shift_ist)
24003 .endif
24004
24005@@ -1061,7 +1555,7 @@ ENTRY(\sym)
24006 .endif
24007
24008 CFI_ENDPROC
24009-END(\sym)
24010+ENDPROC(\sym)
24011 .endm
24012
24013 #ifdef CONFIG_TRACING
24014@@ -1102,9 +1596,10 @@ gs_change:
24015 2: mfence /* workaround */
24016 SWAPGS
24017 popfq_cfi
24018+ pax_force_retaddr
24019 ret
24020 CFI_ENDPROC
24021-END(native_load_gs_index)
24022+ENDPROC(native_load_gs_index)
24023
24024 _ASM_EXTABLE(gs_change,bad_gs)
24025 .section .fixup,"ax"
24026@@ -1132,9 +1627,10 @@ ENTRY(do_softirq_own_stack)
24027 CFI_DEF_CFA_REGISTER rsp
24028 CFI_ADJUST_CFA_OFFSET -8
24029 decl PER_CPU_VAR(irq_count)
24030+ pax_force_retaddr
24031 ret
24032 CFI_ENDPROC
24033-END(do_softirq_own_stack)
24034+ENDPROC(do_softirq_own_stack)
24035
24036 #ifdef CONFIG_XEN
24037 idtentry xen_hypervisor_callback xen_do_hypervisor_callback has_error_code=0
24038@@ -1172,7 +1668,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
24039 decl PER_CPU_VAR(irq_count)
24040 jmp error_exit
24041 CFI_ENDPROC
24042-END(xen_do_hypervisor_callback)
24043+ENDPROC(xen_do_hypervisor_callback)
24044
24045 /*
24046 * Hypervisor uses this for application faults while it executes.
24047@@ -1231,7 +1727,7 @@ ENTRY(xen_failsafe_callback)
24048 SAVE_ALL
24049 jmp error_exit
24050 CFI_ENDPROC
24051-END(xen_failsafe_callback)
24052+ENDPROC(xen_failsafe_callback)
24053
24054 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
24055 xen_hvm_callback_vector xen_evtchn_do_upcall
24056@@ -1278,18 +1774,33 @@ ENTRY(paranoid_exit)
24057 DEFAULT_FRAME
24058 DISABLE_INTERRUPTS(CLBR_NONE)
24059 TRACE_IRQS_OFF_DEBUG
24060- testl %ebx,%ebx /* swapgs needed? */
24061+ testl $1,%ebx /* swapgs needed? */
24062 jnz paranoid_restore
24063- testl $3,CS(%rsp)
24064+ testb $3,CS(%rsp)
24065 jnz paranoid_userspace
24066+#ifdef CONFIG_PAX_MEMORY_UDEREF
24067+ pax_exit_kernel
24068+ TRACE_IRQS_IRETQ 0
24069+ SWAPGS_UNSAFE_STACK
24070+ RESTORE_ALL 8
24071+ pax_force_retaddr_bts
24072+ jmp irq_return
24073+#endif
24074 paranoid_swapgs:
24075+#ifdef CONFIG_PAX_MEMORY_UDEREF
24076+ pax_exit_kernel_user
24077+#else
24078+ pax_exit_kernel
24079+#endif
24080 TRACE_IRQS_IRETQ 0
24081 SWAPGS_UNSAFE_STACK
24082 RESTORE_ALL 8
24083 jmp irq_return
24084 paranoid_restore:
24085+ pax_exit_kernel
24086 TRACE_IRQS_IRETQ_DEBUG 0
24087 RESTORE_ALL 8
24088+ pax_force_retaddr_bts
24089 jmp irq_return
24090 paranoid_userspace:
24091 GET_THREAD_INFO(%rcx)
24092@@ -1318,7 +1829,7 @@ paranoid_schedule:
24093 TRACE_IRQS_OFF
24094 jmp paranoid_userspace
24095 CFI_ENDPROC
24096-END(paranoid_exit)
24097+ENDPROC(paranoid_exit)
24098
24099 /*
24100 * Exception entry point. This expects an error code/orig_rax on the stack.
24101@@ -1345,12 +1856,23 @@ ENTRY(error_entry)
24102 movq %r14, R14+8(%rsp)
24103 movq %r15, R15+8(%rsp)
24104 xorl %ebx,%ebx
24105- testl $3,CS+8(%rsp)
24106+ testb $3,CS+8(%rsp)
24107 je error_kernelspace
24108 error_swapgs:
24109 SWAPGS
24110 error_sti:
24111+#ifdef CONFIG_PAX_MEMORY_UDEREF
24112+ testb $3, CS+8(%rsp)
24113+ jnz 1f
24114+ pax_enter_kernel
24115+ jmp 2f
24116+1: pax_enter_kernel_user
24117+2:
24118+#else
24119+ pax_enter_kernel
24120+#endif
24121 TRACE_IRQS_OFF
24122+ pax_force_retaddr
24123 ret
24124
24125 /*
24126@@ -1385,7 +1907,7 @@ error_bad_iret:
24127 decl %ebx /* Return to usergs */
24128 jmp error_sti
24129 CFI_ENDPROC
24130-END(error_entry)
24131+ENDPROC(error_entry)
24132
24133
24134 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
24135@@ -1396,7 +1918,7 @@ ENTRY(error_exit)
24136 DISABLE_INTERRUPTS(CLBR_NONE)
24137 TRACE_IRQS_OFF
24138 GET_THREAD_INFO(%rcx)
24139- testl %eax,%eax
24140+ testl $1,%eax
24141 jne retint_kernel
24142 LOCKDEP_SYS_EXIT_IRQ
24143 movl TI_flags(%rcx),%edx
24144@@ -1405,7 +1927,7 @@ ENTRY(error_exit)
24145 jnz retint_careful
24146 jmp retint_swapgs
24147 CFI_ENDPROC
24148-END(error_exit)
24149+ENDPROC(error_exit)
24150
24151 /*
24152 * Test if a given stack is an NMI stack or not.
24153@@ -1463,9 +1985,11 @@ ENTRY(nmi)
24154 * If %cs was not the kernel segment, then the NMI triggered in user
24155 * space, which means it is definitely not nested.
24156 */
24157+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
24158+ je 1f
24159 cmpl $__KERNEL_CS, 16(%rsp)
24160 jne first_nmi
24161-
24162+1:
24163 /*
24164 * Check the special variable on the stack to see if NMIs are
24165 * executing.
24166@@ -1499,8 +2023,7 @@ nested_nmi:
24167
24168 1:
24169 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
24170- leaq -1*8(%rsp), %rdx
24171- movq %rdx, %rsp
24172+ subq $8, %rsp
24173 CFI_ADJUST_CFA_OFFSET 1*8
24174 leaq -10*8(%rsp), %rdx
24175 pushq_cfi $__KERNEL_DS
24176@@ -1518,6 +2041,7 @@ nested_nmi_out:
24177 CFI_RESTORE rdx
24178
24179 /* No need to check faults here */
24180+# pax_force_retaddr_bts
24181 INTERRUPT_RETURN
24182
24183 CFI_RESTORE_STATE
24184@@ -1614,13 +2138,13 @@ end_repeat_nmi:
24185 subq $ORIG_RAX-R15, %rsp
24186 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
24187 /*
24188- * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
24189+ * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
24190 * as we should not be calling schedule in NMI context.
24191 * Even with normal interrupts enabled. An NMI should not be
24192 * setting NEED_RESCHED or anything that normal interrupts and
24193 * exceptions might do.
24194 */
24195- call save_paranoid
24196+ call save_paranoid_nmi
24197 DEFAULT_FRAME 0
24198
24199 /*
24200@@ -1630,9 +2154,9 @@ end_repeat_nmi:
24201 * NMI itself takes a page fault, the page fault that was preempted
24202 * will read the information from the NMI page fault and not the
24203 * origin fault. Save it off and restore it if it changes.
24204- * Use the r12 callee-saved register.
24205+ * Use the r13 callee-saved register.
24206 */
24207- movq %cr2, %r12
24208+ movq %cr2, %r13
24209
24210 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
24211 movq %rsp,%rdi
24212@@ -1641,29 +2165,34 @@ end_repeat_nmi:
24213
24214 /* Did the NMI take a page fault? Restore cr2 if it did */
24215 movq %cr2, %rcx
24216- cmpq %rcx, %r12
24217+ cmpq %rcx, %r13
24218 je 1f
24219- movq %r12, %cr2
24220+ movq %r13, %cr2
24221 1:
24222
24223- testl %ebx,%ebx /* swapgs needed? */
24224+ testl $1,%ebx /* swapgs needed? */
24225 jnz nmi_restore
24226 nmi_swapgs:
24227 SWAPGS_UNSAFE_STACK
24228 nmi_restore:
24229+ pax_exit_kernel_nmi
24230 /* Pop the extra iret frame at once */
24231 RESTORE_ALL 6*8
24232+ testb $3, 8(%rsp)
24233+ jnz 1f
24234+ pax_force_retaddr_bts
24235+1:
24236
24237 /* Clear the NMI executing stack variable */
24238 movq $0, 5*8(%rsp)
24239 jmp irq_return
24240 CFI_ENDPROC
24241-END(nmi)
24242+ENDPROC(nmi)
24243
24244 ENTRY(ignore_sysret)
24245 CFI_STARTPROC
24246 mov $-ENOSYS,%eax
24247 sysret
24248 CFI_ENDPROC
24249-END(ignore_sysret)
24250+ENDPROC(ignore_sysret)
24251
24252diff --git a/arch/x86/kernel/espfix_64.c b/arch/x86/kernel/espfix_64.c
24253index 94d857f..5bce89c 100644
24254--- a/arch/x86/kernel/espfix_64.c
24255+++ b/arch/x86/kernel/espfix_64.c
24256@@ -70,8 +70,7 @@ static DEFINE_MUTEX(espfix_init_mutex);
24257 #define ESPFIX_MAX_PAGES DIV_ROUND_UP(CONFIG_NR_CPUS, ESPFIX_STACKS_PER_PAGE)
24258 static void *espfix_pages[ESPFIX_MAX_PAGES];
24259
24260-static __page_aligned_bss pud_t espfix_pud_page[PTRS_PER_PUD]
24261- __aligned(PAGE_SIZE);
24262+static pud_t espfix_pud_page[PTRS_PER_PUD] __page_aligned_rodata;
24263
24264 static unsigned int page_random, slot_random;
24265
24266@@ -122,14 +121,17 @@ static void init_espfix_random(void)
24267 void __init init_espfix_bsp(void)
24268 {
24269 pgd_t *pgd_p;
24270- pteval_t ptemask;
24271-
24272- ptemask = __supported_pte_mask;
24273+ unsigned long index = pgd_index(ESPFIX_BASE_ADDR);
24274
24275 /* Install the espfix pud into the kernel page directory */
24276- pgd_p = &init_level4_pgt[pgd_index(ESPFIX_BASE_ADDR)];
24277+ pgd_p = &init_level4_pgt[index];
24278 pgd_populate(&init_mm, pgd_p, (pud_t *)espfix_pud_page);
24279
24280+#ifdef CONFIG_PAX_PER_CPU_PGD
24281+ clone_pgd_range(get_cpu_pgd(0, kernel) + index, swapper_pg_dir + index, 1);
24282+ clone_pgd_range(get_cpu_pgd(0, user) + index, swapper_pg_dir + index, 1);
24283+#endif
24284+
24285 /* Randomize the locations */
24286 init_espfix_random();
24287
24288@@ -197,7 +199,7 @@ void init_espfix_ap(void)
24289 set_pte(&pte_p[n*PTE_STRIDE], pte);
24290
24291 /* Job is done for this CPU and any CPU which shares this page */
24292- ACCESS_ONCE(espfix_pages[page]) = stack_page;
24293+ ACCESS_ONCE_RW(espfix_pages[page]) = stack_page;
24294
24295 unlock_done:
24296 mutex_unlock(&espfix_init_mutex);
24297diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
24298index 3386dc9..28bdf81 100644
24299--- a/arch/x86/kernel/ftrace.c
24300+++ b/arch/x86/kernel/ftrace.c
24301@@ -88,7 +88,7 @@ static unsigned long text_ip_addr(unsigned long ip)
24302 * kernel identity mapping to modify code.
24303 */
24304 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
24305- ip = (unsigned long)__va(__pa_symbol(ip));
24306+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
24307
24308 return ip;
24309 }
24310@@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
24311 {
24312 unsigned char replaced[MCOUNT_INSN_SIZE];
24313
24314+ ip = ktla_ktva(ip);
24315+
24316 /*
24317 * Note: Due to modules and __init, code can
24318 * disappear and change, we need to protect against faulting
24319@@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
24320 unsigned char old[MCOUNT_INSN_SIZE];
24321 int ret;
24322
24323- memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
24324+ memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
24325
24326 ftrace_update_func = ip;
24327 /* Make sure the breakpoints see the ftrace_update_func update */
24328@@ -310,7 +312,7 @@ static int add_break(unsigned long ip, const char *old)
24329 unsigned char replaced[MCOUNT_INSN_SIZE];
24330 unsigned char brk = BREAKPOINT_INSTRUCTION;
24331
24332- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
24333+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
24334 return -EFAULT;
24335
24336 /* Make sure it is what we expect it to be */
24337diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
24338index eda1a86..8f6df48 100644
24339--- a/arch/x86/kernel/head64.c
24340+++ b/arch/x86/kernel/head64.c
24341@@ -67,12 +67,12 @@ again:
24342 pgd = *pgd_p;
24343
24344 /*
24345- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
24346- * critical -- __PAGE_OFFSET would point us back into the dynamic
24347+ * The use of __early_va rather than __va here is critical:
24348+ * __va would point us back into the dynamic
24349 * range and we might end up looping forever...
24350 */
24351 if (pgd)
24352- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24353+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
24354 else {
24355 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24356 reset_early_page_tables();
24357@@ -82,13 +82,13 @@ again:
24358 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24359 for (i = 0; i < PTRS_PER_PUD; i++)
24360 pud_p[i] = 0;
24361- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24362+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24363 }
24364 pud_p += pud_index(address);
24365 pud = *pud_p;
24366
24367 if (pud)
24368- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24369+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24370 else {
24371 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24372 reset_early_page_tables();
24373@@ -98,7 +98,7 @@ again:
24374 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24375 for (i = 0; i < PTRS_PER_PMD; i++)
24376 pmd_p[i] = 0;
24377- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24378+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24379 }
24380 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24381 pmd_p[pmd_index(address)] = pmd;
24382@@ -175,7 +175,6 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
24383 if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG)
24384 early_printk("Kernel alive\n");
24385
24386- clear_page(init_level4_pgt);
24387 /* set init_level4_pgt kernel high mapping*/
24388 init_level4_pgt[511] = early_level4_pgt[511];
24389
24390diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24391index f36bd42..0ab4474 100644
24392--- a/arch/x86/kernel/head_32.S
24393+++ b/arch/x86/kernel/head_32.S
24394@@ -26,6 +26,12 @@
24395 /* Physical address */
24396 #define pa(X) ((X) - __PAGE_OFFSET)
24397
24398+#ifdef CONFIG_PAX_KERNEXEC
24399+#define ta(X) (X)
24400+#else
24401+#define ta(X) ((X) - __PAGE_OFFSET)
24402+#endif
24403+
24404 /*
24405 * References to members of the new_cpu_data structure.
24406 */
24407@@ -55,11 +61,7 @@
24408 * and small than max_low_pfn, otherwise will waste some page table entries
24409 */
24410
24411-#if PTRS_PER_PMD > 1
24412-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24413-#else
24414-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24415-#endif
24416+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24417
24418 /* Number of possible pages in the lowmem region */
24419 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24420@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24421 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24422
24423 /*
24424+ * Real beginning of normal "text" segment
24425+ */
24426+ENTRY(stext)
24427+ENTRY(_stext)
24428+
24429+/*
24430 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24431 * %esi points to the real-mode code as a 32-bit pointer.
24432 * CS and DS must be 4 GB flat segments, but we don't depend on
24433@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24434 * can.
24435 */
24436 __HEAD
24437+
24438+#ifdef CONFIG_PAX_KERNEXEC
24439+ jmp startup_32
24440+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24441+.fill PAGE_SIZE-5,1,0xcc
24442+#endif
24443+
24444 ENTRY(startup_32)
24445 movl pa(stack_start),%ecx
24446
24447@@ -106,6 +121,59 @@ ENTRY(startup_32)
24448 2:
24449 leal -__PAGE_OFFSET(%ecx),%esp
24450
24451+#ifdef CONFIG_SMP
24452+ movl $pa(cpu_gdt_table),%edi
24453+ movl $__per_cpu_load,%eax
24454+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24455+ rorl $16,%eax
24456+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24457+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24458+ movl $__per_cpu_end - 1,%eax
24459+ subl $__per_cpu_start,%eax
24460+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24461+#endif
24462+
24463+#ifdef CONFIG_PAX_MEMORY_UDEREF
24464+ movl $NR_CPUS,%ecx
24465+ movl $pa(cpu_gdt_table),%edi
24466+1:
24467+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24468+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24469+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24470+ addl $PAGE_SIZE_asm,%edi
24471+ loop 1b
24472+#endif
24473+
24474+#ifdef CONFIG_PAX_KERNEXEC
24475+ movl $pa(boot_gdt),%edi
24476+ movl $__LOAD_PHYSICAL_ADDR,%eax
24477+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24478+ rorl $16,%eax
24479+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24480+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24481+ rorl $16,%eax
24482+
24483+ ljmp $(__BOOT_CS),$1f
24484+1:
24485+
24486+ movl $NR_CPUS,%ecx
24487+ movl $pa(cpu_gdt_table),%edi
24488+ addl $__PAGE_OFFSET,%eax
24489+1:
24490+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24491+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24492+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24493+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24494+ rorl $16,%eax
24495+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24496+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24497+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24498+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24499+ rorl $16,%eax
24500+ addl $PAGE_SIZE_asm,%edi
24501+ loop 1b
24502+#endif
24503+
24504 /*
24505 * Clear BSS first so that there are no surprises...
24506 */
24507@@ -201,8 +269,11 @@ ENTRY(startup_32)
24508 movl %eax, pa(max_pfn_mapped)
24509
24510 /* Do early initialization of the fixmap area */
24511- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24512- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24513+#ifdef CONFIG_COMPAT_VDSO
24514+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24515+#else
24516+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24517+#endif
24518 #else /* Not PAE */
24519
24520 page_pde_offset = (__PAGE_OFFSET >> 20);
24521@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24522 movl %eax, pa(max_pfn_mapped)
24523
24524 /* Do early initialization of the fixmap area */
24525- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24526- movl %eax,pa(initial_page_table+0xffc)
24527+#ifdef CONFIG_COMPAT_VDSO
24528+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24529+#else
24530+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24531+#endif
24532 #endif
24533
24534 #ifdef CONFIG_PARAVIRT
24535@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24536 cmpl $num_subarch_entries, %eax
24537 jae bad_subarch
24538
24539- movl pa(subarch_entries)(,%eax,4), %eax
24540- subl $__PAGE_OFFSET, %eax
24541- jmp *%eax
24542+ jmp *pa(subarch_entries)(,%eax,4)
24543
24544 bad_subarch:
24545 WEAK(lguest_entry)
24546@@ -261,10 +333,10 @@ WEAK(xen_entry)
24547 __INITDATA
24548
24549 subarch_entries:
24550- .long default_entry /* normal x86/PC */
24551- .long lguest_entry /* lguest hypervisor */
24552- .long xen_entry /* Xen hypervisor */
24553- .long default_entry /* Moorestown MID */
24554+ .long ta(default_entry) /* normal x86/PC */
24555+ .long ta(lguest_entry) /* lguest hypervisor */
24556+ .long ta(xen_entry) /* Xen hypervisor */
24557+ .long ta(default_entry) /* Moorestown MID */
24558 num_subarch_entries = (. - subarch_entries) / 4
24559 .previous
24560 #else
24561@@ -354,6 +426,7 @@ default_entry:
24562 movl pa(mmu_cr4_features),%eax
24563 movl %eax,%cr4
24564
24565+#ifdef CONFIG_X86_PAE
24566 testb $X86_CR4_PAE, %al # check if PAE is enabled
24567 jz enable_paging
24568
24569@@ -382,6 +455,9 @@ default_entry:
24570 /* Make changes effective */
24571 wrmsr
24572
24573+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24574+#endif
24575+
24576 enable_paging:
24577
24578 /*
24579@@ -449,14 +525,20 @@ is486:
24580 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24581 movl %eax,%ss # after changing gdt.
24582
24583- movl $(__USER_DS),%eax # DS/ES contains default USER segment
24584+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24585 movl %eax,%ds
24586 movl %eax,%es
24587
24588 movl $(__KERNEL_PERCPU), %eax
24589 movl %eax,%fs # set this cpu's percpu
24590
24591+#ifdef CONFIG_CC_STACKPROTECTOR
24592 movl $(__KERNEL_STACK_CANARY),%eax
24593+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24594+ movl $(__USER_DS),%eax
24595+#else
24596+ xorl %eax,%eax
24597+#endif
24598 movl %eax,%gs
24599
24600 xorl %eax,%eax # Clear LDT
24601@@ -512,8 +594,11 @@ setup_once:
24602 * relocation. Manually set base address in stack canary
24603 * segment descriptor.
24604 */
24605- movl $gdt_page,%eax
24606+ movl $cpu_gdt_table,%eax
24607 movl $stack_canary,%ecx
24608+#ifdef CONFIG_SMP
24609+ addl $__per_cpu_load,%ecx
24610+#endif
24611 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24612 shrl $16, %ecx
24613 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24614@@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24615 cmpl $2,(%esp) # X86_TRAP_NMI
24616 je is_nmi # Ignore NMI
24617
24618- cmpl $2,%ss:early_recursion_flag
24619+ cmpl $1,%ss:early_recursion_flag
24620 je hlt_loop
24621 incl %ss:early_recursion_flag
24622
24623@@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24624 pushl (20+6*4)(%esp) /* trapno */
24625 pushl $fault_msg
24626 call printk
24627-#endif
24628 call dump_stack
24629+#endif
24630 hlt_loop:
24631 hlt
24632 jmp hlt_loop
24633@@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24634 /* This is the default interrupt "handler" :-) */
24635 ALIGN
24636 ignore_int:
24637- cld
24638 #ifdef CONFIG_PRINTK
24639+ cmpl $2,%ss:early_recursion_flag
24640+ je hlt_loop
24641+ incl %ss:early_recursion_flag
24642+ cld
24643 pushl %eax
24644 pushl %ecx
24645 pushl %edx
24646@@ -617,9 +705,6 @@ ignore_int:
24647 movl $(__KERNEL_DS),%eax
24648 movl %eax,%ds
24649 movl %eax,%es
24650- cmpl $2,early_recursion_flag
24651- je hlt_loop
24652- incl early_recursion_flag
24653 pushl 16(%esp)
24654 pushl 24(%esp)
24655 pushl 32(%esp)
24656@@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24657 /*
24658 * BSS section
24659 */
24660-__PAGE_ALIGNED_BSS
24661- .align PAGE_SIZE
24662 #ifdef CONFIG_X86_PAE
24663+.section .initial_pg_pmd,"a",@progbits
24664 initial_pg_pmd:
24665 .fill 1024*KPMDS,4,0
24666 #else
24667+.section .initial_page_table,"a",@progbits
24668 ENTRY(initial_page_table)
24669 .fill 1024,4,0
24670 #endif
24671+.section .initial_pg_fixmap,"a",@progbits
24672 initial_pg_fixmap:
24673 .fill 1024,4,0
24674+.section .empty_zero_page,"a",@progbits
24675 ENTRY(empty_zero_page)
24676 .fill 4096,1,0
24677+.section .swapper_pg_dir,"a",@progbits
24678 ENTRY(swapper_pg_dir)
24679+#ifdef CONFIG_X86_PAE
24680+ .fill 4,8,0
24681+#else
24682 .fill 1024,4,0
24683+#endif
24684
24685 /*
24686 * This starts the data section.
24687 */
24688 #ifdef CONFIG_X86_PAE
24689-__PAGE_ALIGNED_DATA
24690- /* Page-aligned for the benefit of paravirt? */
24691- .align PAGE_SIZE
24692+.section .initial_page_table,"a",@progbits
24693 ENTRY(initial_page_table)
24694 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24695 # if KPMDS == 3
24696@@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24697 # error "Kernel PMDs should be 1, 2 or 3"
24698 # endif
24699 .align PAGE_SIZE /* needs to be page-sized too */
24700+
24701+#ifdef CONFIG_PAX_PER_CPU_PGD
24702+ENTRY(cpu_pgd)
24703+ .rept 2*NR_CPUS
24704+ .fill 4,8,0
24705+ .endr
24706+#endif
24707+
24708 #endif
24709
24710 .data
24711 .balign 4
24712 ENTRY(stack_start)
24713- .long init_thread_union+THREAD_SIZE
24714+ .long init_thread_union+THREAD_SIZE-8
24715
24716 __INITRODATA
24717 int_msg:
24718@@ -727,7 +825,7 @@ fault_msg:
24719 * segment size, and 32-bit linear address value:
24720 */
24721
24722- .data
24723+.section .rodata,"a",@progbits
24724 .globl boot_gdt_descr
24725 .globl idt_descr
24726
24727@@ -736,7 +834,7 @@ fault_msg:
24728 .word 0 # 32 bit align gdt_desc.address
24729 boot_gdt_descr:
24730 .word __BOOT_DS+7
24731- .long boot_gdt - __PAGE_OFFSET
24732+ .long pa(boot_gdt)
24733
24734 .word 0 # 32-bit align idt_desc.address
24735 idt_descr:
24736@@ -747,7 +845,7 @@ idt_descr:
24737 .word 0 # 32 bit align gdt_desc.address
24738 ENTRY(early_gdt_descr)
24739 .word GDT_ENTRIES*8-1
24740- .long gdt_page /* Overwritten for secondary CPUs */
24741+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
24742
24743 /*
24744 * The boot_gdt must mirror the equivalent in setup.S and is
24745@@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24746 .align L1_CACHE_BYTES
24747 ENTRY(boot_gdt)
24748 .fill GDT_ENTRY_BOOT_CS,8,0
24749- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24750- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24751+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24752+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24753+
24754+ .align PAGE_SIZE_asm
24755+ENTRY(cpu_gdt_table)
24756+ .rept NR_CPUS
24757+ .quad 0x0000000000000000 /* NULL descriptor */
24758+ .quad 0x0000000000000000 /* 0x0b reserved */
24759+ .quad 0x0000000000000000 /* 0x13 reserved */
24760+ .quad 0x0000000000000000 /* 0x1b reserved */
24761+
24762+#ifdef CONFIG_PAX_KERNEXEC
24763+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24764+#else
24765+ .quad 0x0000000000000000 /* 0x20 unused */
24766+#endif
24767+
24768+ .quad 0x0000000000000000 /* 0x28 unused */
24769+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24770+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24771+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24772+ .quad 0x0000000000000000 /* 0x4b reserved */
24773+ .quad 0x0000000000000000 /* 0x53 reserved */
24774+ .quad 0x0000000000000000 /* 0x5b reserved */
24775+
24776+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24777+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24778+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24779+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24780+
24781+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24782+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24783+
24784+ /*
24785+ * Segments used for calling PnP BIOS have byte granularity.
24786+ * The code segments and data segments have fixed 64k limits,
24787+ * the transfer segment sizes are set at run time.
24788+ */
24789+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
24790+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
24791+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
24792+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
24793+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
24794+
24795+ /*
24796+ * The APM segments have byte granularity and their bases
24797+ * are set at run time. All have 64k limits.
24798+ */
24799+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24800+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24801+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
24802+
24803+ .quad 0x00c093000000ffff /* 0xd0 - ESPFIX SS */
24804+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24805+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24806+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24807+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24808+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24809+
24810+ /* Be sure this is zeroed to avoid false validations in Xen */
24811+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24812+ .endr
24813diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24814index a468c0a..8b5a879 100644
24815--- a/arch/x86/kernel/head_64.S
24816+++ b/arch/x86/kernel/head_64.S
24817@@ -20,6 +20,8 @@
24818 #include <asm/processor-flags.h>
24819 #include <asm/percpu.h>
24820 #include <asm/nops.h>
24821+#include <asm/cpufeature.h>
24822+#include <asm/alternative-asm.h>
24823
24824 #ifdef CONFIG_PARAVIRT
24825 #include <asm/asm-offsets.h>
24826@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24827 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24828 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24829 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24830+L4_VMALLOC_START = pgd_index(VMALLOC_START)
24831+L3_VMALLOC_START = pud_index(VMALLOC_START)
24832+L4_VMALLOC_END = pgd_index(VMALLOC_END)
24833+L3_VMALLOC_END = pud_index(VMALLOC_END)
24834+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24835+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24836
24837 .text
24838 __HEAD
24839@@ -89,11 +97,24 @@ startup_64:
24840 * Fixup the physical addresses in the page table
24841 */
24842 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24843+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24844+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24845+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24846+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24847+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24848
24849- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24850- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24851+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
24852+#ifndef CONFIG_XEN
24853+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
24854+#endif
24855+
24856+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24857+
24858+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24859+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24860
24861 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24862+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24863
24864 /*
24865 * Set up the identity mapping for the switchover. These
24866@@ -174,11 +195,12 @@ ENTRY(secondary_startup_64)
24867 * after the boot processor executes this code.
24868 */
24869
24870+ orq $-1, %rbp
24871 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24872 1:
24873
24874- /* Enable PAE mode and PGE */
24875- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24876+ /* Enable PAE mode and PSE/PGE */
24877+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24878 movq %rcx, %cr4
24879
24880 /* Setup early boot stage 4 level pagetables. */
24881@@ -199,10 +221,19 @@ ENTRY(secondary_startup_64)
24882 movl $MSR_EFER, %ecx
24883 rdmsr
24884 btsl $_EFER_SCE, %eax /* Enable System Call */
24885- btl $20,%edi /* No Execute supported? */
24886+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24887 jnc 1f
24888 btsl $_EFER_NX, %eax
24889+ cmpq $-1, %rbp
24890+ je 1f
24891 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24892+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24893+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24894+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24895+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24896+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24897+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24898+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24899 1: wrmsr /* Make changes effective */
24900
24901 /* Setup cr0 */
24902@@ -282,6 +313,7 @@ ENTRY(secondary_startup_64)
24903 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24904 * address given in m16:64.
24905 */
24906+ pax_set_fptr_mask
24907 movq initial_code(%rip),%rax
24908 pushq $0 # fake return address to stop unwinder
24909 pushq $__KERNEL_CS # set correct cs
24910@@ -313,7 +345,7 @@ ENDPROC(start_cpu0)
24911 .quad INIT_PER_CPU_VAR(irq_stack_union)
24912
24913 GLOBAL(stack_start)
24914- .quad init_thread_union+THREAD_SIZE-8
24915+ .quad init_thread_union+THREAD_SIZE-16
24916 .word 0
24917 __FINITDATA
24918
24919@@ -391,7 +423,7 @@ ENTRY(early_idt_handler)
24920 call dump_stack
24921 #ifdef CONFIG_KALLSYMS
24922 leaq early_idt_ripmsg(%rip),%rdi
24923- movq 40(%rsp),%rsi # %rip again
24924+ movq 88(%rsp),%rsi # %rip again
24925 call __print_symbol
24926 #endif
24927 #endif /* EARLY_PRINTK */
24928@@ -420,6 +452,7 @@ ENDPROC(early_idt_handler)
24929 early_recursion_flag:
24930 .long 0
24931
24932+ .section .rodata,"a",@progbits
24933 #ifdef CONFIG_EARLY_PRINTK
24934 early_idt_msg:
24935 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24936@@ -447,29 +480,52 @@ NEXT_PAGE(early_level4_pgt)
24937 NEXT_PAGE(early_dynamic_pgts)
24938 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24939
24940- .data
24941+ .section .rodata,"a",@progbits
24942
24943-#ifndef CONFIG_XEN
24944 NEXT_PAGE(init_level4_pgt)
24945- .fill 512,8,0
24946-#else
24947-NEXT_PAGE(init_level4_pgt)
24948- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24949 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24950 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24951+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
24952+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24953+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
24954+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24955+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24956+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24957 .org init_level4_pgt + L4_START_KERNEL*8, 0
24958 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24959 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24960
24961+#ifdef CONFIG_PAX_PER_CPU_PGD
24962+NEXT_PAGE(cpu_pgd)
24963+ .rept 2*NR_CPUS
24964+ .fill 512,8,0
24965+ .endr
24966+#endif
24967+
24968 NEXT_PAGE(level3_ident_pgt)
24969 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24970+#ifdef CONFIG_XEN
24971 .fill 511, 8, 0
24972+#else
24973+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24974+ .fill 510,8,0
24975+#endif
24976+
24977+NEXT_PAGE(level3_vmalloc_start_pgt)
24978+ .fill 512,8,0
24979+
24980+NEXT_PAGE(level3_vmalloc_end_pgt)
24981+ .fill 512,8,0
24982+
24983+NEXT_PAGE(level3_vmemmap_pgt)
24984+ .fill L3_VMEMMAP_START,8,0
24985+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24986+
24987 NEXT_PAGE(level2_ident_pgt)
24988- /* Since I easily can, map the first 1G.
24989+ /* Since I easily can, map the first 2G.
24990 * Don't set NX because code runs from these pages.
24991 */
24992- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
24993-#endif
24994+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
24995
24996 NEXT_PAGE(level3_kernel_pgt)
24997 .fill L3_START_KERNEL,8,0
24998@@ -477,6 +533,9 @@ NEXT_PAGE(level3_kernel_pgt)
24999 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
25000 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25001
25002+NEXT_PAGE(level2_vmemmap_pgt)
25003+ .fill 512,8,0
25004+
25005 NEXT_PAGE(level2_kernel_pgt)
25006 /*
25007 * 512 MB kernel mapping. We spend a full page on this pagetable
25008@@ -494,28 +553,64 @@ NEXT_PAGE(level2_kernel_pgt)
25009 NEXT_PAGE(level2_fixmap_pgt)
25010 .fill 506,8,0
25011 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25012- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
25013- .fill 5,8,0
25014+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
25015+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
25016+ .fill 4,8,0
25017
25018 NEXT_PAGE(level1_fixmap_pgt)
25019 .fill 512,8,0
25020
25021+NEXT_PAGE(level1_vsyscall_pgt)
25022+ .fill 512,8,0
25023+
25024 #undef PMDS
25025
25026- .data
25027+ .align PAGE_SIZE
25028+ENTRY(cpu_gdt_table)
25029+ .rept NR_CPUS
25030+ .quad 0x0000000000000000 /* NULL descriptor */
25031+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
25032+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
25033+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
25034+ .quad 0x00cffb000000ffff /* __USER32_CS */
25035+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
25036+ .quad 0x00affb000000ffff /* __USER_CS */
25037+
25038+#ifdef CONFIG_PAX_KERNEXEC
25039+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
25040+#else
25041+ .quad 0x0 /* unused */
25042+#endif
25043+
25044+ .quad 0,0 /* TSS */
25045+ .quad 0,0 /* LDT */
25046+ .quad 0,0,0 /* three TLS descriptors */
25047+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
25048+ /* asm/segment.h:GDT_ENTRIES must match this */
25049+
25050+#ifdef CONFIG_PAX_MEMORY_UDEREF
25051+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
25052+#else
25053+ .quad 0x0 /* unused */
25054+#endif
25055+
25056+ /* zero the remaining page */
25057+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
25058+ .endr
25059+
25060 .align 16
25061 .globl early_gdt_descr
25062 early_gdt_descr:
25063 .word GDT_ENTRIES*8-1
25064 early_gdt_descr_base:
25065- .quad INIT_PER_CPU_VAR(gdt_page)
25066+ .quad cpu_gdt_table
25067
25068 ENTRY(phys_base)
25069 /* This must match the first entry in level2_kernel_pgt */
25070 .quad 0x0000000000000000
25071
25072 #include "../../x86/xen/xen-head.S"
25073-
25074- __PAGE_ALIGNED_BSS
25075+
25076+ .section .rodata,"a",@progbits
25077 NEXT_PAGE(empty_zero_page)
25078 .skip PAGE_SIZE
25079diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
25080index 05fd74f..c3548b1 100644
25081--- a/arch/x86/kernel/i386_ksyms_32.c
25082+++ b/arch/x86/kernel/i386_ksyms_32.c
25083@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
25084 EXPORT_SYMBOL(cmpxchg8b_emu);
25085 #endif
25086
25087+EXPORT_SYMBOL_GPL(cpu_gdt_table);
25088+
25089 /* Networking helper routines. */
25090 EXPORT_SYMBOL(csum_partial_copy_generic);
25091+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
25092+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
25093
25094 EXPORT_SYMBOL(__get_user_1);
25095 EXPORT_SYMBOL(__get_user_2);
25096@@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
25097 EXPORT_SYMBOL(___preempt_schedule_context);
25098 #endif
25099 #endif
25100+
25101+#ifdef CONFIG_PAX_KERNEXEC
25102+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
25103+#endif
25104+
25105+#ifdef CONFIG_PAX_PER_CPU_PGD
25106+EXPORT_SYMBOL(cpu_pgd);
25107+#endif
25108diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
25109index a9a4229..6f4d476 100644
25110--- a/arch/x86/kernel/i387.c
25111+++ b/arch/x86/kernel/i387.c
25112@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
25113 static inline bool interrupted_user_mode(void)
25114 {
25115 struct pt_regs *regs = get_irq_regs();
25116- return regs && user_mode_vm(regs);
25117+ return regs && user_mode(regs);
25118 }
25119
25120 /*
25121diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
25122index e7cc537..67d7372 100644
25123--- a/arch/x86/kernel/i8259.c
25124+++ b/arch/x86/kernel/i8259.c
25125@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
25126 static void make_8259A_irq(unsigned int irq)
25127 {
25128 disable_irq_nosync(irq);
25129- io_apic_irqs &= ~(1<<irq);
25130+ io_apic_irqs &= ~(1UL<<irq);
25131 irq_set_chip_and_handler(irq, &i8259A_chip, handle_level_irq);
25132 enable_irq(irq);
25133 }
25134@@ -208,7 +208,7 @@ spurious_8259A_irq:
25135 "spurious 8259A interrupt: IRQ%d.\n", irq);
25136 spurious_irq_mask |= irqmask;
25137 }
25138- atomic_inc(&irq_err_count);
25139+ atomic_inc_unchecked(&irq_err_count);
25140 /*
25141 * Theoretically we do not have to handle this IRQ,
25142 * but in Linux this does not cause problems and is
25143@@ -349,14 +349,16 @@ static void init_8259A(int auto_eoi)
25144 /* (slave's support for AEOI in flat mode is to be investigated) */
25145 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
25146
25147+ pax_open_kernel();
25148 if (auto_eoi)
25149 /*
25150 * In AEOI mode we just have to mask the interrupt
25151 * when acking.
25152 */
25153- i8259A_chip.irq_mask_ack = disable_8259A_irq;
25154+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
25155 else
25156- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25157+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25158+ pax_close_kernel();
25159
25160 udelay(100); /* wait for 8259A to initialize */
25161
25162diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
25163index a979b5b..1d6db75 100644
25164--- a/arch/x86/kernel/io_delay.c
25165+++ b/arch/x86/kernel/io_delay.c
25166@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
25167 * Quirk table for systems that misbehave (lock up, etc.) if port
25168 * 0x80 is used:
25169 */
25170-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
25171+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
25172 {
25173 .callback = dmi_io_delay_0xed_port,
25174 .ident = "Compaq Presario V6000",
25175diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
25176index 4ddaf66..49d5c18 100644
25177--- a/arch/x86/kernel/ioport.c
25178+++ b/arch/x86/kernel/ioport.c
25179@@ -6,6 +6,7 @@
25180 #include <linux/sched.h>
25181 #include <linux/kernel.h>
25182 #include <linux/capability.h>
25183+#include <linux/security.h>
25184 #include <linux/errno.h>
25185 #include <linux/types.h>
25186 #include <linux/ioport.h>
25187@@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25188 return -EINVAL;
25189 if (turn_on && !capable(CAP_SYS_RAWIO))
25190 return -EPERM;
25191+#ifdef CONFIG_GRKERNSEC_IO
25192+ if (turn_on && grsec_disable_privio) {
25193+ gr_handle_ioperm();
25194+ return -ENODEV;
25195+ }
25196+#endif
25197
25198 /*
25199 * If it's the first ioperm() call in this thread's lifetime, set the
25200@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25201 * because the ->io_bitmap_max value must match the bitmap
25202 * contents:
25203 */
25204- tss = &per_cpu(init_tss, get_cpu());
25205+ tss = init_tss + get_cpu();
25206
25207 if (turn_on)
25208 bitmap_clear(t->io_bitmap_ptr, from, num);
25209@@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
25210 if (level > old) {
25211 if (!capable(CAP_SYS_RAWIO))
25212 return -EPERM;
25213+#ifdef CONFIG_GRKERNSEC_IO
25214+ if (grsec_disable_privio) {
25215+ gr_handle_iopl();
25216+ return -ENODEV;
25217+ }
25218+#endif
25219 }
25220 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
25221 t->iopl = level << 12;
25222diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
25223index 922d285..6d20692 100644
25224--- a/arch/x86/kernel/irq.c
25225+++ b/arch/x86/kernel/irq.c
25226@@ -22,7 +22,7 @@
25227 #define CREATE_TRACE_POINTS
25228 #include <asm/trace/irq_vectors.h>
25229
25230-atomic_t irq_err_count;
25231+atomic_unchecked_t irq_err_count;
25232
25233 /* Function pointer for generic interrupt vector handling */
25234 void (*x86_platform_ipi_callback)(void) = NULL;
25235@@ -132,9 +132,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
25236 seq_printf(p, "%10u ", irq_stats(j)->irq_hv_callback_count);
25237 seq_printf(p, " Hypervisor callback interrupts\n");
25238 #endif
25239- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
25240+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
25241 #if defined(CONFIG_X86_IO_APIC)
25242- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
25243+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
25244 #endif
25245 return 0;
25246 }
25247@@ -174,7 +174,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
25248
25249 u64 arch_irq_stat(void)
25250 {
25251- u64 sum = atomic_read(&irq_err_count);
25252+ u64 sum = atomic_read_unchecked(&irq_err_count);
25253 return sum;
25254 }
25255
25256diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
25257index 63ce838..2ea3e06 100644
25258--- a/arch/x86/kernel/irq_32.c
25259+++ b/arch/x86/kernel/irq_32.c
25260@@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
25261
25262 #ifdef CONFIG_DEBUG_STACKOVERFLOW
25263
25264+extern void gr_handle_kernel_exploit(void);
25265+
25266 int sysctl_panic_on_stackoverflow __read_mostly;
25267
25268 /* Debugging check for stack overflow: is there less than 1KB free? */
25269@@ -39,13 +41,14 @@ static int check_stack_overflow(void)
25270 __asm__ __volatile__("andl %%esp,%0" :
25271 "=r" (sp) : "0" (THREAD_SIZE - 1));
25272
25273- return sp < (sizeof(struct thread_info) + STACK_WARN);
25274+ return sp < STACK_WARN;
25275 }
25276
25277 static void print_stack_overflow(void)
25278 {
25279 printk(KERN_WARNING "low stack detected by irq handler\n");
25280 dump_stack();
25281+ gr_handle_kernel_exploit();
25282 if (sysctl_panic_on_stackoverflow)
25283 panic("low stack detected by irq handler - check messages\n");
25284 }
25285@@ -84,10 +87,9 @@ static inline void *current_stack(void)
25286 static inline int
25287 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25288 {
25289- struct irq_stack *curstk, *irqstk;
25290+ struct irq_stack *irqstk;
25291 u32 *isp, *prev_esp, arg1, arg2;
25292
25293- curstk = (struct irq_stack *) current_stack();
25294 irqstk = __this_cpu_read(hardirq_stack);
25295
25296 /*
25297@@ -96,15 +98,19 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25298 * handler) we can't do that and just have to keep using the
25299 * current stack (which is the irq stack already after all)
25300 */
25301- if (unlikely(curstk == irqstk))
25302+ if (unlikely((void *)current_stack_pointer - (void *)irqstk < THREAD_SIZE))
25303 return 0;
25304
25305- isp = (u32 *) ((char *)irqstk + sizeof(*irqstk));
25306+ isp = (u32 *) ((char *)irqstk + sizeof(*irqstk) - 8);
25307
25308 /* Save the next esp at the bottom of the stack */
25309 prev_esp = (u32 *)irqstk;
25310 *prev_esp = current_stack_pointer;
25311
25312+#ifdef CONFIG_PAX_MEMORY_UDEREF
25313+ __set_fs(MAKE_MM_SEG(0));
25314+#endif
25315+
25316 if (unlikely(overflow))
25317 call_on_stack(print_stack_overflow, isp);
25318
25319@@ -115,6 +121,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25320 : "0" (irq), "1" (desc), "2" (isp),
25321 "D" (desc->handle_irq)
25322 : "memory", "cc", "ecx");
25323+
25324+#ifdef CONFIG_PAX_MEMORY_UDEREF
25325+ __set_fs(current_thread_info()->addr_limit);
25326+#endif
25327+
25328 return 1;
25329 }
25330
25331@@ -123,32 +134,18 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25332 */
25333 void irq_ctx_init(int cpu)
25334 {
25335- struct irq_stack *irqstk;
25336-
25337 if (per_cpu(hardirq_stack, cpu))
25338 return;
25339
25340- irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25341- THREADINFO_GFP,
25342- THREAD_SIZE_ORDER));
25343- per_cpu(hardirq_stack, cpu) = irqstk;
25344-
25345- irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25346- THREADINFO_GFP,
25347- THREAD_SIZE_ORDER));
25348- per_cpu(softirq_stack, cpu) = irqstk;
25349-
25350- printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
25351- cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
25352+ per_cpu(hardirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25353+ per_cpu(softirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25354 }
25355
25356 void do_softirq_own_stack(void)
25357 {
25358- struct thread_info *curstk;
25359 struct irq_stack *irqstk;
25360 u32 *isp, *prev_esp;
25361
25362- curstk = current_stack();
25363 irqstk = __this_cpu_read(softirq_stack);
25364
25365 /* build the stack frame on the softirq stack */
25366@@ -158,7 +155,16 @@ void do_softirq_own_stack(void)
25367 prev_esp = (u32 *)irqstk;
25368 *prev_esp = current_stack_pointer;
25369
25370+#ifdef CONFIG_PAX_MEMORY_UDEREF
25371+ __set_fs(MAKE_MM_SEG(0));
25372+#endif
25373+
25374 call_on_stack(__do_softirq, isp);
25375+
25376+#ifdef CONFIG_PAX_MEMORY_UDEREF
25377+ __set_fs(current_thread_info()->addr_limit);
25378+#endif
25379+
25380 }
25381
25382 bool handle_irq(unsigned irq, struct pt_regs *regs)
25383@@ -172,7 +178,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25384 if (unlikely(!desc))
25385 return false;
25386
25387- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25388+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25389 if (unlikely(overflow))
25390 print_stack_overflow();
25391 desc->handle_irq(irq, desc);
25392diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25393index e4b503d..824fce8 100644
25394--- a/arch/x86/kernel/irq_64.c
25395+++ b/arch/x86/kernel/irq_64.c
25396@@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
25397 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
25398 EXPORT_PER_CPU_SYMBOL(irq_regs);
25399
25400+extern void gr_handle_kernel_exploit(void);
25401+
25402 int sysctl_panic_on_stackoverflow;
25403
25404 /*
25405@@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25406 u64 estack_top, estack_bottom;
25407 u64 curbase = (u64)task_stack_page(current);
25408
25409- if (user_mode_vm(regs))
25410+ if (user_mode(regs))
25411 return;
25412
25413 if (regs->sp >= curbase + sizeof(struct thread_info) +
25414@@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25415 irq_stack_top, irq_stack_bottom,
25416 estack_top, estack_bottom);
25417
25418+ gr_handle_kernel_exploit();
25419+
25420 if (sysctl_panic_on_stackoverflow)
25421 panic("low stack detected by irq handler - check messages\n");
25422 #endif
25423diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25424index 26d5a55..a01160a 100644
25425--- a/arch/x86/kernel/jump_label.c
25426+++ b/arch/x86/kernel/jump_label.c
25427@@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25428 * Jump label is enabled for the first time.
25429 * So we expect a default_nop...
25430 */
25431- if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25432+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25433 != 0))
25434 bug_at((void *)entry->code, __LINE__);
25435 } else {
25436@@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25437 * ...otherwise expect an ideal_nop. Otherwise
25438 * something went horribly wrong.
25439 */
25440- if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25441+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25442 != 0))
25443 bug_at((void *)entry->code, __LINE__);
25444 }
25445@@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25446 * are converting the default nop to the ideal nop.
25447 */
25448 if (init) {
25449- if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25450+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25451 bug_at((void *)entry->code, __LINE__);
25452 } else {
25453 code.jump = 0xe9;
25454 code.offset = entry->target -
25455 (entry->code + JUMP_LABEL_NOP_SIZE);
25456- if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25457+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25458 bug_at((void *)entry->code, __LINE__);
25459 }
25460 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25461diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25462index 7ec1d5f..5a7d130 100644
25463--- a/arch/x86/kernel/kgdb.c
25464+++ b/arch/x86/kernel/kgdb.c
25465@@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25466 #ifdef CONFIG_X86_32
25467 switch (regno) {
25468 case GDB_SS:
25469- if (!user_mode_vm(regs))
25470+ if (!user_mode(regs))
25471 *(unsigned long *)mem = __KERNEL_DS;
25472 break;
25473 case GDB_SP:
25474- if (!user_mode_vm(regs))
25475+ if (!user_mode(regs))
25476 *(unsigned long *)mem = kernel_stack_pointer(regs);
25477 break;
25478 case GDB_GS:
25479@@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25480 bp->attr.bp_addr = breakinfo[breakno].addr;
25481 bp->attr.bp_len = breakinfo[breakno].len;
25482 bp->attr.bp_type = breakinfo[breakno].type;
25483- info->address = breakinfo[breakno].addr;
25484+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25485+ info->address = ktla_ktva(breakinfo[breakno].addr);
25486+ else
25487+ info->address = breakinfo[breakno].addr;
25488 info->len = breakinfo[breakno].len;
25489 info->type = breakinfo[breakno].type;
25490 val = arch_install_hw_breakpoint(bp);
25491@@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25492 case 'k':
25493 /* clear the trace bit */
25494 linux_regs->flags &= ~X86_EFLAGS_TF;
25495- atomic_set(&kgdb_cpu_doing_single_step, -1);
25496+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25497
25498 /* set the trace bit if we're stepping */
25499 if (remcomInBuffer[0] == 's') {
25500 linux_regs->flags |= X86_EFLAGS_TF;
25501- atomic_set(&kgdb_cpu_doing_single_step,
25502+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25503 raw_smp_processor_id());
25504 }
25505
25506@@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25507
25508 switch (cmd) {
25509 case DIE_DEBUG:
25510- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25511+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25512 if (user_mode(regs))
25513 return single_step_cont(regs, args);
25514 break;
25515@@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25516 #endif /* CONFIG_DEBUG_RODATA */
25517
25518 bpt->type = BP_BREAKPOINT;
25519- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25520+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25521 BREAK_INSTR_SIZE);
25522 if (err)
25523 return err;
25524- err = probe_kernel_write((char *)bpt->bpt_addr,
25525+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25526 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25527 #ifdef CONFIG_DEBUG_RODATA
25528 if (!err)
25529@@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25530 return -EBUSY;
25531 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25532 BREAK_INSTR_SIZE);
25533- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25534+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25535 if (err)
25536 return err;
25537 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25538@@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25539 if (mutex_is_locked(&text_mutex))
25540 goto knl_write;
25541 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25542- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25543+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25544 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25545 goto knl_write;
25546 return err;
25547 knl_write:
25548 #endif /* CONFIG_DEBUG_RODATA */
25549- return probe_kernel_write((char *)bpt->bpt_addr,
25550+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25551 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25552 }
25553
25554diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25555index 67e6d19..731ed28 100644
25556--- a/arch/x86/kernel/kprobes/core.c
25557+++ b/arch/x86/kernel/kprobes/core.c
25558@@ -120,9 +120,12 @@ __synthesize_relative_insn(void *from, void *to, u8 op)
25559 s32 raddr;
25560 } __packed *insn;
25561
25562- insn = (struct __arch_relative_insn *)from;
25563+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
25564+
25565+ pax_open_kernel();
25566 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25567 insn->op = op;
25568+ pax_close_kernel();
25569 }
25570
25571 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25572@@ -168,7 +171,7 @@ int can_boost(kprobe_opcode_t *opcodes)
25573 kprobe_opcode_t opcode;
25574 kprobe_opcode_t *orig_opcodes = opcodes;
25575
25576- if (search_exception_tables((unsigned long)opcodes))
25577+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25578 return 0; /* Page fault may occur on this address. */
25579
25580 retry:
25581@@ -242,9 +245,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25582 * for the first byte, we can recover the original instruction
25583 * from it and kp->opcode.
25584 */
25585- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25586+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25587 buf[0] = kp->opcode;
25588- return (unsigned long)buf;
25589+ return ktva_ktla((unsigned long)buf);
25590 }
25591
25592 /*
25593@@ -336,7 +339,9 @@ int __copy_instruction(u8 *dest, u8 *src)
25594 /* Another subsystem puts a breakpoint, failed to recover */
25595 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25596 return 0;
25597+ pax_open_kernel();
25598 memcpy(dest, insn.kaddr, insn.length);
25599+ pax_close_kernel();
25600
25601 #ifdef CONFIG_X86_64
25602 if (insn_rip_relative(&insn)) {
25603@@ -363,7 +368,9 @@ int __copy_instruction(u8 *dest, u8 *src)
25604 return 0;
25605 }
25606 disp = (u8 *) dest + insn_offset_displacement(&insn);
25607+ pax_open_kernel();
25608 *(s32 *) disp = (s32) newdisp;
25609+ pax_close_kernel();
25610 }
25611 #endif
25612 return insn.length;
25613@@ -505,7 +512,7 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
25614 * nor set current_kprobe, because it doesn't use single
25615 * stepping.
25616 */
25617- regs->ip = (unsigned long)p->ainsn.insn;
25618+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25619 preempt_enable_no_resched();
25620 return;
25621 }
25622@@ -522,9 +529,9 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
25623 regs->flags &= ~X86_EFLAGS_IF;
25624 /* single step inline if the instruction is an int3 */
25625 if (p->opcode == BREAKPOINT_INSTRUCTION)
25626- regs->ip = (unsigned long)p->addr;
25627+ regs->ip = ktla_ktva((unsigned long)p->addr);
25628 else
25629- regs->ip = (unsigned long)p->ainsn.insn;
25630+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25631 }
25632 NOKPROBE_SYMBOL(setup_singlestep);
25633
25634@@ -574,7 +581,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
25635 struct kprobe *p;
25636 struct kprobe_ctlblk *kcb;
25637
25638- if (user_mode_vm(regs))
25639+ if (user_mode(regs))
25640 return 0;
25641
25642 addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
25643@@ -609,7 +616,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
25644 setup_singlestep(p, regs, kcb, 0);
25645 return 1;
25646 }
25647- } else if (*addr != BREAKPOINT_INSTRUCTION) {
25648+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25649 /*
25650 * The breakpoint instruction was removed right
25651 * after we hit it. Another cpu has removed
25652@@ -656,6 +663,9 @@ static void __used kretprobe_trampoline_holder(void)
25653 " movq %rax, 152(%rsp)\n"
25654 RESTORE_REGS_STRING
25655 " popfq\n"
25656+#ifdef KERNEXEC_PLUGIN
25657+ " btsq $63,(%rsp)\n"
25658+#endif
25659 #else
25660 " pushf\n"
25661 SAVE_REGS_STRING
25662@@ -796,7 +806,7 @@ static void resume_execution(struct kprobe *p, struct pt_regs *regs,
25663 struct kprobe_ctlblk *kcb)
25664 {
25665 unsigned long *tos = stack_addr(regs);
25666- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25667+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25668 unsigned long orig_ip = (unsigned long)p->addr;
25669 kprobe_opcode_t *insn = p->ainsn.insn;
25670
25671@@ -979,7 +989,7 @@ int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val,
25672 struct die_args *args = data;
25673 int ret = NOTIFY_DONE;
25674
25675- if (args->regs && user_mode_vm(args->regs))
25676+ if (args->regs && user_mode(args->regs))
25677 return ret;
25678
25679 if (val == DIE_GPF) {
25680diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25681index f1314d0..15f3154 100644
25682--- a/arch/x86/kernel/kprobes/opt.c
25683+++ b/arch/x86/kernel/kprobes/opt.c
25684@@ -79,6 +79,7 @@ found:
25685 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25686 static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25687 {
25688+ pax_open_kernel();
25689 #ifdef CONFIG_X86_64
25690 *addr++ = 0x48;
25691 *addr++ = 0xbf;
25692@@ -86,6 +87,7 @@ static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25693 *addr++ = 0xb8;
25694 #endif
25695 *(unsigned long *)addr = val;
25696+ pax_close_kernel();
25697 }
25698
25699 asm (
25700@@ -337,7 +339,7 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25701 * Verify if the address gap is in 2GB range, because this uses
25702 * a relative jump.
25703 */
25704- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25705+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25706 if (abs(rel) > 0x7fffffff) {
25707 __arch_remove_optimized_kprobe(op, 0);
25708 return -ERANGE;
25709@@ -354,16 +356,18 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25710 op->optinsn.size = ret;
25711
25712 /* Copy arch-dep-instance from template */
25713- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25714+ pax_open_kernel();
25715+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25716+ pax_close_kernel();
25717
25718 /* Set probe information */
25719 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25720
25721 /* Set probe function call */
25722- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25723+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25724
25725 /* Set returning jmp instruction at the tail of out-of-line buffer */
25726- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25727+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25728 (u8 *)op->kp.addr + op->optinsn.size);
25729
25730 flush_icache_range((unsigned long) buf,
25731@@ -388,7 +392,7 @@ void arch_optimize_kprobes(struct list_head *oplist)
25732 WARN_ON(kprobe_disabled(&op->kp));
25733
25734 /* Backup instructions which will be replaced by jump address */
25735- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25736+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25737 RELATIVE_ADDR_SIZE);
25738
25739 insn_buf[0] = RELATIVEJUMP_OPCODE;
25740@@ -436,7 +440,7 @@ int setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25741 /* This kprobe is really able to run optimized path. */
25742 op = container_of(p, struct optimized_kprobe, kp);
25743 /* Detour through copied instructions */
25744- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25745+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25746 if (!reenter)
25747 reset_current_kprobe();
25748 preempt_enable_no_resched();
25749diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25750index c2bedae..25e7ab60 100644
25751--- a/arch/x86/kernel/ksysfs.c
25752+++ b/arch/x86/kernel/ksysfs.c
25753@@ -184,7 +184,7 @@ out:
25754
25755 static struct kobj_attribute type_attr = __ATTR_RO(type);
25756
25757-static struct bin_attribute data_attr = {
25758+static bin_attribute_no_const data_attr __read_only = {
25759 .attr = {
25760 .name = "data",
25761 .mode = S_IRUGO,
25762diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
25763index f6945bef..94f6434 100644
25764--- a/arch/x86/kernel/kvm.c
25765+++ b/arch/x86/kernel/kvm.c
25766@@ -283,7 +283,14 @@ NOKPROBE_SYMBOL(do_async_page_fault);
25767 static void __init paravirt_ops_setup(void)
25768 {
25769 pv_info.name = "KVM";
25770- pv_info.paravirt_enabled = 1;
25771+
25772+ /*
25773+ * KVM isn't paravirt in the sense of paravirt_enabled. A KVM
25774+ * guest kernel works like a bare metal kernel with additional
25775+ * features, and paravirt_enabled is about features that are
25776+ * missing.
25777+ */
25778+ pv_info.paravirt_enabled = 0;
25779
25780 if (kvm_para_has_feature(KVM_FEATURE_NOP_IO_DELAY))
25781 pv_cpu_ops.io_delay = kvm_io_delay;
25782diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c
25783index d9156ce..a2de9bc 100644
25784--- a/arch/x86/kernel/kvmclock.c
25785+++ b/arch/x86/kernel/kvmclock.c
25786@@ -263,7 +263,6 @@ void __init kvmclock_init(void)
25787 #endif
25788 kvm_get_preset_lpj();
25789 clocksource_register_hz(&kvm_clock, NSEC_PER_SEC);
25790- pv_info.paravirt_enabled = 1;
25791 pv_info.name = "KVM";
25792
25793 if (kvm_para_has_feature(KVM_FEATURE_CLOCKSOURCE_STABLE_BIT))
25794diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25795index c37886d..d851d32 100644
25796--- a/arch/x86/kernel/ldt.c
25797+++ b/arch/x86/kernel/ldt.c
25798@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25799 if (reload) {
25800 #ifdef CONFIG_SMP
25801 preempt_disable();
25802- load_LDT(pc);
25803+ load_LDT_nolock(pc);
25804 if (!cpumask_equal(mm_cpumask(current->mm),
25805 cpumask_of(smp_processor_id())))
25806 smp_call_function(flush_ldt, current->mm, 1);
25807 preempt_enable();
25808 #else
25809- load_LDT(pc);
25810+ load_LDT_nolock(pc);
25811 #endif
25812 }
25813 if (oldsize) {
25814@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25815 return err;
25816
25817 for (i = 0; i < old->size; i++)
25818- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25819+ write_ldt_entry(new->ldt, i, old->ldt + i);
25820 return 0;
25821 }
25822
25823@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25824 retval = copy_ldt(&mm->context, &old_mm->context);
25825 mutex_unlock(&old_mm->context.lock);
25826 }
25827+
25828+ if (tsk == current) {
25829+ mm->context.vdso = 0;
25830+
25831+#ifdef CONFIG_X86_32
25832+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25833+ mm->context.user_cs_base = 0UL;
25834+ mm->context.user_cs_limit = ~0UL;
25835+
25836+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25837+ cpus_clear(mm->context.cpu_user_cs_mask);
25838+#endif
25839+
25840+#endif
25841+#endif
25842+
25843+ }
25844+
25845 return retval;
25846 }
25847
25848@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25849 }
25850 }
25851
25852+#ifdef CONFIG_PAX_SEGMEXEC
25853+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25854+ error = -EINVAL;
25855+ goto out_unlock;
25856+ }
25857+#endif
25858+
25859 if (!IS_ENABLED(CONFIG_X86_16BIT) && !ldt_info.seg_32bit) {
25860 error = -EINVAL;
25861 goto out_unlock;
25862diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25863index 72e8e31..f2f1605 100644
25864--- a/arch/x86/kernel/machine_kexec_32.c
25865+++ b/arch/x86/kernel/machine_kexec_32.c
25866@@ -25,7 +25,7 @@
25867 #include <asm/cacheflush.h>
25868 #include <asm/debugreg.h>
25869
25870-static void set_idt(void *newidt, __u16 limit)
25871+static void set_idt(struct desc_struct *newidt, __u16 limit)
25872 {
25873 struct desc_ptr curidt;
25874
25875@@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
25876 }
25877
25878
25879-static void set_gdt(void *newgdt, __u16 limit)
25880+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25881 {
25882 struct desc_ptr curgdt;
25883
25884@@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
25885 }
25886
25887 control_page = page_address(image->control_code_page);
25888- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25889+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25890
25891 relocate_kernel_ptr = control_page;
25892 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25893diff --git a/arch/x86/kernel/mcount_64.S b/arch/x86/kernel/mcount_64.S
25894index c73aecf..4c63630 100644
25895--- a/arch/x86/kernel/mcount_64.S
25896+++ b/arch/x86/kernel/mcount_64.S
25897@@ -7,7 +7,7 @@
25898 #include <linux/linkage.h>
25899 #include <asm/ptrace.h>
25900 #include <asm/ftrace.h>
25901-
25902+#include <asm/alternative-asm.h>
25903
25904 .code64
25905 .section .entry.text, "ax"
25906@@ -24,8 +24,9 @@
25907 #ifdef CONFIG_DYNAMIC_FTRACE
25908
25909 ENTRY(function_hook)
25910+ pax_force_retaddr
25911 retq
25912-END(function_hook)
25913+ENDPROC(function_hook)
25914
25915 /* skip is set if stack has been adjusted */
25916 .macro ftrace_caller_setup skip=0
25917@@ -62,8 +63,9 @@ GLOBAL(ftrace_graph_call)
25918 #endif
25919
25920 GLOBAL(ftrace_stub)
25921+ pax_force_retaddr
25922 retq
25923-END(ftrace_caller)
25924+ENDPROC(ftrace_caller)
25925
25926 ENTRY(ftrace_regs_caller)
25927 /* Save the current flags before compare (in SS location)*/
25928@@ -127,7 +129,7 @@ GLOBAL(ftrace_regs_call)
25929 popfq
25930 jmp ftrace_stub
25931
25932-END(ftrace_regs_caller)
25933+ENDPROC(ftrace_regs_caller)
25934
25935
25936 #else /* ! CONFIG_DYNAMIC_FTRACE */
25937@@ -145,6 +147,7 @@ ENTRY(function_hook)
25938 #endif
25939
25940 GLOBAL(ftrace_stub)
25941+ pax_force_retaddr
25942 retq
25943
25944 trace:
25945@@ -158,12 +161,13 @@ trace:
25946 #endif
25947 subq $MCOUNT_INSN_SIZE, %rdi
25948
25949+ pax_force_fptr ftrace_trace_function
25950 call *ftrace_trace_function
25951
25952 MCOUNT_RESTORE_FRAME
25953
25954 jmp ftrace_stub
25955-END(function_hook)
25956+ENDPROC(function_hook)
25957 #endif /* CONFIG_DYNAMIC_FTRACE */
25958 #endif /* CONFIG_FUNCTION_TRACER */
25959
25960@@ -185,8 +189,9 @@ ENTRY(ftrace_graph_caller)
25961
25962 MCOUNT_RESTORE_FRAME
25963
25964+ pax_force_retaddr
25965 retq
25966-END(ftrace_graph_caller)
25967+ENDPROC(ftrace_graph_caller)
25968
25969 GLOBAL(return_to_handler)
25970 subq $24, %rsp
25971@@ -202,5 +207,7 @@ GLOBAL(return_to_handler)
25972 movq 8(%rsp), %rdx
25973 movq (%rsp), %rax
25974 addq $24, %rsp
25975+ pax_force_fptr %rdi
25976 jmp *%rdi
25977+ENDPROC(return_to_handler)
25978 #endif
25979diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25980index e69f988..da078ea 100644
25981--- a/arch/x86/kernel/module.c
25982+++ b/arch/x86/kernel/module.c
25983@@ -81,17 +81,62 @@ static unsigned long int get_module_load_offset(void)
25984 }
25985 #endif
25986
25987-void *module_alloc(unsigned long size)
25988+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25989 {
25990- if (PAGE_ALIGN(size) > MODULES_LEN)
25991+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25992 return NULL;
25993 return __vmalloc_node_range(size, 1,
25994 MODULES_VADDR + get_module_load_offset(),
25995- MODULES_END, GFP_KERNEL | __GFP_HIGHMEM,
25996- PAGE_KERNEL_EXEC, NUMA_NO_NODE,
25997+ MODULES_END, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
25998+ prot, NUMA_NO_NODE,
25999 __builtin_return_address(0));
26000 }
26001
26002+void *module_alloc(unsigned long size)
26003+{
26004+
26005+#ifdef CONFIG_PAX_KERNEXEC
26006+ return __module_alloc(size, PAGE_KERNEL);
26007+#else
26008+ return __module_alloc(size, PAGE_KERNEL_EXEC);
26009+#endif
26010+
26011+}
26012+
26013+#ifdef CONFIG_PAX_KERNEXEC
26014+#ifdef CONFIG_X86_32
26015+void *module_alloc_exec(unsigned long size)
26016+{
26017+ struct vm_struct *area;
26018+
26019+ if (size == 0)
26020+ return NULL;
26021+
26022+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
26023+return area ? area->addr : NULL;
26024+}
26025+EXPORT_SYMBOL(module_alloc_exec);
26026+
26027+void module_free_exec(struct module *mod, void *module_region)
26028+{
26029+ vunmap(module_region);
26030+}
26031+EXPORT_SYMBOL(module_free_exec);
26032+#else
26033+void module_free_exec(struct module *mod, void *module_region)
26034+{
26035+ module_free(mod, module_region);
26036+}
26037+EXPORT_SYMBOL(module_free_exec);
26038+
26039+void *module_alloc_exec(unsigned long size)
26040+{
26041+ return __module_alloc(size, PAGE_KERNEL_RX);
26042+}
26043+EXPORT_SYMBOL(module_alloc_exec);
26044+#endif
26045+#endif
26046+
26047 #ifdef CONFIG_X86_32
26048 int apply_relocate(Elf32_Shdr *sechdrs,
26049 const char *strtab,
26050@@ -102,14 +147,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26051 unsigned int i;
26052 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
26053 Elf32_Sym *sym;
26054- uint32_t *location;
26055+ uint32_t *plocation, location;
26056
26057 DEBUGP("Applying relocate section %u to %u\n",
26058 relsec, sechdrs[relsec].sh_info);
26059 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
26060 /* This is where to make the change */
26061- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
26062- + rel[i].r_offset;
26063+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
26064+ location = (uint32_t)plocation;
26065+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
26066+ plocation = ktla_ktva((void *)plocation);
26067 /* This is the symbol it is referring to. Note that all
26068 undefined symbols have been resolved. */
26069 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
26070@@ -118,11 +165,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26071 switch (ELF32_R_TYPE(rel[i].r_info)) {
26072 case R_386_32:
26073 /* We add the value into the location given */
26074- *location += sym->st_value;
26075+ pax_open_kernel();
26076+ *plocation += sym->st_value;
26077+ pax_close_kernel();
26078 break;
26079 case R_386_PC32:
26080 /* Add the value, subtract its position */
26081- *location += sym->st_value - (uint32_t)location;
26082+ pax_open_kernel();
26083+ *plocation += sym->st_value - location;
26084+ pax_close_kernel();
26085 break;
26086 default:
26087 pr_err("%s: Unknown relocation: %u\n",
26088@@ -167,21 +218,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
26089 case R_X86_64_NONE:
26090 break;
26091 case R_X86_64_64:
26092+ pax_open_kernel();
26093 *(u64 *)loc = val;
26094+ pax_close_kernel();
26095 break;
26096 case R_X86_64_32:
26097+ pax_open_kernel();
26098 *(u32 *)loc = val;
26099+ pax_close_kernel();
26100 if (val != *(u32 *)loc)
26101 goto overflow;
26102 break;
26103 case R_X86_64_32S:
26104+ pax_open_kernel();
26105 *(s32 *)loc = val;
26106+ pax_close_kernel();
26107 if ((s64)val != *(s32 *)loc)
26108 goto overflow;
26109 break;
26110 case R_X86_64_PC32:
26111 val -= (u64)loc;
26112+ pax_open_kernel();
26113 *(u32 *)loc = val;
26114+ pax_close_kernel();
26115+
26116 #if 0
26117 if ((s64)val != *(s32 *)loc)
26118 goto overflow;
26119diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
26120index c9603ac..9f88728 100644
26121--- a/arch/x86/kernel/msr.c
26122+++ b/arch/x86/kernel/msr.c
26123@@ -37,6 +37,7 @@
26124 #include <linux/notifier.h>
26125 #include <linux/uaccess.h>
26126 #include <linux/gfp.h>
26127+#include <linux/grsecurity.h>
26128
26129 #include <asm/processor.h>
26130 #include <asm/msr.h>
26131@@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
26132 int err = 0;
26133 ssize_t bytes = 0;
26134
26135+#ifdef CONFIG_GRKERNSEC_KMEM
26136+ gr_handle_msr_write();
26137+ return -EPERM;
26138+#endif
26139+
26140 if (count % 8)
26141 return -EINVAL; /* Invalid chunk size */
26142
26143@@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
26144 err = -EBADF;
26145 break;
26146 }
26147+#ifdef CONFIG_GRKERNSEC_KMEM
26148+ gr_handle_msr_write();
26149+ return -EPERM;
26150+#endif
26151 if (copy_from_user(&regs, uregs, sizeof regs)) {
26152 err = -EFAULT;
26153 break;
26154@@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
26155 return notifier_from_errno(err);
26156 }
26157
26158-static struct notifier_block __refdata msr_class_cpu_notifier = {
26159+static struct notifier_block msr_class_cpu_notifier = {
26160 .notifier_call = msr_class_cpu_callback,
26161 };
26162
26163diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
26164index c3e985d..110a36a 100644
26165--- a/arch/x86/kernel/nmi.c
26166+++ b/arch/x86/kernel/nmi.c
26167@@ -98,16 +98,16 @@ fs_initcall(nmi_warning_debugfs);
26168
26169 static void nmi_max_handler(struct irq_work *w)
26170 {
26171- struct nmiaction *a = container_of(w, struct nmiaction, irq_work);
26172+ struct nmiwork *n = container_of(w, struct nmiwork, irq_work);
26173 int remainder_ns, decimal_msecs;
26174- u64 whole_msecs = ACCESS_ONCE(a->max_duration);
26175+ u64 whole_msecs = ACCESS_ONCE(n->max_duration);
26176
26177 remainder_ns = do_div(whole_msecs, (1000 * 1000));
26178 decimal_msecs = remainder_ns / 1000;
26179
26180 printk_ratelimited(KERN_INFO
26181 "INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
26182- a->handler, whole_msecs, decimal_msecs);
26183+ n->action->handler, whole_msecs, decimal_msecs);
26184 }
26185
26186 static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26187@@ -134,11 +134,11 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26188 delta = sched_clock() - delta;
26189 trace_nmi_handler(a->handler, (int)delta, thishandled);
26190
26191- if (delta < nmi_longest_ns || delta < a->max_duration)
26192+ if (delta < nmi_longest_ns || delta < a->work->max_duration)
26193 continue;
26194
26195- a->max_duration = delta;
26196- irq_work_queue(&a->irq_work);
26197+ a->work->max_duration = delta;
26198+ irq_work_queue(&a->work->irq_work);
26199 }
26200
26201 rcu_read_unlock();
26202@@ -148,7 +148,7 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26203 }
26204 NOKPROBE_SYMBOL(nmi_handle);
26205
26206-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26207+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
26208 {
26209 struct nmi_desc *desc = nmi_to_desc(type);
26210 unsigned long flags;
26211@@ -156,7 +156,8 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26212 if (!action->handler)
26213 return -EINVAL;
26214
26215- init_irq_work(&action->irq_work, nmi_max_handler);
26216+ action->work->action = action;
26217+ init_irq_work(&action->work->irq_work, nmi_max_handler);
26218
26219 spin_lock_irqsave(&desc->lock, flags);
26220
26221@@ -174,9 +175,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26222 * event confuses some handlers (kdump uses this flag)
26223 */
26224 if (action->flags & NMI_FLAG_FIRST)
26225- list_add_rcu(&action->list, &desc->head);
26226+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
26227 else
26228- list_add_tail_rcu(&action->list, &desc->head);
26229+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
26230
26231 spin_unlock_irqrestore(&desc->lock, flags);
26232 return 0;
26233@@ -199,7 +200,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
26234 if (!strcmp(n->name, name)) {
26235 WARN(in_nmi(),
26236 "Trying to free NMI (%s) from NMI context!\n", n->name);
26237- list_del_rcu(&n->list);
26238+ pax_list_del_rcu((struct list_head *)&n->list);
26239 break;
26240 }
26241 }
26242@@ -528,6 +529,17 @@ static inline void nmi_nesting_postprocess(void)
26243 dotraplinkage notrace void
26244 do_nmi(struct pt_regs *regs, long error_code)
26245 {
26246+
26247+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26248+ if (!user_mode(regs)) {
26249+ unsigned long cs = regs->cs & 0xFFFF;
26250+ unsigned long ip = ktva_ktla(regs->ip);
26251+
26252+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
26253+ regs->ip = ip;
26254+ }
26255+#endif
26256+
26257 nmi_nesting_preprocess(regs);
26258
26259 nmi_enter();
26260diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
26261index 6d9582e..f746287 100644
26262--- a/arch/x86/kernel/nmi_selftest.c
26263+++ b/arch/x86/kernel/nmi_selftest.c
26264@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
26265 {
26266 /* trap all the unknown NMIs we may generate */
26267 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
26268- __initdata);
26269+ __initconst);
26270 }
26271
26272 static void __init cleanup_nmi_testsuite(void)
26273@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
26274 unsigned long timeout;
26275
26276 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
26277- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
26278+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
26279 nmi_fail = FAILURE;
26280 return;
26281 }
26282diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
26283index bbb6c73..24a58ef 100644
26284--- a/arch/x86/kernel/paravirt-spinlocks.c
26285+++ b/arch/x86/kernel/paravirt-spinlocks.c
26286@@ -8,7 +8,7 @@
26287
26288 #include <asm/paravirt.h>
26289
26290-struct pv_lock_ops pv_lock_ops = {
26291+struct pv_lock_ops pv_lock_ops __read_only = {
26292 #ifdef CONFIG_SMP
26293 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
26294 .unlock_kick = paravirt_nop,
26295diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
26296index 548d25f..f8fb99c 100644
26297--- a/arch/x86/kernel/paravirt.c
26298+++ b/arch/x86/kernel/paravirt.c
26299@@ -56,6 +56,9 @@ u64 _paravirt_ident_64(u64 x)
26300 {
26301 return x;
26302 }
26303+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26304+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
26305+#endif
26306
26307 void __init default_banner(void)
26308 {
26309@@ -142,16 +145,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
26310
26311 if (opfunc == NULL)
26312 /* If there's no function, patch it with a ud2a (BUG) */
26313- ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
26314- else if (opfunc == _paravirt_nop)
26315+ ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
26316+ else if (opfunc == (void *)_paravirt_nop)
26317 /* If the operation is a nop, then nop the callsite */
26318 ret = paravirt_patch_nop();
26319
26320 /* identity functions just return their single argument */
26321- else if (opfunc == _paravirt_ident_32)
26322+ else if (opfunc == (void *)_paravirt_ident_32)
26323 ret = paravirt_patch_ident_32(insnbuf, len);
26324- else if (opfunc == _paravirt_ident_64)
26325+ else if (opfunc == (void *)_paravirt_ident_64)
26326 ret = paravirt_patch_ident_64(insnbuf, len);
26327+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26328+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
26329+ ret = paravirt_patch_ident_64(insnbuf, len);
26330+#endif
26331
26332 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
26333 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
26334@@ -176,7 +183,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
26335 if (insn_len > len || start == NULL)
26336 insn_len = len;
26337 else
26338- memcpy(insnbuf, start, insn_len);
26339+ memcpy(insnbuf, ktla_ktva(start), insn_len);
26340
26341 return insn_len;
26342 }
26343@@ -300,7 +307,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
26344 return this_cpu_read(paravirt_lazy_mode);
26345 }
26346
26347-struct pv_info pv_info = {
26348+struct pv_info pv_info __read_only = {
26349 .name = "bare hardware",
26350 .paravirt_enabled = 0,
26351 .kernel_rpl = 0,
26352@@ -311,16 +318,16 @@ struct pv_info pv_info = {
26353 #endif
26354 };
26355
26356-struct pv_init_ops pv_init_ops = {
26357+struct pv_init_ops pv_init_ops __read_only = {
26358 .patch = native_patch,
26359 };
26360
26361-struct pv_time_ops pv_time_ops = {
26362+struct pv_time_ops pv_time_ops __read_only = {
26363 .sched_clock = native_sched_clock,
26364 .steal_clock = native_steal_clock,
26365 };
26366
26367-__visible struct pv_irq_ops pv_irq_ops = {
26368+__visible struct pv_irq_ops pv_irq_ops __read_only = {
26369 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
26370 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
26371 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
26372@@ -332,7 +339,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
26373 #endif
26374 };
26375
26376-__visible struct pv_cpu_ops pv_cpu_ops = {
26377+__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
26378 .cpuid = native_cpuid,
26379 .get_debugreg = native_get_debugreg,
26380 .set_debugreg = native_set_debugreg,
26381@@ -395,21 +402,26 @@ NOKPROBE_SYMBOL(native_get_debugreg);
26382 NOKPROBE_SYMBOL(native_set_debugreg);
26383 NOKPROBE_SYMBOL(native_load_idt);
26384
26385-struct pv_apic_ops pv_apic_ops = {
26386+struct pv_apic_ops pv_apic_ops __read_only= {
26387 #ifdef CONFIG_X86_LOCAL_APIC
26388 .startup_ipi_hook = paravirt_nop,
26389 #endif
26390 };
26391
26392-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
26393+#ifdef CONFIG_X86_32
26394+#ifdef CONFIG_X86_PAE
26395+/* 64-bit pagetable entries */
26396+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
26397+#else
26398 /* 32-bit pagetable entries */
26399 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
26400+#endif
26401 #else
26402 /* 64-bit pagetable entries */
26403 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
26404 #endif
26405
26406-struct pv_mmu_ops pv_mmu_ops = {
26407+struct pv_mmu_ops pv_mmu_ops __read_only = {
26408
26409 .read_cr2 = native_read_cr2,
26410 .write_cr2 = native_write_cr2,
26411@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
26412 .make_pud = PTE_IDENT,
26413
26414 .set_pgd = native_set_pgd,
26415+ .set_pgd_batched = native_set_pgd_batched,
26416 #endif
26417 #endif /* PAGETABLE_LEVELS >= 3 */
26418
26419@@ -479,6 +492,12 @@ struct pv_mmu_ops pv_mmu_ops = {
26420 },
26421
26422 .set_fixmap = native_set_fixmap,
26423+
26424+#ifdef CONFIG_PAX_KERNEXEC
26425+ .pax_open_kernel = native_pax_open_kernel,
26426+ .pax_close_kernel = native_pax_close_kernel,
26427+#endif
26428+
26429 };
26430
26431 EXPORT_SYMBOL_GPL(pv_time_ops);
26432diff --git a/arch/x86/kernel/paravirt_patch_64.c b/arch/x86/kernel/paravirt_patch_64.c
26433index a1da673..b6f5831 100644
26434--- a/arch/x86/kernel/paravirt_patch_64.c
26435+++ b/arch/x86/kernel/paravirt_patch_64.c
26436@@ -9,7 +9,11 @@ DEF_NATIVE(pv_irq_ops, save_fl, "pushfq; popq %rax");
26437 DEF_NATIVE(pv_mmu_ops, read_cr2, "movq %cr2, %rax");
26438 DEF_NATIVE(pv_mmu_ops, read_cr3, "movq %cr3, %rax");
26439 DEF_NATIVE(pv_mmu_ops, write_cr3, "movq %rdi, %cr3");
26440+
26441+#ifndef CONFIG_PAX_MEMORY_UDEREF
26442 DEF_NATIVE(pv_mmu_ops, flush_tlb_single, "invlpg (%rdi)");
26443+#endif
26444+
26445 DEF_NATIVE(pv_cpu_ops, clts, "clts");
26446 DEF_NATIVE(pv_cpu_ops, wbinvd, "wbinvd");
26447
26448@@ -57,7 +61,11 @@ unsigned native_patch(u8 type, u16 clobbers, void *ibuf,
26449 PATCH_SITE(pv_mmu_ops, read_cr3);
26450 PATCH_SITE(pv_mmu_ops, write_cr3);
26451 PATCH_SITE(pv_cpu_ops, clts);
26452+
26453+#ifndef CONFIG_PAX_MEMORY_UDEREF
26454 PATCH_SITE(pv_mmu_ops, flush_tlb_single);
26455+#endif
26456+
26457 PATCH_SITE(pv_cpu_ops, wbinvd);
26458
26459 patch_site:
26460diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
26461index 0497f71..7186c0d 100644
26462--- a/arch/x86/kernel/pci-calgary_64.c
26463+++ b/arch/x86/kernel/pci-calgary_64.c
26464@@ -1347,7 +1347,7 @@ static void __init get_tce_space_from_tar(void)
26465 tce_space = be64_to_cpu(readq(target));
26466 tce_space = tce_space & TAR_SW_BITS;
26467
26468- tce_space = tce_space & (~specified_table_size);
26469+ tce_space = tce_space & (~(unsigned long)specified_table_size);
26470 info->tce_space = (u64 *)__va(tce_space);
26471 }
26472 }
26473diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
26474index 35ccf75..7a15747 100644
26475--- a/arch/x86/kernel/pci-iommu_table.c
26476+++ b/arch/x86/kernel/pci-iommu_table.c
26477@@ -2,7 +2,7 @@
26478 #include <asm/iommu_table.h>
26479 #include <linux/string.h>
26480 #include <linux/kallsyms.h>
26481-
26482+#include <linux/sched.h>
26483
26484 #define DEBUG 1
26485
26486diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
26487index 77dd0ad..9ec4723 100644
26488--- a/arch/x86/kernel/pci-swiotlb.c
26489+++ b/arch/x86/kernel/pci-swiotlb.c
26490@@ -33,7 +33,7 @@ void x86_swiotlb_free_coherent(struct device *dev, size_t size,
26491 struct dma_attrs *attrs)
26492 {
26493 if (is_swiotlb_buffer(dma_to_phys(dev, dma_addr)))
26494- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
26495+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
26496 else
26497 dma_generic_free_coherent(dev, size, vaddr, dma_addr, attrs);
26498 }
26499diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
26500index e127dda..94e384d 100644
26501--- a/arch/x86/kernel/process.c
26502+++ b/arch/x86/kernel/process.c
26503@@ -36,7 +36,8 @@
26504 * section. Since TSS's are completely CPU-local, we want them
26505 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
26506 */
26507-__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
26508+struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
26509+EXPORT_SYMBOL(init_tss);
26510
26511 #ifdef CONFIG_X86_64
26512 static DEFINE_PER_CPU(unsigned char, is_idle);
26513@@ -94,7 +95,7 @@ void arch_task_cache_init(void)
26514 task_xstate_cachep =
26515 kmem_cache_create("task_xstate", xstate_size,
26516 __alignof__(union thread_xstate),
26517- SLAB_PANIC | SLAB_NOTRACK, NULL);
26518+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
26519 setup_xstate_comp();
26520 }
26521
26522@@ -108,7 +109,7 @@ void exit_thread(void)
26523 unsigned long *bp = t->io_bitmap_ptr;
26524
26525 if (bp) {
26526- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
26527+ struct tss_struct *tss = init_tss + get_cpu();
26528
26529 t->io_bitmap_ptr = NULL;
26530 clear_thread_flag(TIF_IO_BITMAP);
26531@@ -128,6 +129,9 @@ void flush_thread(void)
26532 {
26533 struct task_struct *tsk = current;
26534
26535+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26536+ loadsegment(gs, 0);
26537+#endif
26538 flush_ptrace_hw_breakpoint(tsk);
26539 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26540 drop_init_fpu(tsk);
26541@@ -274,7 +278,7 @@ static void __exit_idle(void)
26542 void exit_idle(void)
26543 {
26544 /* idle loop has pid 0 */
26545- if (current->pid)
26546+ if (task_pid_nr(current))
26547 return;
26548 __exit_idle();
26549 }
26550@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
26551 return ret;
26552 }
26553 #endif
26554-void stop_this_cpu(void *dummy)
26555+__noreturn void stop_this_cpu(void *dummy)
26556 {
26557 local_irq_disable();
26558 /*
26559@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
26560 }
26561 early_param("idle", idle_setup);
26562
26563-unsigned long arch_align_stack(unsigned long sp)
26564+#ifdef CONFIG_PAX_RANDKSTACK
26565+void pax_randomize_kstack(struct pt_regs *regs)
26566 {
26567- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26568- sp -= get_random_int() % 8192;
26569- return sp & ~0xf;
26570-}
26571+ struct thread_struct *thread = &current->thread;
26572+ unsigned long time;
26573
26574-unsigned long arch_randomize_brk(struct mm_struct *mm)
26575-{
26576- unsigned long range_end = mm->brk + 0x02000000;
26577- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26578-}
26579+ if (!randomize_va_space)
26580+ return;
26581+
26582+ if (v8086_mode(regs))
26583+ return;
26584
26585+ rdtscl(time);
26586+
26587+ /* P4 seems to return a 0 LSB, ignore it */
26588+#ifdef CONFIG_MPENTIUM4
26589+ time &= 0x3EUL;
26590+ time <<= 2;
26591+#elif defined(CONFIG_X86_64)
26592+ time &= 0xFUL;
26593+ time <<= 4;
26594+#else
26595+ time &= 0x1FUL;
26596+ time <<= 3;
26597+#endif
26598+
26599+ thread->sp0 ^= time;
26600+ load_sp0(init_tss + smp_processor_id(), thread);
26601+
26602+#ifdef CONFIG_X86_64
26603+ this_cpu_write(kernel_stack, thread->sp0);
26604+#endif
26605+}
26606+#endif
26607diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26608index 8f3ebfe..e6ced5a 100644
26609--- a/arch/x86/kernel/process_32.c
26610+++ b/arch/x86/kernel/process_32.c
26611@@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26612 unsigned long thread_saved_pc(struct task_struct *tsk)
26613 {
26614 return ((unsigned long *)tsk->thread.sp)[3];
26615+//XXX return tsk->thread.eip;
26616 }
26617
26618 void __show_regs(struct pt_regs *regs, int all)
26619@@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26620 unsigned long sp;
26621 unsigned short ss, gs;
26622
26623- if (user_mode_vm(regs)) {
26624+ if (user_mode(regs)) {
26625 sp = regs->sp;
26626 ss = regs->ss & 0xffff;
26627- gs = get_user_gs(regs);
26628 } else {
26629 sp = kernel_stack_pointer(regs);
26630 savesegment(ss, ss);
26631- savesegment(gs, gs);
26632 }
26633+ gs = get_user_gs(regs);
26634
26635 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26636 (u16)regs->cs, regs->ip, regs->flags,
26637- smp_processor_id());
26638+ raw_smp_processor_id());
26639 print_symbol("EIP is at %s\n", regs->ip);
26640
26641 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26642@@ -132,21 +132,22 @@ void release_thread(struct task_struct *dead_task)
26643 int copy_thread(unsigned long clone_flags, unsigned long sp,
26644 unsigned long arg, struct task_struct *p)
26645 {
26646- struct pt_regs *childregs = task_pt_regs(p);
26647+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26648 struct task_struct *tsk;
26649 int err;
26650
26651 p->thread.sp = (unsigned long) childregs;
26652 p->thread.sp0 = (unsigned long) (childregs+1);
26653+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26654 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26655
26656 if (unlikely(p->flags & PF_KTHREAD)) {
26657 /* kernel thread */
26658 memset(childregs, 0, sizeof(struct pt_regs));
26659 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26660- task_user_gs(p) = __KERNEL_STACK_CANARY;
26661- childregs->ds = __USER_DS;
26662- childregs->es = __USER_DS;
26663+ savesegment(gs, childregs->gs);
26664+ childregs->ds = __KERNEL_DS;
26665+ childregs->es = __KERNEL_DS;
26666 childregs->fs = __KERNEL_PERCPU;
26667 childregs->bx = sp; /* function */
26668 childregs->bp = arg;
26669@@ -248,7 +249,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26670 struct thread_struct *prev = &prev_p->thread,
26671 *next = &next_p->thread;
26672 int cpu = smp_processor_id();
26673- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26674+ struct tss_struct *tss = init_tss + cpu;
26675 fpu_switch_t fpu;
26676
26677 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26678@@ -272,6 +273,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26679 */
26680 lazy_save_gs(prev->gs);
26681
26682+#ifdef CONFIG_PAX_MEMORY_UDEREF
26683+ __set_fs(task_thread_info(next_p)->addr_limit);
26684+#endif
26685+
26686 /*
26687 * Load the per-thread Thread-Local Storage descriptor.
26688 */
26689@@ -310,9 +315,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26690 */
26691 arch_end_context_switch(next_p);
26692
26693- this_cpu_write(kernel_stack,
26694- (unsigned long)task_stack_page(next_p) +
26695- THREAD_SIZE - KERNEL_STACK_OFFSET);
26696+ this_cpu_write(current_task, next_p);
26697+ this_cpu_write(current_tinfo, &next_p->tinfo);
26698+ this_cpu_write(kernel_stack, next->sp0);
26699
26700 /*
26701 * Restore %gs if needed (which is common)
26702@@ -322,8 +327,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26703
26704 switch_fpu_finish(next_p, fpu);
26705
26706- this_cpu_write(current_task, next_p);
26707-
26708 return prev_p;
26709 }
26710
26711@@ -353,4 +356,3 @@ unsigned long get_wchan(struct task_struct *p)
26712 } while (count++ < 16);
26713 return 0;
26714 }
26715-
26716diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26717index 3ed4a68..ee8f337 100644
26718--- a/arch/x86/kernel/process_64.c
26719+++ b/arch/x86/kernel/process_64.c
26720@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26721 struct pt_regs *childregs;
26722 struct task_struct *me = current;
26723
26724- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26725+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26726 childregs = task_pt_regs(p);
26727 p->thread.sp = (unsigned long) childregs;
26728 p->thread.usersp = me->thread.usersp;
26729+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26730 set_tsk_thread_flag(p, TIF_FORK);
26731 p->thread.io_bitmap_ptr = NULL;
26732
26733@@ -171,6 +172,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26734 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26735 savesegment(es, p->thread.es);
26736 savesegment(ds, p->thread.ds);
26737+ savesegment(ss, p->thread.ss);
26738+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26739 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26740
26741 if (unlikely(p->flags & PF_KTHREAD)) {
26742@@ -277,7 +280,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26743 struct thread_struct *prev = &prev_p->thread;
26744 struct thread_struct *next = &next_p->thread;
26745 int cpu = smp_processor_id();
26746- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26747+ struct tss_struct *tss = init_tss + cpu;
26748 unsigned fsindex, gsindex;
26749 fpu_switch_t fpu;
26750
26751@@ -300,6 +303,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26752 if (unlikely(next->ds | prev->ds))
26753 loadsegment(ds, next->ds);
26754
26755+ savesegment(ss, prev->ss);
26756+ if (unlikely(next->ss != prev->ss))
26757+ loadsegment(ss, next->ss);
26758
26759 /* We must save %fs and %gs before load_TLS() because
26760 * %fs and %gs may be cleared by load_TLS().
26761@@ -359,6 +365,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26762 prev->usersp = this_cpu_read(old_rsp);
26763 this_cpu_write(old_rsp, next->usersp);
26764 this_cpu_write(current_task, next_p);
26765+ this_cpu_write(current_tinfo, &next_p->tinfo);
26766
26767 /*
26768 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26769@@ -368,9 +375,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26770 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26771 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26772
26773- this_cpu_write(kernel_stack,
26774- (unsigned long)task_stack_page(next_p) +
26775- THREAD_SIZE - KERNEL_STACK_OFFSET);
26776+ this_cpu_write(kernel_stack, next->sp0);
26777
26778 /*
26779 * Now maybe reload the debug registers and handle I/O bitmaps
26780@@ -440,12 +445,11 @@ unsigned long get_wchan(struct task_struct *p)
26781 if (!p || p == current || p->state == TASK_RUNNING)
26782 return 0;
26783 stack = (unsigned long)task_stack_page(p);
26784- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26785+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26786 return 0;
26787 fp = *(u64 *)(p->thread.sp);
26788 do {
26789- if (fp < (unsigned long)stack ||
26790- fp >= (unsigned long)stack+THREAD_SIZE)
26791+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26792 return 0;
26793 ip = *(u64 *)(fp+8);
26794 if (!in_sched_functions(ip))
26795diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26796index e510618..5165ac0 100644
26797--- a/arch/x86/kernel/ptrace.c
26798+++ b/arch/x86/kernel/ptrace.c
26799@@ -186,10 +186,10 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26800 unsigned long sp = (unsigned long)&regs->sp;
26801 u32 *prev_esp;
26802
26803- if (context == (sp & ~(THREAD_SIZE - 1)))
26804+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26805 return sp;
26806
26807- prev_esp = (u32 *)(context);
26808+ prev_esp = *(u32 **)(context);
26809 if (prev_esp)
26810 return (unsigned long)prev_esp;
26811
26812@@ -452,6 +452,20 @@ static int putreg(struct task_struct *child,
26813 if (child->thread.gs != value)
26814 return do_arch_prctl(child, ARCH_SET_GS, value);
26815 return 0;
26816+
26817+ case offsetof(struct user_regs_struct,ip):
26818+ /*
26819+ * Protect against any attempt to set ip to an
26820+ * impossible address. There are dragons lurking if the
26821+ * address is noncanonical. (This explicitly allows
26822+ * setting ip to TASK_SIZE_MAX, because user code can do
26823+ * that all by itself by running off the end of its
26824+ * address space.
26825+ */
26826+ if (value > TASK_SIZE_MAX)
26827+ return -EIO;
26828+ break;
26829+
26830 #endif
26831 }
26832
26833@@ -588,7 +602,7 @@ static void ptrace_triggered(struct perf_event *bp,
26834 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26835 {
26836 int i;
26837- int dr7 = 0;
26838+ unsigned long dr7 = 0;
26839 struct arch_hw_breakpoint *info;
26840
26841 for (i = 0; i < HBP_NUM; i++) {
26842@@ -822,7 +836,7 @@ long arch_ptrace(struct task_struct *child, long request,
26843 unsigned long addr, unsigned long data)
26844 {
26845 int ret;
26846- unsigned long __user *datap = (unsigned long __user *)data;
26847+ unsigned long __user *datap = (__force unsigned long __user *)data;
26848
26849 switch (request) {
26850 /* read the word at location addr in the USER area. */
26851@@ -907,14 +921,14 @@ long arch_ptrace(struct task_struct *child, long request,
26852 if ((int) addr < 0)
26853 return -EIO;
26854 ret = do_get_thread_area(child, addr,
26855- (struct user_desc __user *)data);
26856+ (__force struct user_desc __user *) data);
26857 break;
26858
26859 case PTRACE_SET_THREAD_AREA:
26860 if ((int) addr < 0)
26861 return -EIO;
26862 ret = do_set_thread_area(child, addr,
26863- (struct user_desc __user *)data, 0);
26864+ (__force struct user_desc __user *) data, 0);
26865 break;
26866 #endif
26867
26868@@ -1292,7 +1306,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26869
26870 #ifdef CONFIG_X86_64
26871
26872-static struct user_regset x86_64_regsets[] __read_mostly = {
26873+static user_regset_no_const x86_64_regsets[] __read_only = {
26874 [REGSET_GENERAL] = {
26875 .core_note_type = NT_PRSTATUS,
26876 .n = sizeof(struct user_regs_struct) / sizeof(long),
26877@@ -1333,7 +1347,7 @@ static const struct user_regset_view user_x86_64_view = {
26878 #endif /* CONFIG_X86_64 */
26879
26880 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26881-static struct user_regset x86_32_regsets[] __read_mostly = {
26882+static user_regset_no_const x86_32_regsets[] __read_only = {
26883 [REGSET_GENERAL] = {
26884 .core_note_type = NT_PRSTATUS,
26885 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26886@@ -1386,7 +1400,7 @@ static const struct user_regset_view user_x86_32_view = {
26887 */
26888 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26889
26890-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26891+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26892 {
26893 #ifdef CONFIG_X86_64
26894 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26895@@ -1421,7 +1435,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26896 memset(info, 0, sizeof(*info));
26897 info->si_signo = SIGTRAP;
26898 info->si_code = si_code;
26899- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26900+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26901 }
26902
26903 void user_single_step_siginfo(struct task_struct *tsk,
26904@@ -1455,6 +1469,10 @@ static void do_audit_syscall_entry(struct pt_regs *regs, u32 arch)
26905 }
26906 }
26907
26908+#ifdef CONFIG_GRKERNSEC_SETXID
26909+extern void gr_delayed_cred_worker(void);
26910+#endif
26911+
26912 /*
26913 * We can return 0 to resume the syscall or anything else to go to phase
26914 * 2. If we resume the syscall, we need to put something appropriate in
26915@@ -1562,6 +1580,11 @@ long syscall_trace_enter_phase2(struct pt_regs *regs, u32 arch,
26916
26917 BUG_ON(regs != task_pt_regs(current));
26918
26919+#ifdef CONFIG_GRKERNSEC_SETXID
26920+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26921+ gr_delayed_cred_worker();
26922+#endif
26923+
26924 /*
26925 * If we stepped into a sysenter/syscall insn, it trapped in
26926 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26927@@ -1620,6 +1643,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26928 */
26929 user_exit();
26930
26931+#ifdef CONFIG_GRKERNSEC_SETXID
26932+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26933+ gr_delayed_cred_worker();
26934+#endif
26935+
26936 audit_syscall_exit(regs);
26937
26938 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26939diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26940index 2f355d2..e75ed0a 100644
26941--- a/arch/x86/kernel/pvclock.c
26942+++ b/arch/x86/kernel/pvclock.c
26943@@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26944 reset_hung_task_detector();
26945 }
26946
26947-static atomic64_t last_value = ATOMIC64_INIT(0);
26948+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26949
26950 void pvclock_resume(void)
26951 {
26952- atomic64_set(&last_value, 0);
26953+ atomic64_set_unchecked(&last_value, 0);
26954 }
26955
26956 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26957@@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26958 * updating at the same time, and one of them could be slightly behind,
26959 * making the assumption that last_value always go forward fail to hold.
26960 */
26961- last = atomic64_read(&last_value);
26962+ last = atomic64_read_unchecked(&last_value);
26963 do {
26964 if (ret < last)
26965 return last;
26966- last = atomic64_cmpxchg(&last_value, last, ret);
26967+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26968 } while (unlikely(last != ret));
26969
26970 return ret;
26971diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26972index 17962e6..47f55db 100644
26973--- a/arch/x86/kernel/reboot.c
26974+++ b/arch/x86/kernel/reboot.c
26975@@ -69,6 +69,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26976
26977 void __noreturn machine_real_restart(unsigned int type)
26978 {
26979+
26980+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26981+ struct desc_struct *gdt;
26982+#endif
26983+
26984 local_irq_disable();
26985
26986 /*
26987@@ -96,7 +101,29 @@ void __noreturn machine_real_restart(unsigned int type)
26988
26989 /* Jump to the identity-mapped low memory code */
26990 #ifdef CONFIG_X86_32
26991- asm volatile("jmpl *%0" : :
26992+
26993+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26994+ gdt = get_cpu_gdt_table(smp_processor_id());
26995+ pax_open_kernel();
26996+#ifdef CONFIG_PAX_MEMORY_UDEREF
26997+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26998+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26999+ loadsegment(ds, __KERNEL_DS);
27000+ loadsegment(es, __KERNEL_DS);
27001+ loadsegment(ss, __KERNEL_DS);
27002+#endif
27003+#ifdef CONFIG_PAX_KERNEXEC
27004+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
27005+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
27006+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
27007+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
27008+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
27009+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
27010+#endif
27011+ pax_close_kernel();
27012+#endif
27013+
27014+ asm volatile("ljmpl *%0" : :
27015 "rm" (real_mode_header->machine_real_restart_asm),
27016 "a" (type));
27017 #else
27018@@ -500,7 +527,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
27019 * This means that this function can never return, it can misbehave
27020 * by not rebooting properly and hanging.
27021 */
27022-static void native_machine_emergency_restart(void)
27023+static void __noreturn native_machine_emergency_restart(void)
27024 {
27025 int i;
27026 int attempt = 0;
27027@@ -620,13 +647,13 @@ void native_machine_shutdown(void)
27028 #endif
27029 }
27030
27031-static void __machine_emergency_restart(int emergency)
27032+static void __noreturn __machine_emergency_restart(int emergency)
27033 {
27034 reboot_emergency = emergency;
27035 machine_ops.emergency_restart();
27036 }
27037
27038-static void native_machine_restart(char *__unused)
27039+static void __noreturn native_machine_restart(char *__unused)
27040 {
27041 pr_notice("machine restart\n");
27042
27043@@ -635,7 +662,7 @@ static void native_machine_restart(char *__unused)
27044 __machine_emergency_restart(0);
27045 }
27046
27047-static void native_machine_halt(void)
27048+static void __noreturn native_machine_halt(void)
27049 {
27050 /* Stop other cpus and apics */
27051 machine_shutdown();
27052@@ -645,7 +672,7 @@ static void native_machine_halt(void)
27053 stop_this_cpu(NULL);
27054 }
27055
27056-static void native_machine_power_off(void)
27057+static void __noreturn native_machine_power_off(void)
27058 {
27059 if (pm_power_off) {
27060 if (!reboot_force)
27061@@ -654,9 +681,10 @@ static void native_machine_power_off(void)
27062 }
27063 /* A fallback in case there is no PM info available */
27064 tboot_shutdown(TB_SHUTDOWN_HALT);
27065+ unreachable();
27066 }
27067
27068-struct machine_ops machine_ops = {
27069+struct machine_ops machine_ops __read_only = {
27070 .power_off = native_machine_power_off,
27071 .shutdown = native_machine_shutdown,
27072 .emergency_restart = native_machine_emergency_restart,
27073diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
27074index c8e41e9..64049ef 100644
27075--- a/arch/x86/kernel/reboot_fixups_32.c
27076+++ b/arch/x86/kernel/reboot_fixups_32.c
27077@@ -57,7 +57,7 @@ struct device_fixup {
27078 unsigned int vendor;
27079 unsigned int device;
27080 void (*reboot_fixup)(struct pci_dev *);
27081-};
27082+} __do_const;
27083
27084 /*
27085 * PCI ids solely used for fixups_table go here
27086diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
27087index 3fd2c69..a444264 100644
27088--- a/arch/x86/kernel/relocate_kernel_64.S
27089+++ b/arch/x86/kernel/relocate_kernel_64.S
27090@@ -96,8 +96,7 @@ relocate_kernel:
27091
27092 /* jump to identity mapped page */
27093 addq $(identity_mapped - relocate_kernel), %r8
27094- pushq %r8
27095- ret
27096+ jmp *%r8
27097
27098 identity_mapped:
27099 /* set return address to 0 if not preserving context */
27100diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
27101index ab08aa2..6d74a3a 100644
27102--- a/arch/x86/kernel/setup.c
27103+++ b/arch/x86/kernel/setup.c
27104@@ -110,6 +110,7 @@
27105 #include <asm/mce.h>
27106 #include <asm/alternative.h>
27107 #include <asm/prom.h>
27108+#include <asm/boot.h>
27109
27110 /*
27111 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
27112@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
27113 #endif
27114
27115
27116-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
27117-__visible unsigned long mmu_cr4_features;
27118+#ifdef CONFIG_X86_64
27119+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
27120+#elif defined(CONFIG_X86_PAE)
27121+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
27122 #else
27123-__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
27124+__visible unsigned long mmu_cr4_features __read_only;
27125 #endif
27126
27127+void set_in_cr4(unsigned long mask)
27128+{
27129+ unsigned long cr4 = read_cr4();
27130+
27131+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
27132+ return;
27133+
27134+ pax_open_kernel();
27135+ mmu_cr4_features |= mask;
27136+ pax_close_kernel();
27137+
27138+ if (trampoline_cr4_features)
27139+ *trampoline_cr4_features = mmu_cr4_features;
27140+ cr4 |= mask;
27141+ write_cr4(cr4);
27142+}
27143+EXPORT_SYMBOL(set_in_cr4);
27144+
27145+void clear_in_cr4(unsigned long mask)
27146+{
27147+ unsigned long cr4 = read_cr4();
27148+
27149+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
27150+ return;
27151+
27152+ pax_open_kernel();
27153+ mmu_cr4_features &= ~mask;
27154+ pax_close_kernel();
27155+
27156+ if (trampoline_cr4_features)
27157+ *trampoline_cr4_features = mmu_cr4_features;
27158+ cr4 &= ~mask;
27159+ write_cr4(cr4);
27160+}
27161+EXPORT_SYMBOL(clear_in_cr4);
27162+
27163 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
27164 int bootloader_type, bootloader_version;
27165
27166@@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
27167 * area (640->1Mb) as ram even though it is not.
27168 * take them out.
27169 */
27170- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
27171+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
27172
27173 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
27174 }
27175@@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
27176 /* called before trim_bios_range() to spare extra sanitize */
27177 static void __init e820_add_kernel_range(void)
27178 {
27179- u64 start = __pa_symbol(_text);
27180+ u64 start = __pa_symbol(ktla_ktva(_text));
27181 u64 size = __pa_symbol(_end) - start;
27182
27183 /*
27184@@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
27185
27186 void __init setup_arch(char **cmdline_p)
27187 {
27188+#ifdef CONFIG_X86_32
27189+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
27190+#else
27191 memblock_reserve(__pa_symbol(_text),
27192 (unsigned long)__bss_stop - (unsigned long)_text);
27193+#endif
27194
27195 early_reserve_initrd();
27196
27197@@ -955,14 +998,14 @@ void __init setup_arch(char **cmdline_p)
27198
27199 if (!boot_params.hdr.root_flags)
27200 root_mountflags &= ~MS_RDONLY;
27201- init_mm.start_code = (unsigned long) _text;
27202- init_mm.end_code = (unsigned long) _etext;
27203+ init_mm.start_code = ktla_ktva((unsigned long) _text);
27204+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
27205 init_mm.end_data = (unsigned long) _edata;
27206 init_mm.brk = _brk_end;
27207
27208- code_resource.start = __pa_symbol(_text);
27209- code_resource.end = __pa_symbol(_etext)-1;
27210- data_resource.start = __pa_symbol(_etext);
27211+ code_resource.start = __pa_symbol(ktla_ktva(_text));
27212+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
27213+ data_resource.start = __pa_symbol(_sdata);
27214 data_resource.end = __pa_symbol(_edata)-1;
27215 bss_resource.start = __pa_symbol(__bss_start);
27216 bss_resource.end = __pa_symbol(__bss_stop)-1;
27217diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
27218index 5cdff03..80fa283 100644
27219--- a/arch/x86/kernel/setup_percpu.c
27220+++ b/arch/x86/kernel/setup_percpu.c
27221@@ -21,19 +21,17 @@
27222 #include <asm/cpu.h>
27223 #include <asm/stackprotector.h>
27224
27225-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
27226+#ifdef CONFIG_SMP
27227+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
27228 EXPORT_PER_CPU_SYMBOL(cpu_number);
27229+#endif
27230
27231-#ifdef CONFIG_X86_64
27232 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
27233-#else
27234-#define BOOT_PERCPU_OFFSET 0
27235-#endif
27236
27237 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
27238 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
27239
27240-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
27241+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
27242 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
27243 };
27244 EXPORT_SYMBOL(__per_cpu_offset);
27245@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
27246 {
27247 #ifdef CONFIG_NEED_MULTIPLE_NODES
27248 pg_data_t *last = NULL;
27249- unsigned int cpu;
27250+ int cpu;
27251
27252 for_each_possible_cpu(cpu) {
27253 int node = early_cpu_to_node(cpu);
27254@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
27255 {
27256 #ifdef CONFIG_X86_32
27257 struct desc_struct gdt;
27258+ unsigned long base = per_cpu_offset(cpu);
27259
27260- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
27261- 0x2 | DESCTYPE_S, 0x8);
27262- gdt.s = 1;
27263+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
27264+ 0x83 | DESCTYPE_S, 0xC);
27265 write_gdt_entry(get_cpu_gdt_table(cpu),
27266 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
27267 #endif
27268@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
27269 /* alrighty, percpu areas up and running */
27270 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
27271 for_each_possible_cpu(cpu) {
27272+#ifdef CONFIG_CC_STACKPROTECTOR
27273+#ifdef CONFIG_X86_32
27274+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
27275+#endif
27276+#endif
27277 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
27278 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
27279 per_cpu(cpu_number, cpu) = cpu;
27280@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
27281 */
27282 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
27283 #endif
27284+#ifdef CONFIG_CC_STACKPROTECTOR
27285+#ifdef CONFIG_X86_32
27286+ if (!cpu)
27287+ per_cpu(stack_canary.canary, cpu) = canary;
27288+#endif
27289+#endif
27290 /*
27291 * Up to this point, the boot CPU has been using .init.data
27292 * area. Reload any changed state for the boot CPU.
27293diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
27294index ed37a76..39f936e 100644
27295--- a/arch/x86/kernel/signal.c
27296+++ b/arch/x86/kernel/signal.c
27297@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
27298 * Align the stack pointer according to the i386 ABI,
27299 * i.e. so that on function entry ((sp + 4) & 15) == 0.
27300 */
27301- sp = ((sp + 4) & -16ul) - 4;
27302+ sp = ((sp - 12) & -16ul) - 4;
27303 #else /* !CONFIG_X86_32 */
27304 sp = round_down(sp, 16) - 8;
27305 #endif
27306@@ -298,10 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27307 }
27308
27309 if (current->mm->context.vdso)
27310- restorer = current->mm->context.vdso +
27311- selected_vdso32->sym___kernel_sigreturn;
27312+ restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_sigreturn);
27313 else
27314- restorer = &frame->retcode;
27315+ restorer = (void __user *)&frame->retcode;
27316 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27317 restorer = ksig->ka.sa.sa_restorer;
27318
27319@@ -315,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27320 * reasons and because gdb uses it as a signature to notice
27321 * signal handler stack frames.
27322 */
27323- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
27324+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
27325
27326 if (err)
27327 return -EFAULT;
27328@@ -362,8 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27329 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
27330
27331 /* Set up to return from userspace. */
27332- restorer = current->mm->context.vdso +
27333- selected_vdso32->sym___kernel_rt_sigreturn;
27334+ if (current->mm->context.vdso)
27335+ restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_rt_sigreturn);
27336+ else
27337+ restorer = (void __user *)&frame->retcode;
27338 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27339 restorer = ksig->ka.sa.sa_restorer;
27340 put_user_ex(restorer, &frame->pretcode);
27341@@ -375,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27342 * reasons and because gdb uses it as a signature to notice
27343 * signal handler stack frames.
27344 */
27345- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
27346+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
27347 } put_user_catch(err);
27348
27349 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
27350@@ -611,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27351 {
27352 int usig = signr_convert(ksig->sig);
27353 sigset_t *set = sigmask_to_save();
27354- compat_sigset_t *cset = (compat_sigset_t *) set;
27355+ sigset_t sigcopy;
27356+ compat_sigset_t *cset;
27357+
27358+ sigcopy = *set;
27359+
27360+ cset = (compat_sigset_t *) &sigcopy;
27361
27362 /* Set up the stack frame */
27363 if (is_ia32_frame()) {
27364@@ -622,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27365 } else if (is_x32_frame()) {
27366 return x32_setup_rt_frame(ksig, cset, regs);
27367 } else {
27368- return __setup_rt_frame(ksig->sig, ksig, set, regs);
27369+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
27370 }
27371 }
27372
27373diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
27374index be8e1bd..a3d93fa 100644
27375--- a/arch/x86/kernel/smp.c
27376+++ b/arch/x86/kernel/smp.c
27377@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
27378
27379 __setup("nonmi_ipi", nonmi_ipi_setup);
27380
27381-struct smp_ops smp_ops = {
27382+struct smp_ops smp_ops __read_only = {
27383 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
27384 .smp_prepare_cpus = native_smp_prepare_cpus,
27385 .smp_cpus_done = native_smp_cpus_done,
27386diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
27387index 668d8f2..84a9d54 100644
27388--- a/arch/x86/kernel/smpboot.c
27389+++ b/arch/x86/kernel/smpboot.c
27390@@ -194,14 +194,17 @@ static void notrace start_secondary(void *unused)
27391
27392 enable_start_cpu0 = 0;
27393
27394-#ifdef CONFIG_X86_32
27395+ /* otherwise gcc will move up smp_processor_id before the cpu_init */
27396+ barrier();
27397+
27398 /* switch away from the initial page table */
27399+#ifdef CONFIG_PAX_PER_CPU_PGD
27400+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
27401+#else
27402 load_cr3(swapper_pg_dir);
27403+#endif
27404 __flush_tlb_all();
27405-#endif
27406
27407- /* otherwise gcc will move up smp_processor_id before the cpu_init */
27408- barrier();
27409 /*
27410 * Check TSC synchronization with the BP:
27411 */
27412@@ -765,8 +768,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27413 alternatives_enable_smp();
27414
27415 idle->thread.sp = (unsigned long) (((struct pt_regs *)
27416- (THREAD_SIZE + task_stack_page(idle))) - 1);
27417+ (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
27418 per_cpu(current_task, cpu) = idle;
27419+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
27420
27421 #ifdef CONFIG_X86_32
27422 /* Stack for startup_32 can be just as for start_secondary onwards */
27423@@ -775,10 +779,10 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27424 clear_tsk_thread_flag(idle, TIF_FORK);
27425 initial_gs = per_cpu_offset(cpu);
27426 #endif
27427- per_cpu(kernel_stack, cpu) =
27428- (unsigned long)task_stack_page(idle) -
27429- KERNEL_STACK_OFFSET + THREAD_SIZE;
27430+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27431+ pax_open_kernel();
27432 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
27433+ pax_close_kernel();
27434 initial_code = (unsigned long)start_secondary;
27435 stack_start = idle->thread.sp;
27436
27437@@ -918,6 +922,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
27438 /* the FPU context is blank, nobody can own it */
27439 __cpu_disable_lazy_restore(cpu);
27440
27441+#ifdef CONFIG_PAX_PER_CPU_PGD
27442+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
27443+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27444+ KERNEL_PGD_PTRS);
27445+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
27446+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27447+ KERNEL_PGD_PTRS);
27448+#endif
27449+
27450 err = do_boot_cpu(apicid, cpu, tidle);
27451 if (err) {
27452 pr_err("do_boot_cpu failed(%d) to wakeup CPU#%u\n", err, cpu);
27453diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
27454index 9b4d51d..5d28b58 100644
27455--- a/arch/x86/kernel/step.c
27456+++ b/arch/x86/kernel/step.c
27457@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27458 struct desc_struct *desc;
27459 unsigned long base;
27460
27461- seg &= ~7UL;
27462+ seg >>= 3;
27463
27464 mutex_lock(&child->mm->context.lock);
27465- if (unlikely((seg >> 3) >= child->mm->context.size))
27466+ if (unlikely(seg >= child->mm->context.size))
27467 addr = -1L; /* bogus selector, access would fault */
27468 else {
27469 desc = child->mm->context.ldt + seg;
27470@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27471 addr += base;
27472 }
27473 mutex_unlock(&child->mm->context.lock);
27474- }
27475+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
27476+ addr = ktla_ktva(addr);
27477
27478 return addr;
27479 }
27480@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
27481 unsigned char opcode[15];
27482 unsigned long addr = convert_ip_to_linear(child, regs);
27483
27484+ if (addr == -EINVAL)
27485+ return 0;
27486+
27487 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
27488 for (i = 0; i < copied; i++) {
27489 switch (opcode[i]) {
27490diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
27491new file mode 100644
27492index 0000000..5877189
27493--- /dev/null
27494+++ b/arch/x86/kernel/sys_i386_32.c
27495@@ -0,0 +1,189 @@
27496+/*
27497+ * This file contains various random system calls that
27498+ * have a non-standard calling sequence on the Linux/i386
27499+ * platform.
27500+ */
27501+
27502+#include <linux/errno.h>
27503+#include <linux/sched.h>
27504+#include <linux/mm.h>
27505+#include <linux/fs.h>
27506+#include <linux/smp.h>
27507+#include <linux/sem.h>
27508+#include <linux/msg.h>
27509+#include <linux/shm.h>
27510+#include <linux/stat.h>
27511+#include <linux/syscalls.h>
27512+#include <linux/mman.h>
27513+#include <linux/file.h>
27514+#include <linux/utsname.h>
27515+#include <linux/ipc.h>
27516+#include <linux/elf.h>
27517+
27518+#include <linux/uaccess.h>
27519+#include <linux/unistd.h>
27520+
27521+#include <asm/syscalls.h>
27522+
27523+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
27524+{
27525+ unsigned long pax_task_size = TASK_SIZE;
27526+
27527+#ifdef CONFIG_PAX_SEGMEXEC
27528+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
27529+ pax_task_size = SEGMEXEC_TASK_SIZE;
27530+#endif
27531+
27532+ if (flags & MAP_FIXED)
27533+ if (len > pax_task_size || addr > pax_task_size - len)
27534+ return -EINVAL;
27535+
27536+ return 0;
27537+}
27538+
27539+/*
27540+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
27541+ */
27542+static unsigned long get_align_mask(void)
27543+{
27544+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27545+ return 0;
27546+
27547+ if (!(current->flags & PF_RANDOMIZE))
27548+ return 0;
27549+
27550+ return va_align.mask;
27551+}
27552+
27553+unsigned long
27554+arch_get_unmapped_area(struct file *filp, unsigned long addr,
27555+ unsigned long len, unsigned long pgoff, unsigned long flags)
27556+{
27557+ struct mm_struct *mm = current->mm;
27558+ struct vm_area_struct *vma;
27559+ unsigned long pax_task_size = TASK_SIZE;
27560+ struct vm_unmapped_area_info info;
27561+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27562+
27563+#ifdef CONFIG_PAX_SEGMEXEC
27564+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27565+ pax_task_size = SEGMEXEC_TASK_SIZE;
27566+#endif
27567+
27568+ pax_task_size -= PAGE_SIZE;
27569+
27570+ if (len > pax_task_size)
27571+ return -ENOMEM;
27572+
27573+ if (flags & MAP_FIXED)
27574+ return addr;
27575+
27576+#ifdef CONFIG_PAX_RANDMMAP
27577+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27578+#endif
27579+
27580+ if (addr) {
27581+ addr = PAGE_ALIGN(addr);
27582+ if (pax_task_size - len >= addr) {
27583+ vma = find_vma(mm, addr);
27584+ if (check_heap_stack_gap(vma, addr, len, offset))
27585+ return addr;
27586+ }
27587+ }
27588+
27589+ info.flags = 0;
27590+ info.length = len;
27591+ info.align_mask = filp ? get_align_mask() : 0;
27592+ info.align_offset = pgoff << PAGE_SHIFT;
27593+ info.threadstack_offset = offset;
27594+
27595+#ifdef CONFIG_PAX_PAGEEXEC
27596+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27597+ info.low_limit = 0x00110000UL;
27598+ info.high_limit = mm->start_code;
27599+
27600+#ifdef CONFIG_PAX_RANDMMAP
27601+ if (mm->pax_flags & MF_PAX_RANDMMAP)
27602+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27603+#endif
27604+
27605+ if (info.low_limit < info.high_limit) {
27606+ addr = vm_unmapped_area(&info);
27607+ if (!IS_ERR_VALUE(addr))
27608+ return addr;
27609+ }
27610+ } else
27611+#endif
27612+
27613+ info.low_limit = mm->mmap_base;
27614+ info.high_limit = pax_task_size;
27615+
27616+ return vm_unmapped_area(&info);
27617+}
27618+
27619+unsigned long
27620+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27621+ const unsigned long len, const unsigned long pgoff,
27622+ const unsigned long flags)
27623+{
27624+ struct vm_area_struct *vma;
27625+ struct mm_struct *mm = current->mm;
27626+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27627+ struct vm_unmapped_area_info info;
27628+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27629+
27630+#ifdef CONFIG_PAX_SEGMEXEC
27631+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27632+ pax_task_size = SEGMEXEC_TASK_SIZE;
27633+#endif
27634+
27635+ pax_task_size -= PAGE_SIZE;
27636+
27637+ /* requested length too big for entire address space */
27638+ if (len > pax_task_size)
27639+ return -ENOMEM;
27640+
27641+ if (flags & MAP_FIXED)
27642+ return addr;
27643+
27644+#ifdef CONFIG_PAX_PAGEEXEC
27645+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27646+ goto bottomup;
27647+#endif
27648+
27649+#ifdef CONFIG_PAX_RANDMMAP
27650+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27651+#endif
27652+
27653+ /* requesting a specific address */
27654+ if (addr) {
27655+ addr = PAGE_ALIGN(addr);
27656+ if (pax_task_size - len >= addr) {
27657+ vma = find_vma(mm, addr);
27658+ if (check_heap_stack_gap(vma, addr, len, offset))
27659+ return addr;
27660+ }
27661+ }
27662+
27663+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27664+ info.length = len;
27665+ info.low_limit = PAGE_SIZE;
27666+ info.high_limit = mm->mmap_base;
27667+ info.align_mask = filp ? get_align_mask() : 0;
27668+ info.align_offset = pgoff << PAGE_SHIFT;
27669+ info.threadstack_offset = offset;
27670+
27671+ addr = vm_unmapped_area(&info);
27672+ if (!(addr & ~PAGE_MASK))
27673+ return addr;
27674+ VM_BUG_ON(addr != -ENOMEM);
27675+
27676+bottomup:
27677+ /*
27678+ * A failed mmap() very likely causes application failure,
27679+ * so fall back to the bottom-up function here. This scenario
27680+ * can happen with large stack limits and large mmap()
27681+ * allocations.
27682+ */
27683+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27684+}
27685diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27686index 30277e2..5664a29 100644
27687--- a/arch/x86/kernel/sys_x86_64.c
27688+++ b/arch/x86/kernel/sys_x86_64.c
27689@@ -81,8 +81,8 @@ out:
27690 return error;
27691 }
27692
27693-static void find_start_end(unsigned long flags, unsigned long *begin,
27694- unsigned long *end)
27695+static void find_start_end(struct mm_struct *mm, unsigned long flags,
27696+ unsigned long *begin, unsigned long *end)
27697 {
27698 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27699 unsigned long new_begin;
27700@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27701 *begin = new_begin;
27702 }
27703 } else {
27704- *begin = current->mm->mmap_legacy_base;
27705+ *begin = mm->mmap_legacy_base;
27706 *end = TASK_SIZE;
27707 }
27708 }
27709@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27710 struct vm_area_struct *vma;
27711 struct vm_unmapped_area_info info;
27712 unsigned long begin, end;
27713+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27714
27715 if (flags & MAP_FIXED)
27716 return addr;
27717
27718- find_start_end(flags, &begin, &end);
27719+ find_start_end(mm, flags, &begin, &end);
27720
27721 if (len > end)
27722 return -ENOMEM;
27723
27724+#ifdef CONFIG_PAX_RANDMMAP
27725+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27726+#endif
27727+
27728 if (addr) {
27729 addr = PAGE_ALIGN(addr);
27730 vma = find_vma(mm, addr);
27731- if (end - len >= addr &&
27732- (!vma || addr + len <= vma->vm_start))
27733+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27734 return addr;
27735 }
27736
27737@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27738 info.high_limit = end;
27739 info.align_mask = filp ? get_align_mask() : 0;
27740 info.align_offset = pgoff << PAGE_SHIFT;
27741+ info.threadstack_offset = offset;
27742 return vm_unmapped_area(&info);
27743 }
27744
27745@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27746 struct mm_struct *mm = current->mm;
27747 unsigned long addr = addr0;
27748 struct vm_unmapped_area_info info;
27749+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27750
27751 /* requested length too big for entire address space */
27752 if (len > TASK_SIZE)
27753@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27754 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27755 goto bottomup;
27756
27757+#ifdef CONFIG_PAX_RANDMMAP
27758+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27759+#endif
27760+
27761 /* requesting a specific address */
27762 if (addr) {
27763 addr = PAGE_ALIGN(addr);
27764 vma = find_vma(mm, addr);
27765- if (TASK_SIZE - len >= addr &&
27766- (!vma || addr + len <= vma->vm_start))
27767+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27768 return addr;
27769 }
27770
27771@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27772 info.high_limit = mm->mmap_base;
27773 info.align_mask = filp ? get_align_mask() : 0;
27774 info.align_offset = pgoff << PAGE_SHIFT;
27775+ info.threadstack_offset = offset;
27776 addr = vm_unmapped_area(&info);
27777 if (!(addr & ~PAGE_MASK))
27778 return addr;
27779diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27780index 91a4496..bb87552 100644
27781--- a/arch/x86/kernel/tboot.c
27782+++ b/arch/x86/kernel/tboot.c
27783@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27784
27785 void tboot_shutdown(u32 shutdown_type)
27786 {
27787- void (*shutdown)(void);
27788+ void (* __noreturn shutdown)(void);
27789
27790 if (!tboot_enabled())
27791 return;
27792@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27793
27794 switch_to_tboot_pt();
27795
27796- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27797+ shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27798 shutdown();
27799
27800 /* should not reach here */
27801@@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27802 return -ENODEV;
27803 }
27804
27805-static atomic_t ap_wfs_count;
27806+static atomic_unchecked_t ap_wfs_count;
27807
27808 static int tboot_wait_for_aps(int num_aps)
27809 {
27810@@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27811 {
27812 switch (action) {
27813 case CPU_DYING:
27814- atomic_inc(&ap_wfs_count);
27815+ atomic_inc_unchecked(&ap_wfs_count);
27816 if (num_online_cpus() == 1)
27817- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27818+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27819 return NOTIFY_BAD;
27820 break;
27821 }
27822@@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27823
27824 tboot_create_trampoline();
27825
27826- atomic_set(&ap_wfs_count, 0);
27827+ atomic_set_unchecked(&ap_wfs_count, 0);
27828 register_hotcpu_notifier(&tboot_cpu_notifier);
27829
27830 #ifdef CONFIG_DEBUG_FS
27831diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27832index 0fa2960..91eabbe 100644
27833--- a/arch/x86/kernel/time.c
27834+++ b/arch/x86/kernel/time.c
27835@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27836 {
27837 unsigned long pc = instruction_pointer(regs);
27838
27839- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27840+ if (!user_mode(regs) && in_lock_functions(pc)) {
27841 #ifdef CONFIG_FRAME_POINTER
27842- return *(unsigned long *)(regs->bp + sizeof(long));
27843+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27844 #else
27845 unsigned long *sp =
27846 (unsigned long *)kernel_stack_pointer(regs);
27847@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27848 * or above a saved flags. Eflags has bits 22-31 zero,
27849 * kernel addresses don't.
27850 */
27851+
27852+#ifdef CONFIG_PAX_KERNEXEC
27853+ return ktla_ktva(sp[0]);
27854+#else
27855 if (sp[0] >> 22)
27856 return sp[0];
27857 if (sp[1] >> 22)
27858 return sp[1];
27859 #endif
27860+
27861+#endif
27862 }
27863 return pc;
27864 }
27865diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27866index f7fec09..d0f623f 100644
27867--- a/arch/x86/kernel/tls.c
27868+++ b/arch/x86/kernel/tls.c
27869@@ -27,6 +27,37 @@ static int get_free_idx(void)
27870 return -ESRCH;
27871 }
27872
27873+static bool tls_desc_okay(const struct user_desc *info)
27874+{
27875+ if (LDT_empty(info))
27876+ return true;
27877+
27878+ /*
27879+ * espfix is required for 16-bit data segments, but espfix
27880+ * only works for LDT segments.
27881+ */
27882+ if (!info->seg_32bit)
27883+ return false;
27884+
27885+ /* Only allow data segments in the TLS array. */
27886+ if (info->contents > 1)
27887+ return false;
27888+
27889+ /*
27890+ * Non-present segments with DPL 3 present an interesting attack
27891+ * surface. The kernel should handle such segments correctly,
27892+ * but TLS is very difficult to protect in a sandbox, so prevent
27893+ * such segments from being created.
27894+ *
27895+ * If userspace needs to remove a TLS entry, it can still delete
27896+ * it outright.
27897+ */
27898+ if (info->seg_not_present)
27899+ return false;
27900+
27901+ return true;
27902+}
27903+
27904 static void set_tls_desc(struct task_struct *p, int idx,
27905 const struct user_desc *info, int n)
27906 {
27907@@ -66,6 +97,9 @@ int do_set_thread_area(struct task_struct *p, int idx,
27908 if (copy_from_user(&info, u_info, sizeof(info)))
27909 return -EFAULT;
27910
27911+ if (!tls_desc_okay(&info))
27912+ return -EINVAL;
27913+
27914 if (idx == -1)
27915 idx = info.entry_number;
27916
27917@@ -84,6 +118,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27918 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27919 return -EINVAL;
27920
27921+#ifdef CONFIG_PAX_SEGMEXEC
27922+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27923+ return -EINVAL;
27924+#endif
27925+
27926 set_tls_desc(p, idx, &info, 1);
27927
27928 return 0;
27929@@ -192,6 +231,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27930 {
27931 struct user_desc infobuf[GDT_ENTRY_TLS_ENTRIES];
27932 const struct user_desc *info;
27933+ int i;
27934
27935 if (pos >= GDT_ENTRY_TLS_ENTRIES * sizeof(struct user_desc) ||
27936 (pos % sizeof(struct user_desc)) != 0 ||
27937@@ -200,11 +240,15 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27938
27939 if (kbuf)
27940 info = kbuf;
27941- else if (__copy_from_user(infobuf, ubuf, count))
27942+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27943 return -EFAULT;
27944 else
27945 info = infobuf;
27946
27947+ for (i = 0; i < count / sizeof(struct user_desc); i++)
27948+ if (!tls_desc_okay(info + i))
27949+ return -EINVAL;
27950+
27951 set_tls_desc(target,
27952 GDT_ENTRY_TLS_MIN + (pos / sizeof(struct user_desc)),
27953 info, count / sizeof(struct user_desc));
27954diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27955index 1c113db..287b42e 100644
27956--- a/arch/x86/kernel/tracepoint.c
27957+++ b/arch/x86/kernel/tracepoint.c
27958@@ -9,11 +9,11 @@
27959 #include <linux/atomic.h>
27960
27961 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27962-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27963+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27964 (unsigned long) trace_idt_table };
27965
27966 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27967-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27968+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27969
27970 static int trace_irq_vector_refcount;
27971 static DEFINE_MUTEX(irq_vector_mutex);
27972diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27973index de801f2..4a4c4af 100644
27974--- a/arch/x86/kernel/traps.c
27975+++ b/arch/x86/kernel/traps.c
27976@@ -67,7 +67,7 @@
27977 #include <asm/proto.h>
27978
27979 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27980-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27981+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27982 #else
27983 #include <asm/processor-flags.h>
27984 #include <asm/setup.h>
27985@@ -76,7 +76,7 @@ asmlinkage int system_call(void);
27986 #endif
27987
27988 /* Must be page-aligned because the real IDT is used in a fixmap. */
27989-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27990+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27991
27992 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27993 EXPORT_SYMBOL_GPL(used_vectors);
27994@@ -108,11 +108,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27995 }
27996
27997 static nokprobe_inline int
27998-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27999+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
28000 struct pt_regs *regs, long error_code)
28001 {
28002 #ifdef CONFIG_X86_32
28003- if (regs->flags & X86_VM_MASK) {
28004+ if (v8086_mode(regs)) {
28005 /*
28006 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
28007 * On nmi (interrupt 2), do_trap should not be called.
28008@@ -125,12 +125,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
28009 return -1;
28010 }
28011 #endif
28012- if (!user_mode(regs)) {
28013+ if (!user_mode_novm(regs)) {
28014 if (!fixup_exception(regs)) {
28015 tsk->thread.error_code = error_code;
28016 tsk->thread.trap_nr = trapnr;
28017+
28018+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28019+ if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
28020+ str = "PAX: suspicious stack segment fault";
28021+#endif
28022+
28023 die(str, regs, error_code);
28024 }
28025+
28026+#ifdef CONFIG_PAX_REFCOUNT
28027+ if (trapnr == X86_TRAP_OF)
28028+ pax_report_refcount_overflow(regs);
28029+#endif
28030+
28031 return 0;
28032 }
28033
28034@@ -169,7 +181,7 @@ static siginfo_t *fill_trap_info(struct pt_regs *regs, int signr, int trapnr,
28035 }
28036
28037 static void
28038-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
28039+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
28040 long error_code, siginfo_t *info)
28041 {
28042 struct task_struct *tsk = current;
28043@@ -193,7 +205,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
28044 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
28045 printk_ratelimit()) {
28046 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
28047- tsk->comm, tsk->pid, str,
28048+ tsk->comm, task_pid_nr(tsk), str,
28049 regs->ip, regs->sp, error_code);
28050 print_vma_addr(" in ", regs->ip);
28051 pr_cont("\n");
28052@@ -274,6 +286,11 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
28053 tsk->thread.error_code = error_code;
28054 tsk->thread.trap_nr = X86_TRAP_DF;
28055
28056+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
28057+ if ((unsigned long)tsk->stack - regs->sp <= PAGE_SIZE)
28058+ die("grsec: kernel stack overflow detected", regs, error_code);
28059+#endif
28060+
28061 #ifdef CONFIG_DOUBLEFAULT
28062 df_debug(regs, error_code);
28063 #endif
28064@@ -296,7 +313,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
28065 conditional_sti(regs);
28066
28067 #ifdef CONFIG_X86_32
28068- if (regs->flags & X86_VM_MASK) {
28069+ if (v8086_mode(regs)) {
28070 local_irq_enable();
28071 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
28072 goto exit;
28073@@ -304,18 +321,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
28074 #endif
28075
28076 tsk = current;
28077- if (!user_mode(regs)) {
28078+ if (!user_mode_novm(regs)) {
28079 if (fixup_exception(regs))
28080 goto exit;
28081
28082 tsk->thread.error_code = error_code;
28083 tsk->thread.trap_nr = X86_TRAP_GP;
28084 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
28085- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
28086+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
28087+
28088+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28089+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
28090+ die("PAX: suspicious general protection fault", regs, error_code);
28091+ else
28092+#endif
28093+
28094 die("general protection fault", regs, error_code);
28095+ }
28096 goto exit;
28097 }
28098
28099+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
28100+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
28101+ struct mm_struct *mm = tsk->mm;
28102+ unsigned long limit;
28103+
28104+ down_write(&mm->mmap_sem);
28105+ limit = mm->context.user_cs_limit;
28106+ if (limit < TASK_SIZE) {
28107+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
28108+ up_write(&mm->mmap_sem);
28109+ return;
28110+ }
28111+ up_write(&mm->mmap_sem);
28112+ }
28113+#endif
28114+
28115 tsk->thread.error_code = error_code;
28116 tsk->thread.trap_nr = X86_TRAP_GP;
28117
28118@@ -427,13 +468,16 @@ struct bad_iret_stack *fixup_bad_iret(struct bad_iret_stack *s)
28119 container_of(task_pt_regs(current),
28120 struct bad_iret_stack, regs);
28121
28122+ if ((current->thread.sp0 ^ (unsigned long)s) < THREAD_SIZE)
28123+ new_stack = s;
28124+
28125 /* Copy the IRET target to the new stack. */
28126 memmove(&new_stack->regs.ip, (void *)s->regs.sp, 5*8);
28127
28128 /* Copy the remainder of the stack from the current stack. */
28129 memmove(new_stack, s, offsetof(struct bad_iret_stack, regs.ip));
28130
28131- BUG_ON(!user_mode_vm(&new_stack->regs));
28132+ BUG_ON(!user_mode(&new_stack->regs));
28133 return new_stack;
28134 }
28135 #endif
28136@@ -518,7 +562,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28137 /* It's safe to allow irq's after DR6 has been saved */
28138 preempt_conditional_sti(regs);
28139
28140- if (regs->flags & X86_VM_MASK) {
28141+ if (v8086_mode(regs)) {
28142 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
28143 X86_TRAP_DB);
28144 preempt_conditional_cli(regs);
28145@@ -533,7 +577,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28146 * We already checked v86 mode above, so we can check for kernel mode
28147 * by just checking the CPL of CS.
28148 */
28149- if ((dr6 & DR_STEP) && !user_mode(regs)) {
28150+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
28151 tsk->thread.debugreg6 &= ~DR_STEP;
28152 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
28153 regs->flags &= ~X86_EFLAGS_TF;
28154@@ -566,7 +610,7 @@ static void math_error(struct pt_regs *regs, int error_code, int trapnr)
28155 return;
28156 conditional_sti(regs);
28157
28158- if (!user_mode_vm(regs))
28159+ if (!user_mode(regs))
28160 {
28161 if (!fixup_exception(regs)) {
28162 task->thread.error_code = error_code;
28163diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
28164index b7e50bb..f4a93ae 100644
28165--- a/arch/x86/kernel/tsc.c
28166+++ b/arch/x86/kernel/tsc.c
28167@@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
28168 */
28169 smp_wmb();
28170
28171- ACCESS_ONCE(c2n->head) = data;
28172+ ACCESS_ONCE_RW(c2n->head) = data;
28173 }
28174
28175 /*
28176diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
28177index 5d1cbfe..2a21feb 100644
28178--- a/arch/x86/kernel/uprobes.c
28179+++ b/arch/x86/kernel/uprobes.c
28180@@ -845,7 +845,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
28181 int ret = NOTIFY_DONE;
28182
28183 /* We are only interested in userspace traps */
28184- if (regs && !user_mode_vm(regs))
28185+ if (regs && !user_mode(regs))
28186 return NOTIFY_DONE;
28187
28188 switch (val) {
28189@@ -919,7 +919,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
28190
28191 if (nleft != rasize) {
28192 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
28193- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
28194+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
28195
28196 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
28197 }
28198diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
28199index b9242ba..50c5edd 100644
28200--- a/arch/x86/kernel/verify_cpu.S
28201+++ b/arch/x86/kernel/verify_cpu.S
28202@@ -20,6 +20,7 @@
28203 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
28204 * arch/x86/kernel/trampoline_64.S: secondary processor verification
28205 * arch/x86/kernel/head_32.S: processor startup
28206+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
28207 *
28208 * verify_cpu, returns the status of longmode and SSE in register %eax.
28209 * 0: Success 1: Failure
28210diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
28211index e8edcf5..27f9344 100644
28212--- a/arch/x86/kernel/vm86_32.c
28213+++ b/arch/x86/kernel/vm86_32.c
28214@@ -44,6 +44,7 @@
28215 #include <linux/ptrace.h>
28216 #include <linux/audit.h>
28217 #include <linux/stddef.h>
28218+#include <linux/grsecurity.h>
28219
28220 #include <asm/uaccess.h>
28221 #include <asm/io.h>
28222@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
28223 do_exit(SIGSEGV);
28224 }
28225
28226- tss = &per_cpu(init_tss, get_cpu());
28227+ tss = init_tss + get_cpu();
28228 current->thread.sp0 = current->thread.saved_sp0;
28229 current->thread.sysenter_cs = __KERNEL_CS;
28230 load_sp0(tss, &current->thread);
28231@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
28232
28233 if (tsk->thread.saved_sp0)
28234 return -EPERM;
28235+
28236+#ifdef CONFIG_GRKERNSEC_VM86
28237+ if (!capable(CAP_SYS_RAWIO)) {
28238+ gr_handle_vm86();
28239+ return -EPERM;
28240+ }
28241+#endif
28242+
28243 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
28244 offsetof(struct kernel_vm86_struct, vm86plus) -
28245 sizeof(info.regs));
28246@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
28247 int tmp;
28248 struct vm86plus_struct __user *v86;
28249
28250+#ifdef CONFIG_GRKERNSEC_VM86
28251+ if (!capable(CAP_SYS_RAWIO)) {
28252+ gr_handle_vm86();
28253+ return -EPERM;
28254+ }
28255+#endif
28256+
28257 tsk = current;
28258 switch (cmd) {
28259 case VM86_REQUEST_IRQ:
28260@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
28261 tsk->thread.saved_fs = info->regs32->fs;
28262 tsk->thread.saved_gs = get_user_gs(info->regs32);
28263
28264- tss = &per_cpu(init_tss, get_cpu());
28265+ tss = init_tss + get_cpu();
28266 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
28267 if (cpu_has_sep)
28268 tsk->thread.sysenter_cs = 0;
28269@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
28270 goto cannot_handle;
28271 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
28272 goto cannot_handle;
28273- intr_ptr = (unsigned long __user *) (i << 2);
28274+ intr_ptr = (__force unsigned long __user *) (i << 2);
28275 if (get_user(segoffs, intr_ptr))
28276 goto cannot_handle;
28277 if ((segoffs >> 16) == BIOSSEG)
28278diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
28279index 49edf2d..c0d1362 100644
28280--- a/arch/x86/kernel/vmlinux.lds.S
28281+++ b/arch/x86/kernel/vmlinux.lds.S
28282@@ -26,6 +26,13 @@
28283 #include <asm/page_types.h>
28284 #include <asm/cache.h>
28285 #include <asm/boot.h>
28286+#include <asm/segment.h>
28287+
28288+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28289+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
28290+#else
28291+#define __KERNEL_TEXT_OFFSET 0
28292+#endif
28293
28294 #undef i386 /* in case the preprocessor is a 32bit one */
28295
28296@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
28297
28298 PHDRS {
28299 text PT_LOAD FLAGS(5); /* R_E */
28300+#ifdef CONFIG_X86_32
28301+ module PT_LOAD FLAGS(5); /* R_E */
28302+#endif
28303+#ifdef CONFIG_XEN
28304+ rodata PT_LOAD FLAGS(5); /* R_E */
28305+#else
28306+ rodata PT_LOAD FLAGS(4); /* R__ */
28307+#endif
28308 data PT_LOAD FLAGS(6); /* RW_ */
28309-#ifdef CONFIG_X86_64
28310+ init.begin PT_LOAD FLAGS(6); /* RW_ */
28311 #ifdef CONFIG_SMP
28312 percpu PT_LOAD FLAGS(6); /* RW_ */
28313 #endif
28314+ text.init PT_LOAD FLAGS(5); /* R_E */
28315+ text.exit PT_LOAD FLAGS(5); /* R_E */
28316 init PT_LOAD FLAGS(7); /* RWE */
28317-#endif
28318 note PT_NOTE FLAGS(0); /* ___ */
28319 }
28320
28321 SECTIONS
28322 {
28323 #ifdef CONFIG_X86_32
28324- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
28325- phys_startup_32 = startup_32 - LOAD_OFFSET;
28326+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
28327 #else
28328- . = __START_KERNEL;
28329- phys_startup_64 = startup_64 - LOAD_OFFSET;
28330+ . = __START_KERNEL;
28331 #endif
28332
28333 /* Text and read-only data */
28334- .text : AT(ADDR(.text) - LOAD_OFFSET) {
28335- _text = .;
28336+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28337 /* bootstrapping code */
28338+#ifdef CONFIG_X86_32
28339+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28340+#else
28341+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28342+#endif
28343+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28344+ _text = .;
28345 HEAD_TEXT
28346 . = ALIGN(8);
28347 _stext = .;
28348@@ -104,13 +124,47 @@ SECTIONS
28349 IRQENTRY_TEXT
28350 *(.fixup)
28351 *(.gnu.warning)
28352- /* End of text section */
28353- _etext = .;
28354 } :text = 0x9090
28355
28356- NOTES :text :note
28357+ . += __KERNEL_TEXT_OFFSET;
28358
28359- EXCEPTION_TABLE(16) :text = 0x9090
28360+#ifdef CONFIG_X86_32
28361+ . = ALIGN(PAGE_SIZE);
28362+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
28363+
28364+#ifdef CONFIG_PAX_KERNEXEC
28365+ MODULES_EXEC_VADDR = .;
28366+ BYTE(0)
28367+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
28368+ . = ALIGN(HPAGE_SIZE) - 1;
28369+ MODULES_EXEC_END = .;
28370+#endif
28371+
28372+ } :module
28373+#endif
28374+
28375+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
28376+ /* End of text section */
28377+ BYTE(0)
28378+ _etext = . - __KERNEL_TEXT_OFFSET;
28379+ }
28380+
28381+#ifdef CONFIG_X86_32
28382+ . = ALIGN(PAGE_SIZE);
28383+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
28384+ . = ALIGN(PAGE_SIZE);
28385+ *(.empty_zero_page)
28386+ *(.initial_pg_fixmap)
28387+ *(.initial_pg_pmd)
28388+ *(.initial_page_table)
28389+ *(.swapper_pg_dir)
28390+ } :rodata
28391+#endif
28392+
28393+ . = ALIGN(PAGE_SIZE);
28394+ NOTES :rodata :note
28395+
28396+ EXCEPTION_TABLE(16) :rodata
28397
28398 #if defined(CONFIG_DEBUG_RODATA)
28399 /* .text should occupy whole number of pages */
28400@@ -122,16 +176,20 @@ SECTIONS
28401
28402 /* Data */
28403 .data : AT(ADDR(.data) - LOAD_OFFSET) {
28404+
28405+#ifdef CONFIG_PAX_KERNEXEC
28406+ . = ALIGN(HPAGE_SIZE);
28407+#else
28408+ . = ALIGN(PAGE_SIZE);
28409+#endif
28410+
28411 /* Start of data section */
28412 _sdata = .;
28413
28414 /* init_task */
28415 INIT_TASK_DATA(THREAD_SIZE)
28416
28417-#ifdef CONFIG_X86_32
28418- /* 32 bit has nosave before _edata */
28419 NOSAVE_DATA
28420-#endif
28421
28422 PAGE_ALIGNED_DATA(PAGE_SIZE)
28423
28424@@ -174,12 +232,19 @@ SECTIONS
28425 . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE);
28426
28427 /* Init code and data - will be freed after init */
28428- . = ALIGN(PAGE_SIZE);
28429 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
28430+ BYTE(0)
28431+
28432+#ifdef CONFIG_PAX_KERNEXEC
28433+ . = ALIGN(HPAGE_SIZE);
28434+#else
28435+ . = ALIGN(PAGE_SIZE);
28436+#endif
28437+
28438 __init_begin = .; /* paired with __init_end */
28439- }
28440+ } :init.begin
28441
28442-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
28443+#ifdef CONFIG_SMP
28444 /*
28445 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
28446 * output PHDR, so the next output section - .init.text - should
28447@@ -188,12 +253,27 @@ SECTIONS
28448 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
28449 #endif
28450
28451- INIT_TEXT_SECTION(PAGE_SIZE)
28452-#ifdef CONFIG_X86_64
28453- :init
28454-#endif
28455+ . = ALIGN(PAGE_SIZE);
28456+ init_begin = .;
28457+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
28458+ VMLINUX_SYMBOL(_sinittext) = .;
28459+ INIT_TEXT
28460+ VMLINUX_SYMBOL(_einittext) = .;
28461+ . = ALIGN(PAGE_SIZE);
28462+ } :text.init
28463
28464- INIT_DATA_SECTION(16)
28465+ /*
28466+ * .exit.text is discard at runtime, not link time, to deal with
28467+ * references from .altinstructions and .eh_frame
28468+ */
28469+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28470+ EXIT_TEXT
28471+ . = ALIGN(16);
28472+ } :text.exit
28473+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
28474+
28475+ . = ALIGN(PAGE_SIZE);
28476+ INIT_DATA_SECTION(16) :init
28477
28478 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
28479 __x86_cpu_dev_start = .;
28480@@ -264,19 +344,12 @@ SECTIONS
28481 }
28482
28483 . = ALIGN(8);
28484- /*
28485- * .exit.text is discard at runtime, not link time, to deal with
28486- * references from .altinstructions and .eh_frame
28487- */
28488- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
28489- EXIT_TEXT
28490- }
28491
28492 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
28493 EXIT_DATA
28494 }
28495
28496-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
28497+#ifndef CONFIG_SMP
28498 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
28499 #endif
28500
28501@@ -295,16 +368,10 @@ SECTIONS
28502 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
28503 __smp_locks = .;
28504 *(.smp_locks)
28505- . = ALIGN(PAGE_SIZE);
28506 __smp_locks_end = .;
28507+ . = ALIGN(PAGE_SIZE);
28508 }
28509
28510-#ifdef CONFIG_X86_64
28511- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
28512- NOSAVE_DATA
28513- }
28514-#endif
28515-
28516 /* BSS */
28517 . = ALIGN(PAGE_SIZE);
28518 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
28519@@ -320,6 +387,7 @@ SECTIONS
28520 __brk_base = .;
28521 . += 64 * 1024; /* 64k alignment slop space */
28522 *(.brk_reservation) /* areas brk users have reserved */
28523+ . = ALIGN(HPAGE_SIZE);
28524 __brk_limit = .;
28525 }
28526
28527@@ -346,13 +414,12 @@ SECTIONS
28528 * for the boot processor.
28529 */
28530 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
28531-INIT_PER_CPU(gdt_page);
28532 INIT_PER_CPU(irq_stack_union);
28533
28534 /*
28535 * Build-time check on the image size:
28536 */
28537-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
28538+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
28539 "kernel image bigger than KERNEL_IMAGE_SIZE");
28540
28541 #ifdef CONFIG_SMP
28542diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
28543index 957779f..74e405c 100644
28544--- a/arch/x86/kernel/vsyscall_64.c
28545+++ b/arch/x86/kernel/vsyscall_64.c
28546@@ -54,15 +54,13 @@
28547
28548 DEFINE_VVAR(int, vgetcpu_mode);
28549
28550-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
28551+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
28552
28553 static int __init vsyscall_setup(char *str)
28554 {
28555 if (str) {
28556 if (!strcmp("emulate", str))
28557 vsyscall_mode = EMULATE;
28558- else if (!strcmp("native", str))
28559- vsyscall_mode = NATIVE;
28560 else if (!strcmp("none", str))
28561 vsyscall_mode = NONE;
28562 else
28563@@ -279,8 +277,7 @@ do_ret:
28564 return true;
28565
28566 sigsegv:
28567- force_sig(SIGSEGV, current);
28568- return true;
28569+ do_group_exit(SIGKILL);
28570 }
28571
28572 /*
28573@@ -331,10 +328,7 @@ void __init map_vsyscall(void)
28574 extern char __vsyscall_page;
28575 unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page);
28576
28577- __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall,
28578- vsyscall_mode == NATIVE
28579- ? PAGE_KERNEL_VSYSCALL
28580- : PAGE_KERNEL_VVAR);
28581+ __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
28582 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_PAGE) !=
28583 (unsigned long)VSYSCALL_ADDR);
28584 }
28585diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
28586index 04068192..4d75aa6 100644
28587--- a/arch/x86/kernel/x8664_ksyms_64.c
28588+++ b/arch/x86/kernel/x8664_ksyms_64.c
28589@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
28590 EXPORT_SYMBOL(copy_user_generic_unrolled);
28591 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
28592 EXPORT_SYMBOL(__copy_user_nocache);
28593-EXPORT_SYMBOL(_copy_from_user);
28594-EXPORT_SYMBOL(_copy_to_user);
28595
28596 EXPORT_SYMBOL(copy_page);
28597 EXPORT_SYMBOL(clear_page);
28598@@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
28599 EXPORT_SYMBOL(___preempt_schedule_context);
28600 #endif
28601 #endif
28602+
28603+#ifdef CONFIG_PAX_PER_CPU_PGD
28604+EXPORT_SYMBOL(cpu_pgd);
28605+#endif
28606diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
28607index e48b674..a451dd9 100644
28608--- a/arch/x86/kernel/x86_init.c
28609+++ b/arch/x86/kernel/x86_init.c
28610@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
28611 static void default_nmi_init(void) { };
28612 static int default_i8042_detect(void) { return 1; };
28613
28614-struct x86_platform_ops x86_platform = {
28615+struct x86_platform_ops x86_platform __read_only = {
28616 .calibrate_tsc = native_calibrate_tsc,
28617 .get_wallclock = mach_get_cmos_time,
28618 .set_wallclock = mach_set_rtc_mmss,
28619@@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
28620 EXPORT_SYMBOL_GPL(x86_platform);
28621
28622 #if defined(CONFIG_PCI_MSI)
28623-struct x86_msi_ops x86_msi = {
28624+struct x86_msi_ops x86_msi __read_only = {
28625 .setup_msi_irqs = native_setup_msi_irqs,
28626 .compose_msi_msg = native_compose_msi_msg,
28627 .teardown_msi_irq = native_teardown_msi_irq,
28628@@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
28629 }
28630 #endif
28631
28632-struct x86_io_apic_ops x86_io_apic_ops = {
28633+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
28634 .init = native_io_apic_init_mappings,
28635 .read = native_io_apic_read,
28636 .write = native_io_apic_write,
28637diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
28638index 4c540c4..0b985b0 100644
28639--- a/arch/x86/kernel/xsave.c
28640+++ b/arch/x86/kernel/xsave.c
28641@@ -167,18 +167,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28642
28643 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
28644 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
28645- err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28646+ err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28647
28648 if (!use_xsave())
28649 return err;
28650
28651- err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28652+ err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28653
28654 /*
28655 * Read the xstate_bv which we copied (directly from the cpu or
28656 * from the state in task struct) to the user buffers.
28657 */
28658- err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28659+ err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28660
28661 /*
28662 * For legacy compatible, we always set FP/SSE bits in the bit
28663@@ -193,7 +193,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28664 */
28665 xstate_bv |= XSTATE_FPSSE;
28666
28667- err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28668+ err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28669
28670 return err;
28671 }
28672@@ -202,6 +202,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28673 {
28674 int err;
28675
28676+ buf = (struct xsave_struct __user *)____m(buf);
28677 if (use_xsave())
28678 err = xsave_user(buf);
28679 else if (use_fxsr())
28680@@ -312,6 +313,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28681 */
28682 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28683 {
28684+ buf = (void __user *)____m(buf);
28685 if (use_xsave()) {
28686 if ((unsigned long)buf % 64 || fx_only) {
28687 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28688diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28689index 976e3a5..8bb998c 100644
28690--- a/arch/x86/kvm/cpuid.c
28691+++ b/arch/x86/kvm/cpuid.c
28692@@ -175,15 +175,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28693 struct kvm_cpuid2 *cpuid,
28694 struct kvm_cpuid_entry2 __user *entries)
28695 {
28696- int r;
28697+ int r, i;
28698
28699 r = -E2BIG;
28700 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28701 goto out;
28702 r = -EFAULT;
28703- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28704- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28705+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28706 goto out;
28707+ for (i = 0; i < cpuid->nent; ++i) {
28708+ struct kvm_cpuid_entry2 cpuid_entry;
28709+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28710+ goto out;
28711+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
28712+ }
28713 vcpu->arch.cpuid_nent = cpuid->nent;
28714 kvm_apic_set_version(vcpu);
28715 kvm_x86_ops->cpuid_update(vcpu);
28716@@ -196,15 +201,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28717 struct kvm_cpuid2 *cpuid,
28718 struct kvm_cpuid_entry2 __user *entries)
28719 {
28720- int r;
28721+ int r, i;
28722
28723 r = -E2BIG;
28724 if (cpuid->nent < vcpu->arch.cpuid_nent)
28725 goto out;
28726 r = -EFAULT;
28727- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28728- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28729+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28730 goto out;
28731+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28732+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28733+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28734+ goto out;
28735+ }
28736 return 0;
28737
28738 out:
28739diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
28740index 9f8a2fa..2df3c3f 100644
28741--- a/arch/x86/kvm/emulate.c
28742+++ b/arch/x86/kvm/emulate.c
28743@@ -3519,7 +3519,7 @@ static int check_cr_write(struct x86_emulate_ctxt *ctxt)
28744 int cr = ctxt->modrm_reg;
28745 u64 efer = 0;
28746
28747- static u64 cr_reserved_bits[] = {
28748+ static const u64 cr_reserved_bits[] = {
28749 0xffffffff00000000ULL,
28750 0, 0, 0, /* CR3 checked later */
28751 CR4_RESERVED_BITS,
28752@@ -3554,7 +3554,7 @@ static int check_cr_write(struct x86_emulate_ctxt *ctxt)
28753
28754 ctxt->ops->get_msr(ctxt, MSR_EFER, &efer);
28755 if (efer & EFER_LMA)
28756- rsvd = CR3_L_MODE_RESERVED_BITS;
28757+ rsvd = CR3_L_MODE_RESERVED_BITS & ~CR3_PCID_INVD;
28758
28759 if (new_val & rsvd)
28760 return emulate_gp(ctxt, 0);
28761diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28762index b8345dd..f225d71 100644
28763--- a/arch/x86/kvm/lapic.c
28764+++ b/arch/x86/kvm/lapic.c
28765@@ -55,7 +55,7 @@
28766 #define APIC_BUS_CYCLE_NS 1
28767
28768 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28769-#define apic_debug(fmt, arg...)
28770+#define apic_debug(fmt, arg...) do {} while (0)
28771
28772 #define APIC_LVT_NUM 6
28773 /* 14 is the version for Xeon and Pentium 8.4.8*/
28774diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28775index fd49c86..77e1aa0 100644
28776--- a/arch/x86/kvm/paging_tmpl.h
28777+++ b/arch/x86/kvm/paging_tmpl.h
28778@@ -343,7 +343,7 @@ retry_walk:
28779 if (unlikely(kvm_is_error_hva(host_addr)))
28780 goto error;
28781
28782- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28783+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28784 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28785 goto error;
28786 walker->ptep_user[walker->level - 1] = ptep_user;
28787diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28788index 7527cef..c63a838e 100644
28789--- a/arch/x86/kvm/svm.c
28790+++ b/arch/x86/kvm/svm.c
28791@@ -3564,7 +3564,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28792 int cpu = raw_smp_processor_id();
28793
28794 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28795+
28796+ pax_open_kernel();
28797 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28798+ pax_close_kernel();
28799+
28800 load_TR_desc();
28801 }
28802
28803@@ -3965,6 +3969,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28804 #endif
28805 #endif
28806
28807+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28808+ __set_fs(current_thread_info()->addr_limit);
28809+#endif
28810+
28811 reload_tss(vcpu);
28812
28813 local_irq_disable();
28814diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28815index 3e556c6..08bbf7f 100644
28816--- a/arch/x86/kvm/vmx.c
28817+++ b/arch/x86/kvm/vmx.c
28818@@ -1366,12 +1366,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28819 #endif
28820 }
28821
28822-static void vmcs_clear_bits(unsigned long field, u32 mask)
28823+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28824 {
28825 vmcs_writel(field, vmcs_readl(field) & ~mask);
28826 }
28827
28828-static void vmcs_set_bits(unsigned long field, u32 mask)
28829+static void vmcs_set_bits(unsigned long field, unsigned long mask)
28830 {
28831 vmcs_writel(field, vmcs_readl(field) | mask);
28832 }
28833@@ -1631,7 +1631,11 @@ static void reload_tss(void)
28834 struct desc_struct *descs;
28835
28836 descs = (void *)gdt->address;
28837+
28838+ pax_open_kernel();
28839 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28840+ pax_close_kernel();
28841+
28842 load_TR_desc();
28843 }
28844
28845@@ -1859,6 +1863,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28846 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28847 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28848
28849+#ifdef CONFIG_PAX_PER_CPU_PGD
28850+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28851+#endif
28852+
28853 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28854 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28855 vmx->loaded_vmcs->cpu = cpu;
28856@@ -2148,7 +2156,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28857 * reads and returns guest's timestamp counter "register"
28858 * guest_tsc = host_tsc + tsc_offset -- 21.3
28859 */
28860-static u64 guest_read_tsc(void)
28861+static u64 __intentional_overflow(-1) guest_read_tsc(void)
28862 {
28863 u64 host_tsc, tsc_offset;
28864
28865@@ -3146,11 +3154,16 @@ static __init int hardware_setup(void)
28866 * page upon invalidation. No need to do anything if the
28867 * processor does not have the APIC_ACCESS_ADDR VMCS field.
28868 */
28869- kvm_x86_ops->set_apic_access_page_addr = NULL;
28870+ pax_open_kernel();
28871+ *(void **)&kvm_x86_ops->set_apic_access_page_addr = NULL;
28872+ pax_close_kernel();
28873 }
28874
28875- if (!cpu_has_vmx_tpr_shadow())
28876- kvm_x86_ops->update_cr8_intercept = NULL;
28877+ if (!cpu_has_vmx_tpr_shadow()) {
28878+ pax_open_kernel();
28879+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28880+ pax_close_kernel();
28881+ }
28882
28883 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28884 kvm_disable_largepages();
28885@@ -3161,13 +3174,15 @@ static __init int hardware_setup(void)
28886 if (!cpu_has_vmx_apicv())
28887 enable_apicv = 0;
28888
28889+ pax_open_kernel();
28890 if (enable_apicv)
28891- kvm_x86_ops->update_cr8_intercept = NULL;
28892+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28893 else {
28894- kvm_x86_ops->hwapic_irr_update = NULL;
28895- kvm_x86_ops->deliver_posted_interrupt = NULL;
28896- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28897+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28898+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28899+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28900 }
28901+ pax_close_kernel();
28902
28903 if (nested)
28904 nested_vmx_setup_ctls_msrs();
28905@@ -4274,7 +4289,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28906 unsigned long cr4;
28907
28908 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28909+
28910+#ifndef CONFIG_PAX_PER_CPU_PGD
28911 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28912+#endif
28913
28914 /* Save the most likely value for this task's CR4 in the VMCS. */
28915 cr4 = read_cr4();
28916@@ -4301,7 +4319,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28917 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28918 vmx->host_idt_base = dt.address;
28919
28920- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28921+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28922
28923 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28924 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28925@@ -7622,6 +7640,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28926 "jmp 2f \n\t"
28927 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28928 "2: "
28929+
28930+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28931+ "ljmp %[cs],$3f\n\t"
28932+ "3: "
28933+#endif
28934+
28935 /* Save guest registers, load host registers, keep flags */
28936 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28937 "pop %0 \n\t"
28938@@ -7674,6 +7698,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28939 #endif
28940 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28941 [wordsize]"i"(sizeof(ulong))
28942+
28943+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28944+ ,[cs]"i"(__KERNEL_CS)
28945+#endif
28946+
28947 : "cc", "memory"
28948 #ifdef CONFIG_X86_64
28949 , "rax", "rbx", "rdi", "rsi"
28950@@ -7687,7 +7716,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28951 if (debugctlmsr)
28952 update_debugctlmsr(debugctlmsr);
28953
28954-#ifndef CONFIG_X86_64
28955+#ifdef CONFIG_X86_32
28956 /*
28957 * The sysexit path does not restore ds/es, so we must set them to
28958 * a reasonable value ourselves.
28959@@ -7696,8 +7725,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28960 * may be executed in interrupt context, which saves and restore segments
28961 * around it, nullifying its effect.
28962 */
28963- loadsegment(ds, __USER_DS);
28964- loadsegment(es, __USER_DS);
28965+ loadsegment(ds, __KERNEL_DS);
28966+ loadsegment(es, __KERNEL_DS);
28967+ loadsegment(ss, __KERNEL_DS);
28968+
28969+#ifdef CONFIG_PAX_KERNEXEC
28970+ loadsegment(fs, __KERNEL_PERCPU);
28971+#endif
28972+
28973+#ifdef CONFIG_PAX_MEMORY_UDEREF
28974+ __set_fs(current_thread_info()->addr_limit);
28975+#endif
28976+
28977 #endif
28978
28979 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28980diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28981index 0033df3..db6236d 100644
28982--- a/arch/x86/kvm/x86.c
28983+++ b/arch/x86/kvm/x86.c
28984@@ -732,6 +732,8 @@ EXPORT_SYMBOL_GPL(kvm_set_cr4);
28985
28986 int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
28987 {
28988+ cr3 &= ~CR3_PCID_INVD;
28989+
28990 if (cr3 == kvm_read_cr3(vcpu) && !pdptrs_changed(vcpu)) {
28991 kvm_mmu_sync_roots(vcpu);
28992 kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu);
28993@@ -1878,8 +1880,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28994 {
28995 struct kvm *kvm = vcpu->kvm;
28996 int lm = is_long_mode(vcpu);
28997- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28998- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28999+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
29000+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
29001 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
29002 : kvm->arch.xen_hvm_config.blob_size_32;
29003 u32 page_num = data & ~PAGE_MASK;
29004@@ -2806,6 +2808,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
29005 if (n < msr_list.nmsrs)
29006 goto out;
29007 r = -EFAULT;
29008+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
29009+ goto out;
29010 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
29011 num_msrs_to_save * sizeof(u32)))
29012 goto out;
29013@@ -5670,7 +5674,7 @@ static struct notifier_block pvclock_gtod_notifier = {
29014 };
29015 #endif
29016
29017-int kvm_arch_init(void *opaque)
29018+int kvm_arch_init(const void *opaque)
29019 {
29020 int r;
29021 struct kvm_x86_ops *ops = opaque;
29022diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
29023index aae9413..d11e829 100644
29024--- a/arch/x86/lguest/boot.c
29025+++ b/arch/x86/lguest/boot.c
29026@@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
29027 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
29028 * Launcher to reboot us.
29029 */
29030-static void lguest_restart(char *reason)
29031+static __noreturn void lguest_restart(char *reason)
29032 {
29033 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
29034+ BUG();
29035 }
29036
29037 /*G:050
29038diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
29039index 00933d5..3a64af9 100644
29040--- a/arch/x86/lib/atomic64_386_32.S
29041+++ b/arch/x86/lib/atomic64_386_32.S
29042@@ -48,6 +48,10 @@ BEGIN(read)
29043 movl (v), %eax
29044 movl 4(v), %edx
29045 RET_ENDP
29046+BEGIN(read_unchecked)
29047+ movl (v), %eax
29048+ movl 4(v), %edx
29049+RET_ENDP
29050 #undef v
29051
29052 #define v %esi
29053@@ -55,6 +59,10 @@ BEGIN(set)
29054 movl %ebx, (v)
29055 movl %ecx, 4(v)
29056 RET_ENDP
29057+BEGIN(set_unchecked)
29058+ movl %ebx, (v)
29059+ movl %ecx, 4(v)
29060+RET_ENDP
29061 #undef v
29062
29063 #define v %esi
29064@@ -70,6 +78,20 @@ RET_ENDP
29065 BEGIN(add)
29066 addl %eax, (v)
29067 adcl %edx, 4(v)
29068+
29069+#ifdef CONFIG_PAX_REFCOUNT
29070+ jno 0f
29071+ subl %eax, (v)
29072+ sbbl %edx, 4(v)
29073+ int $4
29074+0:
29075+ _ASM_EXTABLE(0b, 0b)
29076+#endif
29077+
29078+RET_ENDP
29079+BEGIN(add_unchecked)
29080+ addl %eax, (v)
29081+ adcl %edx, 4(v)
29082 RET_ENDP
29083 #undef v
29084
29085@@ -77,6 +99,24 @@ RET_ENDP
29086 BEGIN(add_return)
29087 addl (v), %eax
29088 adcl 4(v), %edx
29089+
29090+#ifdef CONFIG_PAX_REFCOUNT
29091+ into
29092+1234:
29093+ _ASM_EXTABLE(1234b, 2f)
29094+#endif
29095+
29096+ movl %eax, (v)
29097+ movl %edx, 4(v)
29098+
29099+#ifdef CONFIG_PAX_REFCOUNT
29100+2:
29101+#endif
29102+
29103+RET_ENDP
29104+BEGIN(add_return_unchecked)
29105+ addl (v), %eax
29106+ adcl 4(v), %edx
29107 movl %eax, (v)
29108 movl %edx, 4(v)
29109 RET_ENDP
29110@@ -86,6 +126,20 @@ RET_ENDP
29111 BEGIN(sub)
29112 subl %eax, (v)
29113 sbbl %edx, 4(v)
29114+
29115+#ifdef CONFIG_PAX_REFCOUNT
29116+ jno 0f
29117+ addl %eax, (v)
29118+ adcl %edx, 4(v)
29119+ int $4
29120+0:
29121+ _ASM_EXTABLE(0b, 0b)
29122+#endif
29123+
29124+RET_ENDP
29125+BEGIN(sub_unchecked)
29126+ subl %eax, (v)
29127+ sbbl %edx, 4(v)
29128 RET_ENDP
29129 #undef v
29130
29131@@ -96,6 +150,27 @@ BEGIN(sub_return)
29132 sbbl $0, %edx
29133 addl (v), %eax
29134 adcl 4(v), %edx
29135+
29136+#ifdef CONFIG_PAX_REFCOUNT
29137+ into
29138+1234:
29139+ _ASM_EXTABLE(1234b, 2f)
29140+#endif
29141+
29142+ movl %eax, (v)
29143+ movl %edx, 4(v)
29144+
29145+#ifdef CONFIG_PAX_REFCOUNT
29146+2:
29147+#endif
29148+
29149+RET_ENDP
29150+BEGIN(sub_return_unchecked)
29151+ negl %edx
29152+ negl %eax
29153+ sbbl $0, %edx
29154+ addl (v), %eax
29155+ adcl 4(v), %edx
29156 movl %eax, (v)
29157 movl %edx, 4(v)
29158 RET_ENDP
29159@@ -105,6 +180,20 @@ RET_ENDP
29160 BEGIN(inc)
29161 addl $1, (v)
29162 adcl $0, 4(v)
29163+
29164+#ifdef CONFIG_PAX_REFCOUNT
29165+ jno 0f
29166+ subl $1, (v)
29167+ sbbl $0, 4(v)
29168+ int $4
29169+0:
29170+ _ASM_EXTABLE(0b, 0b)
29171+#endif
29172+
29173+RET_ENDP
29174+BEGIN(inc_unchecked)
29175+ addl $1, (v)
29176+ adcl $0, 4(v)
29177 RET_ENDP
29178 #undef v
29179
29180@@ -114,6 +203,26 @@ BEGIN(inc_return)
29181 movl 4(v), %edx
29182 addl $1, %eax
29183 adcl $0, %edx
29184+
29185+#ifdef CONFIG_PAX_REFCOUNT
29186+ into
29187+1234:
29188+ _ASM_EXTABLE(1234b, 2f)
29189+#endif
29190+
29191+ movl %eax, (v)
29192+ movl %edx, 4(v)
29193+
29194+#ifdef CONFIG_PAX_REFCOUNT
29195+2:
29196+#endif
29197+
29198+RET_ENDP
29199+BEGIN(inc_return_unchecked)
29200+ movl (v), %eax
29201+ movl 4(v), %edx
29202+ addl $1, %eax
29203+ adcl $0, %edx
29204 movl %eax, (v)
29205 movl %edx, 4(v)
29206 RET_ENDP
29207@@ -123,6 +232,20 @@ RET_ENDP
29208 BEGIN(dec)
29209 subl $1, (v)
29210 sbbl $0, 4(v)
29211+
29212+#ifdef CONFIG_PAX_REFCOUNT
29213+ jno 0f
29214+ addl $1, (v)
29215+ adcl $0, 4(v)
29216+ int $4
29217+0:
29218+ _ASM_EXTABLE(0b, 0b)
29219+#endif
29220+
29221+RET_ENDP
29222+BEGIN(dec_unchecked)
29223+ subl $1, (v)
29224+ sbbl $0, 4(v)
29225 RET_ENDP
29226 #undef v
29227
29228@@ -132,6 +255,26 @@ BEGIN(dec_return)
29229 movl 4(v), %edx
29230 subl $1, %eax
29231 sbbl $0, %edx
29232+
29233+#ifdef CONFIG_PAX_REFCOUNT
29234+ into
29235+1234:
29236+ _ASM_EXTABLE(1234b, 2f)
29237+#endif
29238+
29239+ movl %eax, (v)
29240+ movl %edx, 4(v)
29241+
29242+#ifdef CONFIG_PAX_REFCOUNT
29243+2:
29244+#endif
29245+
29246+RET_ENDP
29247+BEGIN(dec_return_unchecked)
29248+ movl (v), %eax
29249+ movl 4(v), %edx
29250+ subl $1, %eax
29251+ sbbl $0, %edx
29252 movl %eax, (v)
29253 movl %edx, 4(v)
29254 RET_ENDP
29255@@ -143,6 +286,13 @@ BEGIN(add_unless)
29256 adcl %edx, %edi
29257 addl (v), %eax
29258 adcl 4(v), %edx
29259+
29260+#ifdef CONFIG_PAX_REFCOUNT
29261+ into
29262+1234:
29263+ _ASM_EXTABLE(1234b, 2f)
29264+#endif
29265+
29266 cmpl %eax, %ecx
29267 je 3f
29268 1:
29269@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
29270 1:
29271 addl $1, %eax
29272 adcl $0, %edx
29273+
29274+#ifdef CONFIG_PAX_REFCOUNT
29275+ into
29276+1234:
29277+ _ASM_EXTABLE(1234b, 2f)
29278+#endif
29279+
29280 movl %eax, (v)
29281 movl %edx, 4(v)
29282 movl $1, %eax
29283@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
29284 movl 4(v), %edx
29285 subl $1, %eax
29286 sbbl $0, %edx
29287+
29288+#ifdef CONFIG_PAX_REFCOUNT
29289+ into
29290+1234:
29291+ _ASM_EXTABLE(1234b, 1f)
29292+#endif
29293+
29294 js 1f
29295 movl %eax, (v)
29296 movl %edx, 4(v)
29297diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
29298index f5cc9eb..51fa319 100644
29299--- a/arch/x86/lib/atomic64_cx8_32.S
29300+++ b/arch/x86/lib/atomic64_cx8_32.S
29301@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
29302 CFI_STARTPROC
29303
29304 read64 %ecx
29305+ pax_force_retaddr
29306 ret
29307 CFI_ENDPROC
29308 ENDPROC(atomic64_read_cx8)
29309
29310+ENTRY(atomic64_read_unchecked_cx8)
29311+ CFI_STARTPROC
29312+
29313+ read64 %ecx
29314+ pax_force_retaddr
29315+ ret
29316+ CFI_ENDPROC
29317+ENDPROC(atomic64_read_unchecked_cx8)
29318+
29319 ENTRY(atomic64_set_cx8)
29320 CFI_STARTPROC
29321
29322@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
29323 cmpxchg8b (%esi)
29324 jne 1b
29325
29326+ pax_force_retaddr
29327 ret
29328 CFI_ENDPROC
29329 ENDPROC(atomic64_set_cx8)
29330
29331+ENTRY(atomic64_set_unchecked_cx8)
29332+ CFI_STARTPROC
29333+
29334+1:
29335+/* we don't need LOCK_PREFIX since aligned 64-bit writes
29336+ * are atomic on 586 and newer */
29337+ cmpxchg8b (%esi)
29338+ jne 1b
29339+
29340+ pax_force_retaddr
29341+ ret
29342+ CFI_ENDPROC
29343+ENDPROC(atomic64_set_unchecked_cx8)
29344+
29345 ENTRY(atomic64_xchg_cx8)
29346 CFI_STARTPROC
29347
29348@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
29349 cmpxchg8b (%esi)
29350 jne 1b
29351
29352+ pax_force_retaddr
29353 ret
29354 CFI_ENDPROC
29355 ENDPROC(atomic64_xchg_cx8)
29356
29357-.macro addsub_return func ins insc
29358-ENTRY(atomic64_\func\()_return_cx8)
29359+.macro addsub_return func ins insc unchecked=""
29360+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29361 CFI_STARTPROC
29362 SAVE ebp
29363 SAVE ebx
29364@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
29365 movl %edx, %ecx
29366 \ins\()l %esi, %ebx
29367 \insc\()l %edi, %ecx
29368+
29369+.ifb \unchecked
29370+#ifdef CONFIG_PAX_REFCOUNT
29371+ into
29372+2:
29373+ _ASM_EXTABLE(2b, 3f)
29374+#endif
29375+.endif
29376+
29377 LOCK_PREFIX
29378 cmpxchg8b (%ebp)
29379 jne 1b
29380-
29381-10:
29382 movl %ebx, %eax
29383 movl %ecx, %edx
29384+
29385+.ifb \unchecked
29386+#ifdef CONFIG_PAX_REFCOUNT
29387+3:
29388+#endif
29389+.endif
29390+
29391 RESTORE edi
29392 RESTORE esi
29393 RESTORE ebx
29394 RESTORE ebp
29395+ pax_force_retaddr
29396 ret
29397 CFI_ENDPROC
29398-ENDPROC(atomic64_\func\()_return_cx8)
29399+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29400 .endm
29401
29402 addsub_return add add adc
29403 addsub_return sub sub sbb
29404+addsub_return add add adc _unchecked
29405+addsub_return sub sub sbb _unchecked
29406
29407-.macro incdec_return func ins insc
29408-ENTRY(atomic64_\func\()_return_cx8)
29409+.macro incdec_return func ins insc unchecked=""
29410+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29411 CFI_STARTPROC
29412 SAVE ebx
29413
29414@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
29415 movl %edx, %ecx
29416 \ins\()l $1, %ebx
29417 \insc\()l $0, %ecx
29418+
29419+.ifb \unchecked
29420+#ifdef CONFIG_PAX_REFCOUNT
29421+ into
29422+2:
29423+ _ASM_EXTABLE(2b, 3f)
29424+#endif
29425+.endif
29426+
29427 LOCK_PREFIX
29428 cmpxchg8b (%esi)
29429 jne 1b
29430
29431-10:
29432 movl %ebx, %eax
29433 movl %ecx, %edx
29434+
29435+.ifb \unchecked
29436+#ifdef CONFIG_PAX_REFCOUNT
29437+3:
29438+#endif
29439+.endif
29440+
29441 RESTORE ebx
29442+ pax_force_retaddr
29443 ret
29444 CFI_ENDPROC
29445-ENDPROC(atomic64_\func\()_return_cx8)
29446+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29447 .endm
29448
29449 incdec_return inc add adc
29450 incdec_return dec sub sbb
29451+incdec_return inc add adc _unchecked
29452+incdec_return dec sub sbb _unchecked
29453
29454 ENTRY(atomic64_dec_if_positive_cx8)
29455 CFI_STARTPROC
29456@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
29457 movl %edx, %ecx
29458 subl $1, %ebx
29459 sbb $0, %ecx
29460+
29461+#ifdef CONFIG_PAX_REFCOUNT
29462+ into
29463+1234:
29464+ _ASM_EXTABLE(1234b, 2f)
29465+#endif
29466+
29467 js 2f
29468 LOCK_PREFIX
29469 cmpxchg8b (%esi)
29470@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
29471 movl %ebx, %eax
29472 movl %ecx, %edx
29473 RESTORE ebx
29474+ pax_force_retaddr
29475 ret
29476 CFI_ENDPROC
29477 ENDPROC(atomic64_dec_if_positive_cx8)
29478@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
29479 movl %edx, %ecx
29480 addl %ebp, %ebx
29481 adcl %edi, %ecx
29482+
29483+#ifdef CONFIG_PAX_REFCOUNT
29484+ into
29485+1234:
29486+ _ASM_EXTABLE(1234b, 3f)
29487+#endif
29488+
29489 LOCK_PREFIX
29490 cmpxchg8b (%esi)
29491 jne 1b
29492@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
29493 CFI_ADJUST_CFA_OFFSET -8
29494 RESTORE ebx
29495 RESTORE ebp
29496+ pax_force_retaddr
29497 ret
29498 4:
29499 cmpl %edx, 4(%esp)
29500@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
29501 xorl %ecx, %ecx
29502 addl $1, %ebx
29503 adcl %edx, %ecx
29504+
29505+#ifdef CONFIG_PAX_REFCOUNT
29506+ into
29507+1234:
29508+ _ASM_EXTABLE(1234b, 3f)
29509+#endif
29510+
29511 LOCK_PREFIX
29512 cmpxchg8b (%esi)
29513 jne 1b
29514@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
29515 movl $1, %eax
29516 3:
29517 RESTORE ebx
29518+ pax_force_retaddr
29519 ret
29520 CFI_ENDPROC
29521 ENDPROC(atomic64_inc_not_zero_cx8)
29522diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
29523index e78b8eee..7e173a8 100644
29524--- a/arch/x86/lib/checksum_32.S
29525+++ b/arch/x86/lib/checksum_32.S
29526@@ -29,7 +29,8 @@
29527 #include <asm/dwarf2.h>
29528 #include <asm/errno.h>
29529 #include <asm/asm.h>
29530-
29531+#include <asm/segment.h>
29532+
29533 /*
29534 * computes a partial checksum, e.g. for TCP/UDP fragments
29535 */
29536@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
29537
29538 #define ARGBASE 16
29539 #define FP 12
29540-
29541-ENTRY(csum_partial_copy_generic)
29542+
29543+ENTRY(csum_partial_copy_generic_to_user)
29544 CFI_STARTPROC
29545+
29546+#ifdef CONFIG_PAX_MEMORY_UDEREF
29547+ pushl_cfi %gs
29548+ popl_cfi %es
29549+ jmp csum_partial_copy_generic
29550+#endif
29551+
29552+ENTRY(csum_partial_copy_generic_from_user)
29553+
29554+#ifdef CONFIG_PAX_MEMORY_UDEREF
29555+ pushl_cfi %gs
29556+ popl_cfi %ds
29557+#endif
29558+
29559+ENTRY(csum_partial_copy_generic)
29560 subl $4,%esp
29561 CFI_ADJUST_CFA_OFFSET 4
29562 pushl_cfi %edi
29563@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
29564 jmp 4f
29565 SRC(1: movw (%esi), %bx )
29566 addl $2, %esi
29567-DST( movw %bx, (%edi) )
29568+DST( movw %bx, %es:(%edi) )
29569 addl $2, %edi
29570 addw %bx, %ax
29571 adcl $0, %eax
29572@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
29573 SRC(1: movl (%esi), %ebx )
29574 SRC( movl 4(%esi), %edx )
29575 adcl %ebx, %eax
29576-DST( movl %ebx, (%edi) )
29577+DST( movl %ebx, %es:(%edi) )
29578 adcl %edx, %eax
29579-DST( movl %edx, 4(%edi) )
29580+DST( movl %edx, %es:4(%edi) )
29581
29582 SRC( movl 8(%esi), %ebx )
29583 SRC( movl 12(%esi), %edx )
29584 adcl %ebx, %eax
29585-DST( movl %ebx, 8(%edi) )
29586+DST( movl %ebx, %es:8(%edi) )
29587 adcl %edx, %eax
29588-DST( movl %edx, 12(%edi) )
29589+DST( movl %edx, %es:12(%edi) )
29590
29591 SRC( movl 16(%esi), %ebx )
29592 SRC( movl 20(%esi), %edx )
29593 adcl %ebx, %eax
29594-DST( movl %ebx, 16(%edi) )
29595+DST( movl %ebx, %es:16(%edi) )
29596 adcl %edx, %eax
29597-DST( movl %edx, 20(%edi) )
29598+DST( movl %edx, %es:20(%edi) )
29599
29600 SRC( movl 24(%esi), %ebx )
29601 SRC( movl 28(%esi), %edx )
29602 adcl %ebx, %eax
29603-DST( movl %ebx, 24(%edi) )
29604+DST( movl %ebx, %es:24(%edi) )
29605 adcl %edx, %eax
29606-DST( movl %edx, 28(%edi) )
29607+DST( movl %edx, %es:28(%edi) )
29608
29609 lea 32(%esi), %esi
29610 lea 32(%edi), %edi
29611@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
29612 shrl $2, %edx # This clears CF
29613 SRC(3: movl (%esi), %ebx )
29614 adcl %ebx, %eax
29615-DST( movl %ebx, (%edi) )
29616+DST( movl %ebx, %es:(%edi) )
29617 lea 4(%esi), %esi
29618 lea 4(%edi), %edi
29619 dec %edx
29620@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
29621 jb 5f
29622 SRC( movw (%esi), %cx )
29623 leal 2(%esi), %esi
29624-DST( movw %cx, (%edi) )
29625+DST( movw %cx, %es:(%edi) )
29626 leal 2(%edi), %edi
29627 je 6f
29628 shll $16,%ecx
29629 SRC(5: movb (%esi), %cl )
29630-DST( movb %cl, (%edi) )
29631+DST( movb %cl, %es:(%edi) )
29632 6: addl %ecx, %eax
29633 adcl $0, %eax
29634 7:
29635@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
29636
29637 6001:
29638 movl ARGBASE+20(%esp), %ebx # src_err_ptr
29639- movl $-EFAULT, (%ebx)
29640+ movl $-EFAULT, %ss:(%ebx)
29641
29642 # zero the complete destination - computing the rest
29643 # is too much work
29644@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
29645
29646 6002:
29647 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29648- movl $-EFAULT,(%ebx)
29649+ movl $-EFAULT,%ss:(%ebx)
29650 jmp 5000b
29651
29652 .previous
29653
29654+ pushl_cfi %ss
29655+ popl_cfi %ds
29656+ pushl_cfi %ss
29657+ popl_cfi %es
29658 popl_cfi %ebx
29659 CFI_RESTORE ebx
29660 popl_cfi %esi
29661@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
29662 popl_cfi %ecx # equivalent to addl $4,%esp
29663 ret
29664 CFI_ENDPROC
29665-ENDPROC(csum_partial_copy_generic)
29666+ENDPROC(csum_partial_copy_generic_to_user)
29667
29668 #else
29669
29670 /* Version for PentiumII/PPro */
29671
29672 #define ROUND1(x) \
29673+ nop; nop; nop; \
29674 SRC(movl x(%esi), %ebx ) ; \
29675 addl %ebx, %eax ; \
29676- DST(movl %ebx, x(%edi) ) ;
29677+ DST(movl %ebx, %es:x(%edi)) ;
29678
29679 #define ROUND(x) \
29680+ nop; nop; nop; \
29681 SRC(movl x(%esi), %ebx ) ; \
29682 adcl %ebx, %eax ; \
29683- DST(movl %ebx, x(%edi) ) ;
29684+ DST(movl %ebx, %es:x(%edi)) ;
29685
29686 #define ARGBASE 12
29687-
29688-ENTRY(csum_partial_copy_generic)
29689+
29690+ENTRY(csum_partial_copy_generic_to_user)
29691 CFI_STARTPROC
29692+
29693+#ifdef CONFIG_PAX_MEMORY_UDEREF
29694+ pushl_cfi %gs
29695+ popl_cfi %es
29696+ jmp csum_partial_copy_generic
29697+#endif
29698+
29699+ENTRY(csum_partial_copy_generic_from_user)
29700+
29701+#ifdef CONFIG_PAX_MEMORY_UDEREF
29702+ pushl_cfi %gs
29703+ popl_cfi %ds
29704+#endif
29705+
29706+ENTRY(csum_partial_copy_generic)
29707 pushl_cfi %ebx
29708 CFI_REL_OFFSET ebx, 0
29709 pushl_cfi %edi
29710@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29711 subl %ebx, %edi
29712 lea -1(%esi),%edx
29713 andl $-32,%edx
29714- lea 3f(%ebx,%ebx), %ebx
29715+ lea 3f(%ebx,%ebx,2), %ebx
29716 testl %esi, %esi
29717 jmp *%ebx
29718 1: addl $64,%esi
29719@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29720 jb 5f
29721 SRC( movw (%esi), %dx )
29722 leal 2(%esi), %esi
29723-DST( movw %dx, (%edi) )
29724+DST( movw %dx, %es:(%edi) )
29725 leal 2(%edi), %edi
29726 je 6f
29727 shll $16,%edx
29728 5:
29729 SRC( movb (%esi), %dl )
29730-DST( movb %dl, (%edi) )
29731+DST( movb %dl, %es:(%edi) )
29732 6: addl %edx, %eax
29733 adcl $0, %eax
29734 7:
29735 .section .fixup, "ax"
29736 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29737- movl $-EFAULT, (%ebx)
29738+ movl $-EFAULT, %ss:(%ebx)
29739 # zero the complete destination (computing the rest is too much work)
29740 movl ARGBASE+8(%esp),%edi # dst
29741 movl ARGBASE+12(%esp),%ecx # len
29742@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29743 rep; stosb
29744 jmp 7b
29745 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29746- movl $-EFAULT, (%ebx)
29747+ movl $-EFAULT, %ss:(%ebx)
29748 jmp 7b
29749 .previous
29750
29751+#ifdef CONFIG_PAX_MEMORY_UDEREF
29752+ pushl_cfi %ss
29753+ popl_cfi %ds
29754+ pushl_cfi %ss
29755+ popl_cfi %es
29756+#endif
29757+
29758 popl_cfi %esi
29759 CFI_RESTORE esi
29760 popl_cfi %edi
29761@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29762 CFI_RESTORE ebx
29763 ret
29764 CFI_ENDPROC
29765-ENDPROC(csum_partial_copy_generic)
29766+ENDPROC(csum_partial_copy_generic_to_user)
29767
29768 #undef ROUND
29769 #undef ROUND1
29770diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29771index f2145cf..cea889d 100644
29772--- a/arch/x86/lib/clear_page_64.S
29773+++ b/arch/x86/lib/clear_page_64.S
29774@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29775 movl $4096/8,%ecx
29776 xorl %eax,%eax
29777 rep stosq
29778+ pax_force_retaddr
29779 ret
29780 CFI_ENDPROC
29781 ENDPROC(clear_page_c)
29782@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29783 movl $4096,%ecx
29784 xorl %eax,%eax
29785 rep stosb
29786+ pax_force_retaddr
29787 ret
29788 CFI_ENDPROC
29789 ENDPROC(clear_page_c_e)
29790@@ -43,6 +45,7 @@ ENTRY(clear_page)
29791 leaq 64(%rdi),%rdi
29792 jnz .Lloop
29793 nop
29794+ pax_force_retaddr
29795 ret
29796 CFI_ENDPROC
29797 .Lclear_page_end:
29798@@ -58,7 +61,7 @@ ENDPROC(clear_page)
29799
29800 #include <asm/cpufeature.h>
29801
29802- .section .altinstr_replacement,"ax"
29803+ .section .altinstr_replacement,"a"
29804 1: .byte 0xeb /* jmp <disp8> */
29805 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29806 2: .byte 0xeb /* jmp <disp8> */
29807diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29808index 40a1725..5d12ac4 100644
29809--- a/arch/x86/lib/cmpxchg16b_emu.S
29810+++ b/arch/x86/lib/cmpxchg16b_emu.S
29811@@ -8,6 +8,7 @@
29812 #include <linux/linkage.h>
29813 #include <asm/dwarf2.h>
29814 #include <asm/percpu.h>
29815+#include <asm/alternative-asm.h>
29816
29817 .text
29818
29819@@ -46,12 +47,14 @@ CFI_STARTPROC
29820 CFI_REMEMBER_STATE
29821 popfq_cfi
29822 mov $1, %al
29823+ pax_force_retaddr
29824 ret
29825
29826 CFI_RESTORE_STATE
29827 .Lnot_same:
29828 popfq_cfi
29829 xor %al,%al
29830+ pax_force_retaddr
29831 ret
29832
29833 CFI_ENDPROC
29834diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29835index 176cca6..e0d658e 100644
29836--- a/arch/x86/lib/copy_page_64.S
29837+++ b/arch/x86/lib/copy_page_64.S
29838@@ -9,6 +9,7 @@ copy_page_rep:
29839 CFI_STARTPROC
29840 movl $4096/8, %ecx
29841 rep movsq
29842+ pax_force_retaddr
29843 ret
29844 CFI_ENDPROC
29845 ENDPROC(copy_page_rep)
29846@@ -24,8 +25,8 @@ ENTRY(copy_page)
29847 CFI_ADJUST_CFA_OFFSET 2*8
29848 movq %rbx, (%rsp)
29849 CFI_REL_OFFSET rbx, 0
29850- movq %r12, 1*8(%rsp)
29851- CFI_REL_OFFSET r12, 1*8
29852+ movq %r13, 1*8(%rsp)
29853+ CFI_REL_OFFSET r13, 1*8
29854
29855 movl $(4096/64)-5, %ecx
29856 .p2align 4
29857@@ -38,7 +39,7 @@ ENTRY(copy_page)
29858 movq 0x8*4(%rsi), %r9
29859 movq 0x8*5(%rsi), %r10
29860 movq 0x8*6(%rsi), %r11
29861- movq 0x8*7(%rsi), %r12
29862+ movq 0x8*7(%rsi), %r13
29863
29864 prefetcht0 5*64(%rsi)
29865
29866@@ -49,7 +50,7 @@ ENTRY(copy_page)
29867 movq %r9, 0x8*4(%rdi)
29868 movq %r10, 0x8*5(%rdi)
29869 movq %r11, 0x8*6(%rdi)
29870- movq %r12, 0x8*7(%rdi)
29871+ movq %r13, 0x8*7(%rdi)
29872
29873 leaq 64 (%rsi), %rsi
29874 leaq 64 (%rdi), %rdi
29875@@ -68,7 +69,7 @@ ENTRY(copy_page)
29876 movq 0x8*4(%rsi), %r9
29877 movq 0x8*5(%rsi), %r10
29878 movq 0x8*6(%rsi), %r11
29879- movq 0x8*7(%rsi), %r12
29880+ movq 0x8*7(%rsi), %r13
29881
29882 movq %rax, 0x8*0(%rdi)
29883 movq %rbx, 0x8*1(%rdi)
29884@@ -77,7 +78,7 @@ ENTRY(copy_page)
29885 movq %r9, 0x8*4(%rdi)
29886 movq %r10, 0x8*5(%rdi)
29887 movq %r11, 0x8*6(%rdi)
29888- movq %r12, 0x8*7(%rdi)
29889+ movq %r13, 0x8*7(%rdi)
29890
29891 leaq 64(%rdi), %rdi
29892 leaq 64(%rsi), %rsi
29893@@ -85,10 +86,11 @@ ENTRY(copy_page)
29894
29895 movq (%rsp), %rbx
29896 CFI_RESTORE rbx
29897- movq 1*8(%rsp), %r12
29898- CFI_RESTORE r12
29899+ movq 1*8(%rsp), %r13
29900+ CFI_RESTORE r13
29901 addq $2*8, %rsp
29902 CFI_ADJUST_CFA_OFFSET -2*8
29903+ pax_force_retaddr
29904 ret
29905 .Lcopy_page_end:
29906 CFI_ENDPROC
29907@@ -99,7 +101,7 @@ ENDPROC(copy_page)
29908
29909 #include <asm/cpufeature.h>
29910
29911- .section .altinstr_replacement,"ax"
29912+ .section .altinstr_replacement,"a"
29913 1: .byte 0xeb /* jmp <disp8> */
29914 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29915 2:
29916diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29917index dee945d..a84067b 100644
29918--- a/arch/x86/lib/copy_user_64.S
29919+++ b/arch/x86/lib/copy_user_64.S
29920@@ -18,31 +18,7 @@
29921 #include <asm/alternative-asm.h>
29922 #include <asm/asm.h>
29923 #include <asm/smap.h>
29924-
29925-/*
29926- * By placing feature2 after feature1 in altinstructions section, we logically
29927- * implement:
29928- * If CPU has feature2, jmp to alt2 is used
29929- * else if CPU has feature1, jmp to alt1 is used
29930- * else jmp to orig is used.
29931- */
29932- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29933-0:
29934- .byte 0xe9 /* 32bit jump */
29935- .long \orig-1f /* by default jump to orig */
29936-1:
29937- .section .altinstr_replacement,"ax"
29938-2: .byte 0xe9 /* near jump with 32bit immediate */
29939- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29940-3: .byte 0xe9 /* near jump with 32bit immediate */
29941- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29942- .previous
29943-
29944- .section .altinstructions,"a"
29945- altinstruction_entry 0b,2b,\feature1,5,5
29946- altinstruction_entry 0b,3b,\feature2,5,5
29947- .previous
29948- .endm
29949+#include <asm/pgtable.h>
29950
29951 .macro ALIGN_DESTINATION
29952 #ifdef FIX_ALIGNMENT
29953@@ -70,52 +46,6 @@
29954 #endif
29955 .endm
29956
29957-/* Standard copy_to_user with segment limit checking */
29958-ENTRY(_copy_to_user)
29959- CFI_STARTPROC
29960- GET_THREAD_INFO(%rax)
29961- movq %rdi,%rcx
29962- addq %rdx,%rcx
29963- jc bad_to_user
29964- cmpq TI_addr_limit(%rax),%rcx
29965- ja bad_to_user
29966- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29967- copy_user_generic_unrolled,copy_user_generic_string, \
29968- copy_user_enhanced_fast_string
29969- CFI_ENDPROC
29970-ENDPROC(_copy_to_user)
29971-
29972-/* Standard copy_from_user with segment limit checking */
29973-ENTRY(_copy_from_user)
29974- CFI_STARTPROC
29975- GET_THREAD_INFO(%rax)
29976- movq %rsi,%rcx
29977- addq %rdx,%rcx
29978- jc bad_from_user
29979- cmpq TI_addr_limit(%rax),%rcx
29980- ja bad_from_user
29981- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29982- copy_user_generic_unrolled,copy_user_generic_string, \
29983- copy_user_enhanced_fast_string
29984- CFI_ENDPROC
29985-ENDPROC(_copy_from_user)
29986-
29987- .section .fixup,"ax"
29988- /* must zero dest */
29989-ENTRY(bad_from_user)
29990-bad_from_user:
29991- CFI_STARTPROC
29992- movl %edx,%ecx
29993- xorl %eax,%eax
29994- rep
29995- stosb
29996-bad_to_user:
29997- movl %edx,%eax
29998- ret
29999- CFI_ENDPROC
30000-ENDPROC(bad_from_user)
30001- .previous
30002-
30003 /*
30004 * copy_user_generic_unrolled - memory copy with exception handling.
30005 * This version is for CPUs like P4 that don't have efficient micro
30006@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
30007 */
30008 ENTRY(copy_user_generic_unrolled)
30009 CFI_STARTPROC
30010+ ASM_PAX_OPEN_USERLAND
30011 ASM_STAC
30012 cmpl $8,%edx
30013 jb 20f /* less then 8 bytes, go to byte copy loop */
30014@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
30015 jnz 21b
30016 23: xor %eax,%eax
30017 ASM_CLAC
30018+ ASM_PAX_CLOSE_USERLAND
30019+ pax_force_retaddr
30020 ret
30021
30022 .section .fixup,"ax"
30023@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
30024 */
30025 ENTRY(copy_user_generic_string)
30026 CFI_STARTPROC
30027+ ASM_PAX_OPEN_USERLAND
30028 ASM_STAC
30029 cmpl $8,%edx
30030 jb 2f /* less than 8 bytes, go to byte copy loop */
30031@@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
30032 movsb
30033 xorl %eax,%eax
30034 ASM_CLAC
30035+ ASM_PAX_CLOSE_USERLAND
30036+ pax_force_retaddr
30037 ret
30038
30039 .section .fixup,"ax"
30040@@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
30041 */
30042 ENTRY(copy_user_enhanced_fast_string)
30043 CFI_STARTPROC
30044+ ASM_PAX_OPEN_USERLAND
30045 ASM_STAC
30046 movl %edx,%ecx
30047 1: rep
30048 movsb
30049 xorl %eax,%eax
30050 ASM_CLAC
30051+ ASM_PAX_CLOSE_USERLAND
30052+ pax_force_retaddr
30053 ret
30054
30055 .section .fixup,"ax"
30056diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
30057index 6a4f43c..c70fb52 100644
30058--- a/arch/x86/lib/copy_user_nocache_64.S
30059+++ b/arch/x86/lib/copy_user_nocache_64.S
30060@@ -8,6 +8,7 @@
30061
30062 #include <linux/linkage.h>
30063 #include <asm/dwarf2.h>
30064+#include <asm/alternative-asm.h>
30065
30066 #define FIX_ALIGNMENT 1
30067
30068@@ -16,6 +17,7 @@
30069 #include <asm/thread_info.h>
30070 #include <asm/asm.h>
30071 #include <asm/smap.h>
30072+#include <asm/pgtable.h>
30073
30074 .macro ALIGN_DESTINATION
30075 #ifdef FIX_ALIGNMENT
30076@@ -49,6 +51,16 @@
30077 */
30078 ENTRY(__copy_user_nocache)
30079 CFI_STARTPROC
30080+
30081+#ifdef CONFIG_PAX_MEMORY_UDEREF
30082+ mov pax_user_shadow_base,%rcx
30083+ cmp %rcx,%rsi
30084+ jae 1f
30085+ add %rcx,%rsi
30086+1:
30087+#endif
30088+
30089+ ASM_PAX_OPEN_USERLAND
30090 ASM_STAC
30091 cmpl $8,%edx
30092 jb 20f /* less then 8 bytes, go to byte copy loop */
30093@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
30094 jnz 21b
30095 23: xorl %eax,%eax
30096 ASM_CLAC
30097+ ASM_PAX_CLOSE_USERLAND
30098 sfence
30099+ pax_force_retaddr
30100 ret
30101
30102 .section .fixup,"ax"
30103diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
30104index 2419d5f..fe52d0e 100644
30105--- a/arch/x86/lib/csum-copy_64.S
30106+++ b/arch/x86/lib/csum-copy_64.S
30107@@ -9,6 +9,7 @@
30108 #include <asm/dwarf2.h>
30109 #include <asm/errno.h>
30110 #include <asm/asm.h>
30111+#include <asm/alternative-asm.h>
30112
30113 /*
30114 * Checksum copy with exception handling.
30115@@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
30116 CFI_ADJUST_CFA_OFFSET 7*8
30117 movq %rbx, 2*8(%rsp)
30118 CFI_REL_OFFSET rbx, 2*8
30119- movq %r12, 3*8(%rsp)
30120- CFI_REL_OFFSET r12, 3*8
30121+ movq %r15, 3*8(%rsp)
30122+ CFI_REL_OFFSET r15, 3*8
30123 movq %r14, 4*8(%rsp)
30124 CFI_REL_OFFSET r14, 4*8
30125 movq %r13, 5*8(%rsp)
30126@@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
30127 movl %edx, %ecx
30128
30129 xorl %r9d, %r9d
30130- movq %rcx, %r12
30131+ movq %rcx, %r15
30132
30133- shrq $6, %r12
30134+ shrq $6, %r15
30135 jz .Lhandle_tail /* < 64 */
30136
30137 clc
30138
30139 /* main loop. clear in 64 byte blocks */
30140 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
30141- /* r11: temp3, rdx: temp4, r12 loopcnt */
30142+ /* r11: temp3, rdx: temp4, r15 loopcnt */
30143 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
30144 .p2align 4
30145 .Lloop:
30146@@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
30147 adcq %r14, %rax
30148 adcq %r13, %rax
30149
30150- decl %r12d
30151+ decl %r15d
30152
30153 dest
30154 movq %rbx, (%rsi)
30155@@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
30156 .Lende:
30157 movq 2*8(%rsp), %rbx
30158 CFI_RESTORE rbx
30159- movq 3*8(%rsp), %r12
30160- CFI_RESTORE r12
30161+ movq 3*8(%rsp), %r15
30162+ CFI_RESTORE r15
30163 movq 4*8(%rsp), %r14
30164 CFI_RESTORE r14
30165 movq 5*8(%rsp), %r13
30166@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
30167 CFI_RESTORE rbp
30168 addq $7*8, %rsp
30169 CFI_ADJUST_CFA_OFFSET -7*8
30170+ pax_force_retaddr
30171 ret
30172 CFI_RESTORE_STATE
30173
30174diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
30175index 1318f75..44c30fd 100644
30176--- a/arch/x86/lib/csum-wrappers_64.c
30177+++ b/arch/x86/lib/csum-wrappers_64.c
30178@@ -52,10 +52,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
30179 len -= 2;
30180 }
30181 }
30182+ pax_open_userland();
30183 stac();
30184- isum = csum_partial_copy_generic((__force const void *)src,
30185+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
30186 dst, len, isum, errp, NULL);
30187 clac();
30188+ pax_close_userland();
30189 if (unlikely(*errp))
30190 goto out_err;
30191
30192@@ -109,10 +111,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
30193 }
30194
30195 *errp = 0;
30196+ pax_open_userland();
30197 stac();
30198- ret = csum_partial_copy_generic(src, (void __force *)dst,
30199+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
30200 len, isum, NULL, errp);
30201 clac();
30202+ pax_close_userland();
30203 return ret;
30204 }
30205 EXPORT_SYMBOL(csum_partial_copy_to_user);
30206diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
30207index a451235..1daa956 100644
30208--- a/arch/x86/lib/getuser.S
30209+++ b/arch/x86/lib/getuser.S
30210@@ -33,17 +33,40 @@
30211 #include <asm/thread_info.h>
30212 #include <asm/asm.h>
30213 #include <asm/smap.h>
30214+#include <asm/segment.h>
30215+#include <asm/pgtable.h>
30216+#include <asm/alternative-asm.h>
30217+
30218+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30219+#define __copyuser_seg gs;
30220+#else
30221+#define __copyuser_seg
30222+#endif
30223
30224 .text
30225 ENTRY(__get_user_1)
30226 CFI_STARTPROC
30227+
30228+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30229 GET_THREAD_INFO(%_ASM_DX)
30230 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30231 jae bad_get_user
30232 ASM_STAC
30233-1: movzbl (%_ASM_AX),%edx
30234+
30235+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30236+ mov pax_user_shadow_base,%_ASM_DX
30237+ cmp %_ASM_DX,%_ASM_AX
30238+ jae 1234f
30239+ add %_ASM_DX,%_ASM_AX
30240+1234:
30241+#endif
30242+
30243+#endif
30244+
30245+1: __copyuser_seg movzbl (%_ASM_AX),%edx
30246 xor %eax,%eax
30247 ASM_CLAC
30248+ pax_force_retaddr
30249 ret
30250 CFI_ENDPROC
30251 ENDPROC(__get_user_1)
30252@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
30253 ENTRY(__get_user_2)
30254 CFI_STARTPROC
30255 add $1,%_ASM_AX
30256+
30257+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30258 jc bad_get_user
30259 GET_THREAD_INFO(%_ASM_DX)
30260 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30261 jae bad_get_user
30262 ASM_STAC
30263-2: movzwl -1(%_ASM_AX),%edx
30264+
30265+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30266+ mov pax_user_shadow_base,%_ASM_DX
30267+ cmp %_ASM_DX,%_ASM_AX
30268+ jae 1234f
30269+ add %_ASM_DX,%_ASM_AX
30270+1234:
30271+#endif
30272+
30273+#endif
30274+
30275+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
30276 xor %eax,%eax
30277 ASM_CLAC
30278+ pax_force_retaddr
30279 ret
30280 CFI_ENDPROC
30281 ENDPROC(__get_user_2)
30282@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
30283 ENTRY(__get_user_4)
30284 CFI_STARTPROC
30285 add $3,%_ASM_AX
30286+
30287+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30288 jc bad_get_user
30289 GET_THREAD_INFO(%_ASM_DX)
30290 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30291 jae bad_get_user
30292 ASM_STAC
30293-3: movl -3(%_ASM_AX),%edx
30294+
30295+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30296+ mov pax_user_shadow_base,%_ASM_DX
30297+ cmp %_ASM_DX,%_ASM_AX
30298+ jae 1234f
30299+ add %_ASM_DX,%_ASM_AX
30300+1234:
30301+#endif
30302+
30303+#endif
30304+
30305+3: __copyuser_seg movl -3(%_ASM_AX),%edx
30306 xor %eax,%eax
30307 ASM_CLAC
30308+ pax_force_retaddr
30309 ret
30310 CFI_ENDPROC
30311 ENDPROC(__get_user_4)
30312@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
30313 GET_THREAD_INFO(%_ASM_DX)
30314 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30315 jae bad_get_user
30316+
30317+#ifdef CONFIG_PAX_MEMORY_UDEREF
30318+ mov pax_user_shadow_base,%_ASM_DX
30319+ cmp %_ASM_DX,%_ASM_AX
30320+ jae 1234f
30321+ add %_ASM_DX,%_ASM_AX
30322+1234:
30323+#endif
30324+
30325 ASM_STAC
30326 4: movq -7(%_ASM_AX),%rdx
30327 xor %eax,%eax
30328 ASM_CLAC
30329+ pax_force_retaddr
30330 ret
30331 #else
30332 add $7,%_ASM_AX
30333@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
30334 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30335 jae bad_get_user_8
30336 ASM_STAC
30337-4: movl -7(%_ASM_AX),%edx
30338-5: movl -3(%_ASM_AX),%ecx
30339+4: __copyuser_seg movl -7(%_ASM_AX),%edx
30340+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
30341 xor %eax,%eax
30342 ASM_CLAC
30343+ pax_force_retaddr
30344 ret
30345 #endif
30346 CFI_ENDPROC
30347@@ -113,6 +175,7 @@ bad_get_user:
30348 xor %edx,%edx
30349 mov $(-EFAULT),%_ASM_AX
30350 ASM_CLAC
30351+ pax_force_retaddr
30352 ret
30353 CFI_ENDPROC
30354 END(bad_get_user)
30355@@ -124,6 +187,7 @@ bad_get_user_8:
30356 xor %ecx,%ecx
30357 mov $(-EFAULT),%_ASM_AX
30358 ASM_CLAC
30359+ pax_force_retaddr
30360 ret
30361 CFI_ENDPROC
30362 END(bad_get_user_8)
30363diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
30364index 54fcffe..7be149e 100644
30365--- a/arch/x86/lib/insn.c
30366+++ b/arch/x86/lib/insn.c
30367@@ -20,8 +20,10 @@
30368
30369 #ifdef __KERNEL__
30370 #include <linux/string.h>
30371+#include <asm/pgtable_types.h>
30372 #else
30373 #include <string.h>
30374+#define ktla_ktva(addr) addr
30375 #endif
30376 #include <asm/inat.h>
30377 #include <asm/insn.h>
30378@@ -53,8 +55,8 @@
30379 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
30380 {
30381 memset(insn, 0, sizeof(*insn));
30382- insn->kaddr = kaddr;
30383- insn->next_byte = kaddr;
30384+ insn->kaddr = ktla_ktva(kaddr);
30385+ insn->next_byte = ktla_ktva(kaddr);
30386 insn->x86_64 = x86_64 ? 1 : 0;
30387 insn->opnd_bytes = 4;
30388 if (x86_64)
30389diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
30390index 05a95e7..326f2fa 100644
30391--- a/arch/x86/lib/iomap_copy_64.S
30392+++ b/arch/x86/lib/iomap_copy_64.S
30393@@ -17,6 +17,7 @@
30394
30395 #include <linux/linkage.h>
30396 #include <asm/dwarf2.h>
30397+#include <asm/alternative-asm.h>
30398
30399 /*
30400 * override generic version in lib/iomap_copy.c
30401@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
30402 CFI_STARTPROC
30403 movl %edx,%ecx
30404 rep movsd
30405+ pax_force_retaddr
30406 ret
30407 CFI_ENDPROC
30408 ENDPROC(__iowrite32_copy)
30409diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
30410index 56313a3..0db417e 100644
30411--- a/arch/x86/lib/memcpy_64.S
30412+++ b/arch/x86/lib/memcpy_64.S
30413@@ -24,7 +24,7 @@
30414 * This gets patched over the unrolled variant (below) via the
30415 * alternative instructions framework:
30416 */
30417- .section .altinstr_replacement, "ax", @progbits
30418+ .section .altinstr_replacement, "a", @progbits
30419 .Lmemcpy_c:
30420 movq %rdi, %rax
30421 movq %rdx, %rcx
30422@@ -33,6 +33,7 @@
30423 rep movsq
30424 movl %edx, %ecx
30425 rep movsb
30426+ pax_force_retaddr
30427 ret
30428 .Lmemcpy_e:
30429 .previous
30430@@ -44,11 +45,12 @@
30431 * This gets patched over the unrolled variant (below) via the
30432 * alternative instructions framework:
30433 */
30434- .section .altinstr_replacement, "ax", @progbits
30435+ .section .altinstr_replacement, "a", @progbits
30436 .Lmemcpy_c_e:
30437 movq %rdi, %rax
30438 movq %rdx, %rcx
30439 rep movsb
30440+ pax_force_retaddr
30441 ret
30442 .Lmemcpy_e_e:
30443 .previous
30444@@ -136,6 +138,7 @@ ENTRY(memcpy)
30445 movq %r9, 1*8(%rdi)
30446 movq %r10, -2*8(%rdi, %rdx)
30447 movq %r11, -1*8(%rdi, %rdx)
30448+ pax_force_retaddr
30449 retq
30450 .p2align 4
30451 .Lless_16bytes:
30452@@ -148,6 +151,7 @@ ENTRY(memcpy)
30453 movq -1*8(%rsi, %rdx), %r9
30454 movq %r8, 0*8(%rdi)
30455 movq %r9, -1*8(%rdi, %rdx)
30456+ pax_force_retaddr
30457 retq
30458 .p2align 4
30459 .Lless_8bytes:
30460@@ -161,6 +165,7 @@ ENTRY(memcpy)
30461 movl -4(%rsi, %rdx), %r8d
30462 movl %ecx, (%rdi)
30463 movl %r8d, -4(%rdi, %rdx)
30464+ pax_force_retaddr
30465 retq
30466 .p2align 4
30467 .Lless_3bytes:
30468@@ -179,6 +184,7 @@ ENTRY(memcpy)
30469 movb %cl, (%rdi)
30470
30471 .Lend:
30472+ pax_force_retaddr
30473 retq
30474 CFI_ENDPROC
30475 ENDPROC(memcpy)
30476diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
30477index 65268a6..dd1de11 100644
30478--- a/arch/x86/lib/memmove_64.S
30479+++ b/arch/x86/lib/memmove_64.S
30480@@ -202,14 +202,16 @@ ENTRY(memmove)
30481 movb (%rsi), %r11b
30482 movb %r11b, (%rdi)
30483 13:
30484+ pax_force_retaddr
30485 retq
30486 CFI_ENDPROC
30487
30488- .section .altinstr_replacement,"ax"
30489+ .section .altinstr_replacement,"a"
30490 .Lmemmove_begin_forward_efs:
30491 /* Forward moving data. */
30492 movq %rdx, %rcx
30493 rep movsb
30494+ pax_force_retaddr
30495 retq
30496 .Lmemmove_end_forward_efs:
30497 .previous
30498diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
30499index 2dcb380..2eb79fe 100644
30500--- a/arch/x86/lib/memset_64.S
30501+++ b/arch/x86/lib/memset_64.S
30502@@ -16,7 +16,7 @@
30503 *
30504 * rax original destination
30505 */
30506- .section .altinstr_replacement, "ax", @progbits
30507+ .section .altinstr_replacement, "a", @progbits
30508 .Lmemset_c:
30509 movq %rdi,%r9
30510 movq %rdx,%rcx
30511@@ -30,6 +30,7 @@
30512 movl %edx,%ecx
30513 rep stosb
30514 movq %r9,%rax
30515+ pax_force_retaddr
30516 ret
30517 .Lmemset_e:
30518 .previous
30519@@ -45,13 +46,14 @@
30520 *
30521 * rax original destination
30522 */
30523- .section .altinstr_replacement, "ax", @progbits
30524+ .section .altinstr_replacement, "a", @progbits
30525 .Lmemset_c_e:
30526 movq %rdi,%r9
30527 movb %sil,%al
30528 movq %rdx,%rcx
30529 rep stosb
30530 movq %r9,%rax
30531+ pax_force_retaddr
30532 ret
30533 .Lmemset_e_e:
30534 .previous
30535@@ -118,6 +120,7 @@ ENTRY(__memset)
30536
30537 .Lende:
30538 movq %r10,%rax
30539+ pax_force_retaddr
30540 ret
30541
30542 CFI_RESTORE_STATE
30543diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
30544index c9f2d9b..e7fd2c0 100644
30545--- a/arch/x86/lib/mmx_32.c
30546+++ b/arch/x86/lib/mmx_32.c
30547@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30548 {
30549 void *p;
30550 int i;
30551+ unsigned long cr0;
30552
30553 if (unlikely(in_interrupt()))
30554 return __memcpy(to, from, len);
30555@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30556 kernel_fpu_begin();
30557
30558 __asm__ __volatile__ (
30559- "1: prefetch (%0)\n" /* This set is 28 bytes */
30560- " prefetch 64(%0)\n"
30561- " prefetch 128(%0)\n"
30562- " prefetch 192(%0)\n"
30563- " prefetch 256(%0)\n"
30564+ "1: prefetch (%1)\n" /* This set is 28 bytes */
30565+ " prefetch 64(%1)\n"
30566+ " prefetch 128(%1)\n"
30567+ " prefetch 192(%1)\n"
30568+ " prefetch 256(%1)\n"
30569 "2: \n"
30570 ".section .fixup, \"ax\"\n"
30571- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30572+ "3: \n"
30573+
30574+#ifdef CONFIG_PAX_KERNEXEC
30575+ " movl %%cr0, %0\n"
30576+ " movl %0, %%eax\n"
30577+ " andl $0xFFFEFFFF, %%eax\n"
30578+ " movl %%eax, %%cr0\n"
30579+#endif
30580+
30581+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30582+
30583+#ifdef CONFIG_PAX_KERNEXEC
30584+ " movl %0, %%cr0\n"
30585+#endif
30586+
30587 " jmp 2b\n"
30588 ".previous\n"
30589 _ASM_EXTABLE(1b, 3b)
30590- : : "r" (from));
30591+ : "=&r" (cr0) : "r" (from) : "ax");
30592
30593 for ( ; i > 5; i--) {
30594 __asm__ __volatile__ (
30595- "1: prefetch 320(%0)\n"
30596- "2: movq (%0), %%mm0\n"
30597- " movq 8(%0), %%mm1\n"
30598- " movq 16(%0), %%mm2\n"
30599- " movq 24(%0), %%mm3\n"
30600- " movq %%mm0, (%1)\n"
30601- " movq %%mm1, 8(%1)\n"
30602- " movq %%mm2, 16(%1)\n"
30603- " movq %%mm3, 24(%1)\n"
30604- " movq 32(%0), %%mm0\n"
30605- " movq 40(%0), %%mm1\n"
30606- " movq 48(%0), %%mm2\n"
30607- " movq 56(%0), %%mm3\n"
30608- " movq %%mm0, 32(%1)\n"
30609- " movq %%mm1, 40(%1)\n"
30610- " movq %%mm2, 48(%1)\n"
30611- " movq %%mm3, 56(%1)\n"
30612+ "1: prefetch 320(%1)\n"
30613+ "2: movq (%1), %%mm0\n"
30614+ " movq 8(%1), %%mm1\n"
30615+ " movq 16(%1), %%mm2\n"
30616+ " movq 24(%1), %%mm3\n"
30617+ " movq %%mm0, (%2)\n"
30618+ " movq %%mm1, 8(%2)\n"
30619+ " movq %%mm2, 16(%2)\n"
30620+ " movq %%mm3, 24(%2)\n"
30621+ " movq 32(%1), %%mm0\n"
30622+ " movq 40(%1), %%mm1\n"
30623+ " movq 48(%1), %%mm2\n"
30624+ " movq 56(%1), %%mm3\n"
30625+ " movq %%mm0, 32(%2)\n"
30626+ " movq %%mm1, 40(%2)\n"
30627+ " movq %%mm2, 48(%2)\n"
30628+ " movq %%mm3, 56(%2)\n"
30629 ".section .fixup, \"ax\"\n"
30630- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30631+ "3:\n"
30632+
30633+#ifdef CONFIG_PAX_KERNEXEC
30634+ " movl %%cr0, %0\n"
30635+ " movl %0, %%eax\n"
30636+ " andl $0xFFFEFFFF, %%eax\n"
30637+ " movl %%eax, %%cr0\n"
30638+#endif
30639+
30640+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30641+
30642+#ifdef CONFIG_PAX_KERNEXEC
30643+ " movl %0, %%cr0\n"
30644+#endif
30645+
30646 " jmp 2b\n"
30647 ".previous\n"
30648 _ASM_EXTABLE(1b, 3b)
30649- : : "r" (from), "r" (to) : "memory");
30650+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30651
30652 from += 64;
30653 to += 64;
30654@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
30655 static void fast_copy_page(void *to, void *from)
30656 {
30657 int i;
30658+ unsigned long cr0;
30659
30660 kernel_fpu_begin();
30661
30662@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
30663 * but that is for later. -AV
30664 */
30665 __asm__ __volatile__(
30666- "1: prefetch (%0)\n"
30667- " prefetch 64(%0)\n"
30668- " prefetch 128(%0)\n"
30669- " prefetch 192(%0)\n"
30670- " prefetch 256(%0)\n"
30671+ "1: prefetch (%1)\n"
30672+ " prefetch 64(%1)\n"
30673+ " prefetch 128(%1)\n"
30674+ " prefetch 192(%1)\n"
30675+ " prefetch 256(%1)\n"
30676 "2: \n"
30677 ".section .fixup, \"ax\"\n"
30678- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30679+ "3: \n"
30680+
30681+#ifdef CONFIG_PAX_KERNEXEC
30682+ " movl %%cr0, %0\n"
30683+ " movl %0, %%eax\n"
30684+ " andl $0xFFFEFFFF, %%eax\n"
30685+ " movl %%eax, %%cr0\n"
30686+#endif
30687+
30688+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30689+
30690+#ifdef CONFIG_PAX_KERNEXEC
30691+ " movl %0, %%cr0\n"
30692+#endif
30693+
30694 " jmp 2b\n"
30695 ".previous\n"
30696- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30697+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30698
30699 for (i = 0; i < (4096-320)/64; i++) {
30700 __asm__ __volatile__ (
30701- "1: prefetch 320(%0)\n"
30702- "2: movq (%0), %%mm0\n"
30703- " movntq %%mm0, (%1)\n"
30704- " movq 8(%0), %%mm1\n"
30705- " movntq %%mm1, 8(%1)\n"
30706- " movq 16(%0), %%mm2\n"
30707- " movntq %%mm2, 16(%1)\n"
30708- " movq 24(%0), %%mm3\n"
30709- " movntq %%mm3, 24(%1)\n"
30710- " movq 32(%0), %%mm4\n"
30711- " movntq %%mm4, 32(%1)\n"
30712- " movq 40(%0), %%mm5\n"
30713- " movntq %%mm5, 40(%1)\n"
30714- " movq 48(%0), %%mm6\n"
30715- " movntq %%mm6, 48(%1)\n"
30716- " movq 56(%0), %%mm7\n"
30717- " movntq %%mm7, 56(%1)\n"
30718+ "1: prefetch 320(%1)\n"
30719+ "2: movq (%1), %%mm0\n"
30720+ " movntq %%mm0, (%2)\n"
30721+ " movq 8(%1), %%mm1\n"
30722+ " movntq %%mm1, 8(%2)\n"
30723+ " movq 16(%1), %%mm2\n"
30724+ " movntq %%mm2, 16(%2)\n"
30725+ " movq 24(%1), %%mm3\n"
30726+ " movntq %%mm3, 24(%2)\n"
30727+ " movq 32(%1), %%mm4\n"
30728+ " movntq %%mm4, 32(%2)\n"
30729+ " movq 40(%1), %%mm5\n"
30730+ " movntq %%mm5, 40(%2)\n"
30731+ " movq 48(%1), %%mm6\n"
30732+ " movntq %%mm6, 48(%2)\n"
30733+ " movq 56(%1), %%mm7\n"
30734+ " movntq %%mm7, 56(%2)\n"
30735 ".section .fixup, \"ax\"\n"
30736- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30737+ "3:\n"
30738+
30739+#ifdef CONFIG_PAX_KERNEXEC
30740+ " movl %%cr0, %0\n"
30741+ " movl %0, %%eax\n"
30742+ " andl $0xFFFEFFFF, %%eax\n"
30743+ " movl %%eax, %%cr0\n"
30744+#endif
30745+
30746+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30747+
30748+#ifdef CONFIG_PAX_KERNEXEC
30749+ " movl %0, %%cr0\n"
30750+#endif
30751+
30752 " jmp 2b\n"
30753 ".previous\n"
30754- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30755+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30756
30757 from += 64;
30758 to += 64;
30759@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30760 static void fast_copy_page(void *to, void *from)
30761 {
30762 int i;
30763+ unsigned long cr0;
30764
30765 kernel_fpu_begin();
30766
30767 __asm__ __volatile__ (
30768- "1: prefetch (%0)\n"
30769- " prefetch 64(%0)\n"
30770- " prefetch 128(%0)\n"
30771- " prefetch 192(%0)\n"
30772- " prefetch 256(%0)\n"
30773+ "1: prefetch (%1)\n"
30774+ " prefetch 64(%1)\n"
30775+ " prefetch 128(%1)\n"
30776+ " prefetch 192(%1)\n"
30777+ " prefetch 256(%1)\n"
30778 "2: \n"
30779 ".section .fixup, \"ax\"\n"
30780- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30781+ "3: \n"
30782+
30783+#ifdef CONFIG_PAX_KERNEXEC
30784+ " movl %%cr0, %0\n"
30785+ " movl %0, %%eax\n"
30786+ " andl $0xFFFEFFFF, %%eax\n"
30787+ " movl %%eax, %%cr0\n"
30788+#endif
30789+
30790+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30791+
30792+#ifdef CONFIG_PAX_KERNEXEC
30793+ " movl %0, %%cr0\n"
30794+#endif
30795+
30796 " jmp 2b\n"
30797 ".previous\n"
30798- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30799+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30800
30801 for (i = 0; i < 4096/64; i++) {
30802 __asm__ __volatile__ (
30803- "1: prefetch 320(%0)\n"
30804- "2: movq (%0), %%mm0\n"
30805- " movq 8(%0), %%mm1\n"
30806- " movq 16(%0), %%mm2\n"
30807- " movq 24(%0), %%mm3\n"
30808- " movq %%mm0, (%1)\n"
30809- " movq %%mm1, 8(%1)\n"
30810- " movq %%mm2, 16(%1)\n"
30811- " movq %%mm3, 24(%1)\n"
30812- " movq 32(%0), %%mm0\n"
30813- " movq 40(%0), %%mm1\n"
30814- " movq 48(%0), %%mm2\n"
30815- " movq 56(%0), %%mm3\n"
30816- " movq %%mm0, 32(%1)\n"
30817- " movq %%mm1, 40(%1)\n"
30818- " movq %%mm2, 48(%1)\n"
30819- " movq %%mm3, 56(%1)\n"
30820+ "1: prefetch 320(%1)\n"
30821+ "2: movq (%1), %%mm0\n"
30822+ " movq 8(%1), %%mm1\n"
30823+ " movq 16(%1), %%mm2\n"
30824+ " movq 24(%1), %%mm3\n"
30825+ " movq %%mm0, (%2)\n"
30826+ " movq %%mm1, 8(%2)\n"
30827+ " movq %%mm2, 16(%2)\n"
30828+ " movq %%mm3, 24(%2)\n"
30829+ " movq 32(%1), %%mm0\n"
30830+ " movq 40(%1), %%mm1\n"
30831+ " movq 48(%1), %%mm2\n"
30832+ " movq 56(%1), %%mm3\n"
30833+ " movq %%mm0, 32(%2)\n"
30834+ " movq %%mm1, 40(%2)\n"
30835+ " movq %%mm2, 48(%2)\n"
30836+ " movq %%mm3, 56(%2)\n"
30837 ".section .fixup, \"ax\"\n"
30838- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30839+ "3:\n"
30840+
30841+#ifdef CONFIG_PAX_KERNEXEC
30842+ " movl %%cr0, %0\n"
30843+ " movl %0, %%eax\n"
30844+ " andl $0xFFFEFFFF, %%eax\n"
30845+ " movl %%eax, %%cr0\n"
30846+#endif
30847+
30848+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30849+
30850+#ifdef CONFIG_PAX_KERNEXEC
30851+ " movl %0, %%cr0\n"
30852+#endif
30853+
30854 " jmp 2b\n"
30855 ".previous\n"
30856 _ASM_EXTABLE(1b, 3b)
30857- : : "r" (from), "r" (to) : "memory");
30858+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30859
30860 from += 64;
30861 to += 64;
30862diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30863index f6d13ee..d789440 100644
30864--- a/arch/x86/lib/msr-reg.S
30865+++ b/arch/x86/lib/msr-reg.S
30866@@ -3,6 +3,7 @@
30867 #include <asm/dwarf2.h>
30868 #include <asm/asm.h>
30869 #include <asm/msr.h>
30870+#include <asm/alternative-asm.h>
30871
30872 #ifdef CONFIG_X86_64
30873 /*
30874@@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30875 movl %edi, 28(%r10)
30876 popq_cfi %rbp
30877 popq_cfi %rbx
30878+ pax_force_retaddr
30879 ret
30880 3:
30881 CFI_RESTORE_STATE
30882diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30883index fc6ba17..d4d989d 100644
30884--- a/arch/x86/lib/putuser.S
30885+++ b/arch/x86/lib/putuser.S
30886@@ -16,7 +16,9 @@
30887 #include <asm/errno.h>
30888 #include <asm/asm.h>
30889 #include <asm/smap.h>
30890-
30891+#include <asm/segment.h>
30892+#include <asm/pgtable.h>
30893+#include <asm/alternative-asm.h>
30894
30895 /*
30896 * __put_user_X
30897@@ -30,57 +32,125 @@
30898 * as they get called from within inline assembly.
30899 */
30900
30901-#define ENTER CFI_STARTPROC ; \
30902- GET_THREAD_INFO(%_ASM_BX)
30903-#define EXIT ASM_CLAC ; \
30904- ret ; \
30905+#define ENTER CFI_STARTPROC
30906+#define EXIT ASM_CLAC ; \
30907+ pax_force_retaddr ; \
30908+ ret ; \
30909 CFI_ENDPROC
30910
30911+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30912+#define _DEST %_ASM_CX,%_ASM_BX
30913+#else
30914+#define _DEST %_ASM_CX
30915+#endif
30916+
30917+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30918+#define __copyuser_seg gs;
30919+#else
30920+#define __copyuser_seg
30921+#endif
30922+
30923 .text
30924 ENTRY(__put_user_1)
30925 ENTER
30926+
30927+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30928+ GET_THREAD_INFO(%_ASM_BX)
30929 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30930 jae bad_put_user
30931 ASM_STAC
30932-1: movb %al,(%_ASM_CX)
30933+
30934+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30935+ mov pax_user_shadow_base,%_ASM_BX
30936+ cmp %_ASM_BX,%_ASM_CX
30937+ jb 1234f
30938+ xor %ebx,%ebx
30939+1234:
30940+#endif
30941+
30942+#endif
30943+
30944+1: __copyuser_seg movb %al,(_DEST)
30945 xor %eax,%eax
30946 EXIT
30947 ENDPROC(__put_user_1)
30948
30949 ENTRY(__put_user_2)
30950 ENTER
30951+
30952+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30953+ GET_THREAD_INFO(%_ASM_BX)
30954 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30955 sub $1,%_ASM_BX
30956 cmp %_ASM_BX,%_ASM_CX
30957 jae bad_put_user
30958 ASM_STAC
30959-2: movw %ax,(%_ASM_CX)
30960+
30961+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30962+ mov pax_user_shadow_base,%_ASM_BX
30963+ cmp %_ASM_BX,%_ASM_CX
30964+ jb 1234f
30965+ xor %ebx,%ebx
30966+1234:
30967+#endif
30968+
30969+#endif
30970+
30971+2: __copyuser_seg movw %ax,(_DEST)
30972 xor %eax,%eax
30973 EXIT
30974 ENDPROC(__put_user_2)
30975
30976 ENTRY(__put_user_4)
30977 ENTER
30978+
30979+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30980+ GET_THREAD_INFO(%_ASM_BX)
30981 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30982 sub $3,%_ASM_BX
30983 cmp %_ASM_BX,%_ASM_CX
30984 jae bad_put_user
30985 ASM_STAC
30986-3: movl %eax,(%_ASM_CX)
30987+
30988+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30989+ mov pax_user_shadow_base,%_ASM_BX
30990+ cmp %_ASM_BX,%_ASM_CX
30991+ jb 1234f
30992+ xor %ebx,%ebx
30993+1234:
30994+#endif
30995+
30996+#endif
30997+
30998+3: __copyuser_seg movl %eax,(_DEST)
30999 xor %eax,%eax
31000 EXIT
31001 ENDPROC(__put_user_4)
31002
31003 ENTRY(__put_user_8)
31004 ENTER
31005+
31006+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31007+ GET_THREAD_INFO(%_ASM_BX)
31008 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
31009 sub $7,%_ASM_BX
31010 cmp %_ASM_BX,%_ASM_CX
31011 jae bad_put_user
31012 ASM_STAC
31013-4: mov %_ASM_AX,(%_ASM_CX)
31014+
31015+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31016+ mov pax_user_shadow_base,%_ASM_BX
31017+ cmp %_ASM_BX,%_ASM_CX
31018+ jb 1234f
31019+ xor %ebx,%ebx
31020+1234:
31021+#endif
31022+
31023+#endif
31024+
31025+4: __copyuser_seg mov %_ASM_AX,(_DEST)
31026 #ifdef CONFIG_X86_32
31027-5: movl %edx,4(%_ASM_CX)
31028+5: __copyuser_seg movl %edx,4(_DEST)
31029 #endif
31030 xor %eax,%eax
31031 EXIT
31032diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
31033index 5dff5f0..cadebf4 100644
31034--- a/arch/x86/lib/rwsem.S
31035+++ b/arch/x86/lib/rwsem.S
31036@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
31037 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
31038 CFI_RESTORE __ASM_REG(dx)
31039 restore_common_regs
31040+ pax_force_retaddr
31041 ret
31042 CFI_ENDPROC
31043 ENDPROC(call_rwsem_down_read_failed)
31044@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
31045 movq %rax,%rdi
31046 call rwsem_down_write_failed
31047 restore_common_regs
31048+ pax_force_retaddr
31049 ret
31050 CFI_ENDPROC
31051 ENDPROC(call_rwsem_down_write_failed)
31052@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
31053 movq %rax,%rdi
31054 call rwsem_wake
31055 restore_common_regs
31056-1: ret
31057+1: pax_force_retaddr
31058+ ret
31059 CFI_ENDPROC
31060 ENDPROC(call_rwsem_wake)
31061
31062@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
31063 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
31064 CFI_RESTORE __ASM_REG(dx)
31065 restore_common_regs
31066+ pax_force_retaddr
31067 ret
31068 CFI_ENDPROC
31069 ENDPROC(call_rwsem_downgrade_wake)
31070diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
31071index b30b5eb..2b57052 100644
31072--- a/arch/x86/lib/thunk_64.S
31073+++ b/arch/x86/lib/thunk_64.S
31074@@ -9,6 +9,7 @@
31075 #include <asm/dwarf2.h>
31076 #include <asm/calling.h>
31077 #include <asm/asm.h>
31078+#include <asm/alternative-asm.h>
31079
31080 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
31081 .macro THUNK name, func, put_ret_addr_in_rdi=0
31082@@ -16,11 +17,11 @@
31083 \name:
31084 CFI_STARTPROC
31085
31086- /* this one pushes 9 elems, the next one would be %rIP */
31087- SAVE_ARGS
31088+ /* this one pushes 15+1 elems, the next one would be %rIP */
31089+ SAVE_ARGS 8
31090
31091 .if \put_ret_addr_in_rdi
31092- movq_cfi_restore 9*8, rdi
31093+ movq_cfi_restore RIP, rdi
31094 .endif
31095
31096 call \func
31097@@ -47,9 +48,10 @@
31098
31099 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
31100 CFI_STARTPROC
31101- SAVE_ARGS
31102+ SAVE_ARGS 8
31103 restore:
31104- RESTORE_ARGS
31105+ RESTORE_ARGS 1,8
31106+ pax_force_retaddr
31107 ret
31108 CFI_ENDPROC
31109 _ASM_NOKPROBE(restore)
31110diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
31111index e2f5e21..4b22130 100644
31112--- a/arch/x86/lib/usercopy_32.c
31113+++ b/arch/x86/lib/usercopy_32.c
31114@@ -42,11 +42,13 @@ do { \
31115 int __d0; \
31116 might_fault(); \
31117 __asm__ __volatile__( \
31118+ __COPYUSER_SET_ES \
31119 ASM_STAC "\n" \
31120 "0: rep; stosl\n" \
31121 " movl %2,%0\n" \
31122 "1: rep; stosb\n" \
31123 "2: " ASM_CLAC "\n" \
31124+ __COPYUSER_RESTORE_ES \
31125 ".section .fixup,\"ax\"\n" \
31126 "3: lea 0(%2,%0,4),%0\n" \
31127 " jmp 2b\n" \
31128@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
31129
31130 #ifdef CONFIG_X86_INTEL_USERCOPY
31131 static unsigned long
31132-__copy_user_intel(void __user *to, const void *from, unsigned long size)
31133+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
31134 {
31135 int d0, d1;
31136 __asm__ __volatile__(
31137@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31138 " .align 2,0x90\n"
31139 "3: movl 0(%4), %%eax\n"
31140 "4: movl 4(%4), %%edx\n"
31141- "5: movl %%eax, 0(%3)\n"
31142- "6: movl %%edx, 4(%3)\n"
31143+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
31144+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
31145 "7: movl 8(%4), %%eax\n"
31146 "8: movl 12(%4),%%edx\n"
31147- "9: movl %%eax, 8(%3)\n"
31148- "10: movl %%edx, 12(%3)\n"
31149+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
31150+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
31151 "11: movl 16(%4), %%eax\n"
31152 "12: movl 20(%4), %%edx\n"
31153- "13: movl %%eax, 16(%3)\n"
31154- "14: movl %%edx, 20(%3)\n"
31155+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
31156+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
31157 "15: movl 24(%4), %%eax\n"
31158 "16: movl 28(%4), %%edx\n"
31159- "17: movl %%eax, 24(%3)\n"
31160- "18: movl %%edx, 28(%3)\n"
31161+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
31162+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
31163 "19: movl 32(%4), %%eax\n"
31164 "20: movl 36(%4), %%edx\n"
31165- "21: movl %%eax, 32(%3)\n"
31166- "22: movl %%edx, 36(%3)\n"
31167+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
31168+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
31169 "23: movl 40(%4), %%eax\n"
31170 "24: movl 44(%4), %%edx\n"
31171- "25: movl %%eax, 40(%3)\n"
31172- "26: movl %%edx, 44(%3)\n"
31173+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
31174+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
31175 "27: movl 48(%4), %%eax\n"
31176 "28: movl 52(%4), %%edx\n"
31177- "29: movl %%eax, 48(%3)\n"
31178- "30: movl %%edx, 52(%3)\n"
31179+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
31180+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
31181 "31: movl 56(%4), %%eax\n"
31182 "32: movl 60(%4), %%edx\n"
31183- "33: movl %%eax, 56(%3)\n"
31184- "34: movl %%edx, 60(%3)\n"
31185+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
31186+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
31187 " addl $-64, %0\n"
31188 " addl $64, %4\n"
31189 " addl $64, %3\n"
31190@@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31191 " shrl $2, %0\n"
31192 " andl $3, %%eax\n"
31193 " cld\n"
31194+ __COPYUSER_SET_ES
31195 "99: rep; movsl\n"
31196 "36: movl %%eax, %0\n"
31197 "37: rep; movsb\n"
31198 "100:\n"
31199+ __COPYUSER_RESTORE_ES
31200+ ".section .fixup,\"ax\"\n"
31201+ "101: lea 0(%%eax,%0,4),%0\n"
31202+ " jmp 100b\n"
31203+ ".previous\n"
31204+ _ASM_EXTABLE(1b,100b)
31205+ _ASM_EXTABLE(2b,100b)
31206+ _ASM_EXTABLE(3b,100b)
31207+ _ASM_EXTABLE(4b,100b)
31208+ _ASM_EXTABLE(5b,100b)
31209+ _ASM_EXTABLE(6b,100b)
31210+ _ASM_EXTABLE(7b,100b)
31211+ _ASM_EXTABLE(8b,100b)
31212+ _ASM_EXTABLE(9b,100b)
31213+ _ASM_EXTABLE(10b,100b)
31214+ _ASM_EXTABLE(11b,100b)
31215+ _ASM_EXTABLE(12b,100b)
31216+ _ASM_EXTABLE(13b,100b)
31217+ _ASM_EXTABLE(14b,100b)
31218+ _ASM_EXTABLE(15b,100b)
31219+ _ASM_EXTABLE(16b,100b)
31220+ _ASM_EXTABLE(17b,100b)
31221+ _ASM_EXTABLE(18b,100b)
31222+ _ASM_EXTABLE(19b,100b)
31223+ _ASM_EXTABLE(20b,100b)
31224+ _ASM_EXTABLE(21b,100b)
31225+ _ASM_EXTABLE(22b,100b)
31226+ _ASM_EXTABLE(23b,100b)
31227+ _ASM_EXTABLE(24b,100b)
31228+ _ASM_EXTABLE(25b,100b)
31229+ _ASM_EXTABLE(26b,100b)
31230+ _ASM_EXTABLE(27b,100b)
31231+ _ASM_EXTABLE(28b,100b)
31232+ _ASM_EXTABLE(29b,100b)
31233+ _ASM_EXTABLE(30b,100b)
31234+ _ASM_EXTABLE(31b,100b)
31235+ _ASM_EXTABLE(32b,100b)
31236+ _ASM_EXTABLE(33b,100b)
31237+ _ASM_EXTABLE(34b,100b)
31238+ _ASM_EXTABLE(35b,100b)
31239+ _ASM_EXTABLE(36b,100b)
31240+ _ASM_EXTABLE(37b,100b)
31241+ _ASM_EXTABLE(99b,101b)
31242+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
31243+ : "1"(to), "2"(from), "0"(size)
31244+ : "eax", "edx", "memory");
31245+ return size;
31246+}
31247+
31248+static unsigned long
31249+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
31250+{
31251+ int d0, d1;
31252+ __asm__ __volatile__(
31253+ " .align 2,0x90\n"
31254+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
31255+ " cmpl $67, %0\n"
31256+ " jbe 3f\n"
31257+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
31258+ " .align 2,0x90\n"
31259+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
31260+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
31261+ "5: movl %%eax, 0(%3)\n"
31262+ "6: movl %%edx, 4(%3)\n"
31263+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
31264+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
31265+ "9: movl %%eax, 8(%3)\n"
31266+ "10: movl %%edx, 12(%3)\n"
31267+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
31268+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
31269+ "13: movl %%eax, 16(%3)\n"
31270+ "14: movl %%edx, 20(%3)\n"
31271+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
31272+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
31273+ "17: movl %%eax, 24(%3)\n"
31274+ "18: movl %%edx, 28(%3)\n"
31275+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
31276+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
31277+ "21: movl %%eax, 32(%3)\n"
31278+ "22: movl %%edx, 36(%3)\n"
31279+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
31280+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
31281+ "25: movl %%eax, 40(%3)\n"
31282+ "26: movl %%edx, 44(%3)\n"
31283+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
31284+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
31285+ "29: movl %%eax, 48(%3)\n"
31286+ "30: movl %%edx, 52(%3)\n"
31287+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
31288+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
31289+ "33: movl %%eax, 56(%3)\n"
31290+ "34: movl %%edx, 60(%3)\n"
31291+ " addl $-64, %0\n"
31292+ " addl $64, %4\n"
31293+ " addl $64, %3\n"
31294+ " cmpl $63, %0\n"
31295+ " ja 1b\n"
31296+ "35: movl %0, %%eax\n"
31297+ " shrl $2, %0\n"
31298+ " andl $3, %%eax\n"
31299+ " cld\n"
31300+ "99: rep; "__copyuser_seg" movsl\n"
31301+ "36: movl %%eax, %0\n"
31302+ "37: rep; "__copyuser_seg" movsb\n"
31303+ "100:\n"
31304 ".section .fixup,\"ax\"\n"
31305 "101: lea 0(%%eax,%0,4),%0\n"
31306 " jmp 100b\n"
31307@@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31308 int d0, d1;
31309 __asm__ __volatile__(
31310 " .align 2,0x90\n"
31311- "0: movl 32(%4), %%eax\n"
31312+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31313 " cmpl $67, %0\n"
31314 " jbe 2f\n"
31315- "1: movl 64(%4), %%eax\n"
31316+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31317 " .align 2,0x90\n"
31318- "2: movl 0(%4), %%eax\n"
31319- "21: movl 4(%4), %%edx\n"
31320+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31321+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31322 " movl %%eax, 0(%3)\n"
31323 " movl %%edx, 4(%3)\n"
31324- "3: movl 8(%4), %%eax\n"
31325- "31: movl 12(%4),%%edx\n"
31326+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31327+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31328 " movl %%eax, 8(%3)\n"
31329 " movl %%edx, 12(%3)\n"
31330- "4: movl 16(%4), %%eax\n"
31331- "41: movl 20(%4), %%edx\n"
31332+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31333+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31334 " movl %%eax, 16(%3)\n"
31335 " movl %%edx, 20(%3)\n"
31336- "10: movl 24(%4), %%eax\n"
31337- "51: movl 28(%4), %%edx\n"
31338+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31339+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31340 " movl %%eax, 24(%3)\n"
31341 " movl %%edx, 28(%3)\n"
31342- "11: movl 32(%4), %%eax\n"
31343- "61: movl 36(%4), %%edx\n"
31344+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31345+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31346 " movl %%eax, 32(%3)\n"
31347 " movl %%edx, 36(%3)\n"
31348- "12: movl 40(%4), %%eax\n"
31349- "71: movl 44(%4), %%edx\n"
31350+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31351+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31352 " movl %%eax, 40(%3)\n"
31353 " movl %%edx, 44(%3)\n"
31354- "13: movl 48(%4), %%eax\n"
31355- "81: movl 52(%4), %%edx\n"
31356+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31357+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31358 " movl %%eax, 48(%3)\n"
31359 " movl %%edx, 52(%3)\n"
31360- "14: movl 56(%4), %%eax\n"
31361- "91: movl 60(%4), %%edx\n"
31362+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31363+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31364 " movl %%eax, 56(%3)\n"
31365 " movl %%edx, 60(%3)\n"
31366 " addl $-64, %0\n"
31367@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31368 " shrl $2, %0\n"
31369 " andl $3, %%eax\n"
31370 " cld\n"
31371- "6: rep; movsl\n"
31372+ "6: rep; "__copyuser_seg" movsl\n"
31373 " movl %%eax,%0\n"
31374- "7: rep; movsb\n"
31375+ "7: rep; "__copyuser_seg" movsb\n"
31376 "8:\n"
31377 ".section .fixup,\"ax\"\n"
31378 "9: lea 0(%%eax,%0,4),%0\n"
31379@@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31380
31381 __asm__ __volatile__(
31382 " .align 2,0x90\n"
31383- "0: movl 32(%4), %%eax\n"
31384+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31385 " cmpl $67, %0\n"
31386 " jbe 2f\n"
31387- "1: movl 64(%4), %%eax\n"
31388+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31389 " .align 2,0x90\n"
31390- "2: movl 0(%4), %%eax\n"
31391- "21: movl 4(%4), %%edx\n"
31392+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31393+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31394 " movnti %%eax, 0(%3)\n"
31395 " movnti %%edx, 4(%3)\n"
31396- "3: movl 8(%4), %%eax\n"
31397- "31: movl 12(%4),%%edx\n"
31398+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31399+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31400 " movnti %%eax, 8(%3)\n"
31401 " movnti %%edx, 12(%3)\n"
31402- "4: movl 16(%4), %%eax\n"
31403- "41: movl 20(%4), %%edx\n"
31404+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31405+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31406 " movnti %%eax, 16(%3)\n"
31407 " movnti %%edx, 20(%3)\n"
31408- "10: movl 24(%4), %%eax\n"
31409- "51: movl 28(%4), %%edx\n"
31410+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31411+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31412 " movnti %%eax, 24(%3)\n"
31413 " movnti %%edx, 28(%3)\n"
31414- "11: movl 32(%4), %%eax\n"
31415- "61: movl 36(%4), %%edx\n"
31416+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31417+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31418 " movnti %%eax, 32(%3)\n"
31419 " movnti %%edx, 36(%3)\n"
31420- "12: movl 40(%4), %%eax\n"
31421- "71: movl 44(%4), %%edx\n"
31422+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31423+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31424 " movnti %%eax, 40(%3)\n"
31425 " movnti %%edx, 44(%3)\n"
31426- "13: movl 48(%4), %%eax\n"
31427- "81: movl 52(%4), %%edx\n"
31428+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31429+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31430 " movnti %%eax, 48(%3)\n"
31431 " movnti %%edx, 52(%3)\n"
31432- "14: movl 56(%4), %%eax\n"
31433- "91: movl 60(%4), %%edx\n"
31434+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31435+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31436 " movnti %%eax, 56(%3)\n"
31437 " movnti %%edx, 60(%3)\n"
31438 " addl $-64, %0\n"
31439@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31440 " shrl $2, %0\n"
31441 " andl $3, %%eax\n"
31442 " cld\n"
31443- "6: rep; movsl\n"
31444+ "6: rep; "__copyuser_seg" movsl\n"
31445 " movl %%eax,%0\n"
31446- "7: rep; movsb\n"
31447+ "7: rep; "__copyuser_seg" movsb\n"
31448 "8:\n"
31449 ".section .fixup,\"ax\"\n"
31450 "9: lea 0(%%eax,%0,4),%0\n"
31451@@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
31452
31453 __asm__ __volatile__(
31454 " .align 2,0x90\n"
31455- "0: movl 32(%4), %%eax\n"
31456+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31457 " cmpl $67, %0\n"
31458 " jbe 2f\n"
31459- "1: movl 64(%4), %%eax\n"
31460+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31461 " .align 2,0x90\n"
31462- "2: movl 0(%4), %%eax\n"
31463- "21: movl 4(%4), %%edx\n"
31464+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31465+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31466 " movnti %%eax, 0(%3)\n"
31467 " movnti %%edx, 4(%3)\n"
31468- "3: movl 8(%4), %%eax\n"
31469- "31: movl 12(%4),%%edx\n"
31470+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31471+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31472 " movnti %%eax, 8(%3)\n"
31473 " movnti %%edx, 12(%3)\n"
31474- "4: movl 16(%4), %%eax\n"
31475- "41: movl 20(%4), %%edx\n"
31476+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31477+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31478 " movnti %%eax, 16(%3)\n"
31479 " movnti %%edx, 20(%3)\n"
31480- "10: movl 24(%4), %%eax\n"
31481- "51: movl 28(%4), %%edx\n"
31482+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31483+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31484 " movnti %%eax, 24(%3)\n"
31485 " movnti %%edx, 28(%3)\n"
31486- "11: movl 32(%4), %%eax\n"
31487- "61: movl 36(%4), %%edx\n"
31488+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31489+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31490 " movnti %%eax, 32(%3)\n"
31491 " movnti %%edx, 36(%3)\n"
31492- "12: movl 40(%4), %%eax\n"
31493- "71: movl 44(%4), %%edx\n"
31494+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31495+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31496 " movnti %%eax, 40(%3)\n"
31497 " movnti %%edx, 44(%3)\n"
31498- "13: movl 48(%4), %%eax\n"
31499- "81: movl 52(%4), %%edx\n"
31500+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31501+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31502 " movnti %%eax, 48(%3)\n"
31503 " movnti %%edx, 52(%3)\n"
31504- "14: movl 56(%4), %%eax\n"
31505- "91: movl 60(%4), %%edx\n"
31506+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31507+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31508 " movnti %%eax, 56(%3)\n"
31509 " movnti %%edx, 60(%3)\n"
31510 " addl $-64, %0\n"
31511@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
31512 " shrl $2, %0\n"
31513 " andl $3, %%eax\n"
31514 " cld\n"
31515- "6: rep; movsl\n"
31516+ "6: rep; "__copyuser_seg" movsl\n"
31517 " movl %%eax,%0\n"
31518- "7: rep; movsb\n"
31519+ "7: rep; "__copyuser_seg" movsb\n"
31520 "8:\n"
31521 ".section .fixup,\"ax\"\n"
31522 "9: lea 0(%%eax,%0,4),%0\n"
31523@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
31524 */
31525 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
31526 unsigned long size);
31527-unsigned long __copy_user_intel(void __user *to, const void *from,
31528+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
31529+ unsigned long size);
31530+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
31531 unsigned long size);
31532 unsigned long __copy_user_zeroing_intel_nocache(void *to,
31533 const void __user *from, unsigned long size);
31534 #endif /* CONFIG_X86_INTEL_USERCOPY */
31535
31536 /* Generic arbitrary sized copy. */
31537-#define __copy_user(to, from, size) \
31538+#define __copy_user(to, from, size, prefix, set, restore) \
31539 do { \
31540 int __d0, __d1, __d2; \
31541 __asm__ __volatile__( \
31542+ set \
31543 " cmp $7,%0\n" \
31544 " jbe 1f\n" \
31545 " movl %1,%0\n" \
31546 " negl %0\n" \
31547 " andl $7,%0\n" \
31548 " subl %0,%3\n" \
31549- "4: rep; movsb\n" \
31550+ "4: rep; "prefix"movsb\n" \
31551 " movl %3,%0\n" \
31552 " shrl $2,%0\n" \
31553 " andl $3,%3\n" \
31554 " .align 2,0x90\n" \
31555- "0: rep; movsl\n" \
31556+ "0: rep; "prefix"movsl\n" \
31557 " movl %3,%0\n" \
31558- "1: rep; movsb\n" \
31559+ "1: rep; "prefix"movsb\n" \
31560 "2:\n" \
31561+ restore \
31562 ".section .fixup,\"ax\"\n" \
31563 "5: addl %3,%0\n" \
31564 " jmp 2b\n" \
31565@@ -538,14 +650,14 @@ do { \
31566 " negl %0\n" \
31567 " andl $7,%0\n" \
31568 " subl %0,%3\n" \
31569- "4: rep; movsb\n" \
31570+ "4: rep; "__copyuser_seg"movsb\n" \
31571 " movl %3,%0\n" \
31572 " shrl $2,%0\n" \
31573 " andl $3,%3\n" \
31574 " .align 2,0x90\n" \
31575- "0: rep; movsl\n" \
31576+ "0: rep; "__copyuser_seg"movsl\n" \
31577 " movl %3,%0\n" \
31578- "1: rep; movsb\n" \
31579+ "1: rep; "__copyuser_seg"movsb\n" \
31580 "2:\n" \
31581 ".section .fixup,\"ax\"\n" \
31582 "5: addl %3,%0\n" \
31583@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
31584 {
31585 stac();
31586 if (movsl_is_ok(to, from, n))
31587- __copy_user(to, from, n);
31588+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
31589 else
31590- n = __copy_user_intel(to, from, n);
31591+ n = __generic_copy_to_user_intel(to, from, n);
31592 clac();
31593 return n;
31594 }
31595@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
31596 {
31597 stac();
31598 if (movsl_is_ok(to, from, n))
31599- __copy_user(to, from, n);
31600+ __copy_user(to, from, n, __copyuser_seg, "", "");
31601 else
31602- n = __copy_user_intel((void __user *)to,
31603- (const void *)from, n);
31604+ n = __generic_copy_from_user_intel(to, from, n);
31605 clac();
31606 return n;
31607 }
31608@@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
31609 if (n > 64 && cpu_has_xmm2)
31610 n = __copy_user_intel_nocache(to, from, n);
31611 else
31612- __copy_user(to, from, n);
31613+ __copy_user(to, from, n, __copyuser_seg, "", "");
31614 #else
31615- __copy_user(to, from, n);
31616+ __copy_user(to, from, n, __copyuser_seg, "", "");
31617 #endif
31618 clac();
31619 return n;
31620 }
31621 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
31622
31623-/**
31624- * copy_to_user: - Copy a block of data into user space.
31625- * @to: Destination address, in user space.
31626- * @from: Source address, in kernel space.
31627- * @n: Number of bytes to copy.
31628- *
31629- * Context: User context only. This function may sleep.
31630- *
31631- * Copy data from kernel space to user space.
31632- *
31633- * Returns number of bytes that could not be copied.
31634- * On success, this will be zero.
31635- */
31636-unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31637+#ifdef CONFIG_PAX_MEMORY_UDEREF
31638+void __set_fs(mm_segment_t x)
31639 {
31640- if (access_ok(VERIFY_WRITE, to, n))
31641- n = __copy_to_user(to, from, n);
31642- return n;
31643+ switch (x.seg) {
31644+ case 0:
31645+ loadsegment(gs, 0);
31646+ break;
31647+ case TASK_SIZE_MAX:
31648+ loadsegment(gs, __USER_DS);
31649+ break;
31650+ case -1UL:
31651+ loadsegment(gs, __KERNEL_DS);
31652+ break;
31653+ default:
31654+ BUG();
31655+ }
31656 }
31657-EXPORT_SYMBOL(_copy_to_user);
31658+EXPORT_SYMBOL(__set_fs);
31659
31660-/**
31661- * copy_from_user: - Copy a block of data from user space.
31662- * @to: Destination address, in kernel space.
31663- * @from: Source address, in user space.
31664- * @n: Number of bytes to copy.
31665- *
31666- * Context: User context only. This function may sleep.
31667- *
31668- * Copy data from user space to kernel space.
31669- *
31670- * Returns number of bytes that could not be copied.
31671- * On success, this will be zero.
31672- *
31673- * If some data could not be copied, this function will pad the copied
31674- * data to the requested size using zero bytes.
31675- */
31676-unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31677+void set_fs(mm_segment_t x)
31678 {
31679- if (access_ok(VERIFY_READ, from, n))
31680- n = __copy_from_user(to, from, n);
31681- else
31682- memset(to, 0, n);
31683- return n;
31684+ current_thread_info()->addr_limit = x;
31685+ __set_fs(x);
31686 }
31687-EXPORT_SYMBOL(_copy_from_user);
31688+EXPORT_SYMBOL(set_fs);
31689+#endif
31690diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31691index c905e89..01ab928 100644
31692--- a/arch/x86/lib/usercopy_64.c
31693+++ b/arch/x86/lib/usercopy_64.c
31694@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31695 might_fault();
31696 /* no memory constraint because it doesn't change any memory gcc knows
31697 about */
31698+ pax_open_userland();
31699 stac();
31700 asm volatile(
31701 " testq %[size8],%[size8]\n"
31702@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31703 _ASM_EXTABLE(0b,3b)
31704 _ASM_EXTABLE(1b,2b)
31705 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31706- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31707+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31708 [zero] "r" (0UL), [eight] "r" (8UL));
31709 clac();
31710+ pax_close_userland();
31711 return size;
31712 }
31713 EXPORT_SYMBOL(__clear_user);
31714@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31715 }
31716 EXPORT_SYMBOL(clear_user);
31717
31718-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31719+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31720 {
31721- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31722- return copy_user_generic((__force void *)to, (__force void *)from, len);
31723- }
31724- return len;
31725+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31726+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31727+ return len;
31728 }
31729 EXPORT_SYMBOL(copy_in_user);
31730
31731@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31732 * it is not necessary to optimize tail handling.
31733 */
31734 __visible unsigned long
31735-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31736+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31737 {
31738 char c;
31739 unsigned zero_len;
31740
31741+ clac();
31742+ pax_close_userland();
31743 for (; len; --len, to++) {
31744 if (__get_user_nocheck(c, from++, sizeof(char)))
31745 break;
31746@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31747 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31748 if (__put_user_nocheck(c, to++, sizeof(char)))
31749 break;
31750- clac();
31751 return len;
31752 }
31753diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31754index 6a19ad9..1c48f9a 100644
31755--- a/arch/x86/mm/Makefile
31756+++ b/arch/x86/mm/Makefile
31757@@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31758 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31759
31760 obj-$(CONFIG_MEMTEST) += memtest.o
31761+
31762+quote:="
31763+obj-$(CONFIG_X86_64) += uderef_64.o
31764+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31765diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31766index 903ec1e..c4166b2 100644
31767--- a/arch/x86/mm/extable.c
31768+++ b/arch/x86/mm/extable.c
31769@@ -6,12 +6,24 @@
31770 static inline unsigned long
31771 ex_insn_addr(const struct exception_table_entry *x)
31772 {
31773- return (unsigned long)&x->insn + x->insn;
31774+ unsigned long reloc = 0;
31775+
31776+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31777+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31778+#endif
31779+
31780+ return (unsigned long)&x->insn + x->insn + reloc;
31781 }
31782 static inline unsigned long
31783 ex_fixup_addr(const struct exception_table_entry *x)
31784 {
31785- return (unsigned long)&x->fixup + x->fixup;
31786+ unsigned long reloc = 0;
31787+
31788+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31789+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31790+#endif
31791+
31792+ return (unsigned long)&x->fixup + x->fixup + reloc;
31793 }
31794
31795 int fixup_exception(struct pt_regs *regs)
31796@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31797 unsigned long new_ip;
31798
31799 #ifdef CONFIG_PNPBIOS
31800- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31801+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31802 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31803 extern u32 pnp_bios_is_utter_crap;
31804 pnp_bios_is_utter_crap = 1;
31805@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31806 i += 4;
31807 p->fixup -= i;
31808 i += 4;
31809+
31810+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31811+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31812+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31813+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31814+#endif
31815+
31816 }
31817 }
31818
31819diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31820index d973e61..fb868e9 100644
31821--- a/arch/x86/mm/fault.c
31822+++ b/arch/x86/mm/fault.c
31823@@ -13,12 +13,19 @@
31824 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31825 #include <linux/prefetch.h> /* prefetchw */
31826 #include <linux/context_tracking.h> /* exception_enter(), ... */
31827+#include <linux/unistd.h>
31828+#include <linux/compiler.h>
31829
31830 #include <asm/traps.h> /* dotraplinkage, ... */
31831 #include <asm/pgalloc.h> /* pgd_*(), ... */
31832 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31833 #include <asm/fixmap.h> /* VSYSCALL_ADDR */
31834 #include <asm/vsyscall.h> /* emulate_vsyscall */
31835+#include <asm/tlbflush.h>
31836+
31837+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31838+#include <asm/stacktrace.h>
31839+#endif
31840
31841 #define CREATE_TRACE_POINTS
31842 #include <asm/trace/exceptions.h>
31843@@ -59,7 +66,7 @@ static nokprobe_inline int kprobes_fault(struct pt_regs *regs)
31844 int ret = 0;
31845
31846 /* kprobe_running() needs smp_processor_id() */
31847- if (kprobes_built_in() && !user_mode_vm(regs)) {
31848+ if (kprobes_built_in() && !user_mode(regs)) {
31849 preempt_disable();
31850 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31851 ret = 1;
31852@@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31853 return !instr_lo || (instr_lo>>1) == 1;
31854 case 0x00:
31855 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31856- if (probe_kernel_address(instr, opcode))
31857+ if (user_mode(regs)) {
31858+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31859+ return 0;
31860+ } else if (probe_kernel_address(instr, opcode))
31861 return 0;
31862
31863 *prefetch = (instr_lo == 0xF) &&
31864@@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31865 while (instr < max_instr) {
31866 unsigned char opcode;
31867
31868- if (probe_kernel_address(instr, opcode))
31869+ if (user_mode(regs)) {
31870+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31871+ break;
31872+ } else if (probe_kernel_address(instr, opcode))
31873 break;
31874
31875 instr++;
31876@@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31877 force_sig_info(si_signo, &info, tsk);
31878 }
31879
31880+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31881+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31882+#endif
31883+
31884+#ifdef CONFIG_PAX_EMUTRAMP
31885+static int pax_handle_fetch_fault(struct pt_regs *regs);
31886+#endif
31887+
31888+#ifdef CONFIG_PAX_PAGEEXEC
31889+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31890+{
31891+ pgd_t *pgd;
31892+ pud_t *pud;
31893+ pmd_t *pmd;
31894+
31895+ pgd = pgd_offset(mm, address);
31896+ if (!pgd_present(*pgd))
31897+ return NULL;
31898+ pud = pud_offset(pgd, address);
31899+ if (!pud_present(*pud))
31900+ return NULL;
31901+ pmd = pmd_offset(pud, address);
31902+ if (!pmd_present(*pmd))
31903+ return NULL;
31904+ return pmd;
31905+}
31906+#endif
31907+
31908 DEFINE_SPINLOCK(pgd_lock);
31909 LIST_HEAD(pgd_list);
31910
31911@@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31912 for (address = VMALLOC_START & PMD_MASK;
31913 address >= TASK_SIZE && address < FIXADDR_TOP;
31914 address += PMD_SIZE) {
31915+
31916+#ifdef CONFIG_PAX_PER_CPU_PGD
31917+ unsigned long cpu;
31918+#else
31919 struct page *page;
31920+#endif
31921
31922 spin_lock(&pgd_lock);
31923+
31924+#ifdef CONFIG_PAX_PER_CPU_PGD
31925+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31926+ pgd_t *pgd = get_cpu_pgd(cpu, user);
31927+ pmd_t *ret;
31928+
31929+ ret = vmalloc_sync_one(pgd, address);
31930+ if (!ret)
31931+ break;
31932+ pgd = get_cpu_pgd(cpu, kernel);
31933+#else
31934 list_for_each_entry(page, &pgd_list, lru) {
31935+ pgd_t *pgd;
31936 spinlock_t *pgt_lock;
31937 pmd_t *ret;
31938
31939@@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31940 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31941
31942 spin_lock(pgt_lock);
31943- ret = vmalloc_sync_one(page_address(page), address);
31944+ pgd = page_address(page);
31945+#endif
31946+
31947+ ret = vmalloc_sync_one(pgd, address);
31948+
31949+#ifndef CONFIG_PAX_PER_CPU_PGD
31950 spin_unlock(pgt_lock);
31951+#endif
31952
31953 if (!ret)
31954 break;
31955@@ -281,6 +345,12 @@ static noinline int vmalloc_fault(unsigned long address)
31956 * an interrupt in the middle of a task switch..
31957 */
31958 pgd_paddr = read_cr3();
31959+
31960+#ifdef CONFIG_PAX_PER_CPU_PGD
31961+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31962+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31963+#endif
31964+
31965 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31966 if (!pmd_k)
31967 return -1;
31968@@ -377,11 +447,25 @@ static noinline int vmalloc_fault(unsigned long address)
31969 * happen within a race in page table update. In the later
31970 * case just flush:
31971 */
31972- pgd = pgd_offset(current->active_mm, address);
31973+
31974 pgd_ref = pgd_offset_k(address);
31975 if (pgd_none(*pgd_ref))
31976 return -1;
31977
31978+#ifdef CONFIG_PAX_PER_CPU_PGD
31979+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31980+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31981+ if (pgd_none(*pgd)) {
31982+ set_pgd(pgd, *pgd_ref);
31983+ arch_flush_lazy_mmu_mode();
31984+ } else {
31985+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31986+ }
31987+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31988+#else
31989+ pgd = pgd_offset(current->active_mm, address);
31990+#endif
31991+
31992 if (pgd_none(*pgd)) {
31993 set_pgd(pgd, *pgd_ref);
31994 arch_flush_lazy_mmu_mode();
31995@@ -548,7 +632,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31996 static int is_errata100(struct pt_regs *regs, unsigned long address)
31997 {
31998 #ifdef CONFIG_X86_64
31999- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
32000+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
32001 return 1;
32002 #endif
32003 return 0;
32004@@ -575,9 +659,9 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
32005 }
32006
32007 static const char nx_warning[] = KERN_CRIT
32008-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
32009+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
32010 static const char smep_warning[] = KERN_CRIT
32011-"unable to execute userspace code (SMEP?) (uid: %d)\n";
32012+"unable to execute userspace code (SMEP?) (uid: %d, task: %s, pid: %d)\n";
32013
32014 static void
32015 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32016@@ -586,7 +670,7 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32017 if (!oops_may_print())
32018 return;
32019
32020- if (error_code & PF_INSTR) {
32021+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
32022 unsigned int level;
32023 pgd_t *pgd;
32024 pte_t *pte;
32025@@ -597,13 +681,25 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32026 pte = lookup_address_in_pgd(pgd, address, &level);
32027
32028 if (pte && pte_present(*pte) && !pte_exec(*pte))
32029- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
32030+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
32031 if (pte && pte_present(*pte) && pte_exec(*pte) &&
32032 (pgd_flags(*pgd) & _PAGE_USER) &&
32033 (read_cr4() & X86_CR4_SMEP))
32034- printk(smep_warning, from_kuid(&init_user_ns, current_uid()));
32035+ printk(smep_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
32036 }
32037
32038+#ifdef CONFIG_PAX_KERNEXEC
32039+ if (init_mm.start_code <= address && address < init_mm.end_code) {
32040+ if (current->signal->curr_ip)
32041+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
32042+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
32043+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
32044+ else
32045+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
32046+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
32047+ }
32048+#endif
32049+
32050 printk(KERN_ALERT "BUG: unable to handle kernel ");
32051 if (address < PAGE_SIZE)
32052 printk(KERN_CONT "NULL pointer dereference");
32053@@ -782,6 +878,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
32054 return;
32055 }
32056 #endif
32057+
32058+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32059+ if (pax_is_fetch_fault(regs, error_code, address)) {
32060+
32061+#ifdef CONFIG_PAX_EMUTRAMP
32062+ switch (pax_handle_fetch_fault(regs)) {
32063+ case 2:
32064+ return;
32065+ }
32066+#endif
32067+
32068+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32069+ do_group_exit(SIGKILL);
32070+ }
32071+#endif
32072+
32073 /* Kernel addresses are always protection faults: */
32074 if (address >= TASK_SIZE)
32075 error_code |= PF_PROT;
32076@@ -867,7 +979,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
32077 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
32078 printk(KERN_ERR
32079 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
32080- tsk->comm, tsk->pid, address);
32081+ tsk->comm, task_pid_nr(tsk), address);
32082 code = BUS_MCEERR_AR;
32083 }
32084 #endif
32085@@ -921,6 +1033,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
32086 return 1;
32087 }
32088
32089+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32090+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
32091+{
32092+ pte_t *pte;
32093+ pmd_t *pmd;
32094+ spinlock_t *ptl;
32095+ unsigned char pte_mask;
32096+
32097+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
32098+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
32099+ return 0;
32100+
32101+ /* PaX: it's our fault, let's handle it if we can */
32102+
32103+ /* PaX: take a look at read faults before acquiring any locks */
32104+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
32105+ /* instruction fetch attempt from a protected page in user mode */
32106+ up_read(&mm->mmap_sem);
32107+
32108+#ifdef CONFIG_PAX_EMUTRAMP
32109+ switch (pax_handle_fetch_fault(regs)) {
32110+ case 2:
32111+ return 1;
32112+ }
32113+#endif
32114+
32115+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32116+ do_group_exit(SIGKILL);
32117+ }
32118+
32119+ pmd = pax_get_pmd(mm, address);
32120+ if (unlikely(!pmd))
32121+ return 0;
32122+
32123+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
32124+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
32125+ pte_unmap_unlock(pte, ptl);
32126+ return 0;
32127+ }
32128+
32129+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
32130+ /* write attempt to a protected page in user mode */
32131+ pte_unmap_unlock(pte, ptl);
32132+ return 0;
32133+ }
32134+
32135+#ifdef CONFIG_SMP
32136+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
32137+#else
32138+ if (likely(address > get_limit(regs->cs)))
32139+#endif
32140+ {
32141+ set_pte(pte, pte_mkread(*pte));
32142+ __flush_tlb_one(address);
32143+ pte_unmap_unlock(pte, ptl);
32144+ up_read(&mm->mmap_sem);
32145+ return 1;
32146+ }
32147+
32148+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
32149+
32150+ /*
32151+ * PaX: fill DTLB with user rights and retry
32152+ */
32153+ __asm__ __volatile__ (
32154+ "orb %2,(%1)\n"
32155+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
32156+/*
32157+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
32158+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
32159+ * page fault when examined during a TLB load attempt. this is true not only
32160+ * for PTEs holding a non-present entry but also present entries that will
32161+ * raise a page fault (such as those set up by PaX, or the copy-on-write
32162+ * mechanism). in effect it means that we do *not* need to flush the TLBs
32163+ * for our target pages since their PTEs are simply not in the TLBs at all.
32164+
32165+ * the best thing in omitting it is that we gain around 15-20% speed in the
32166+ * fast path of the page fault handler and can get rid of tracing since we
32167+ * can no longer flush unintended entries.
32168+ */
32169+ "invlpg (%0)\n"
32170+#endif
32171+ __copyuser_seg"testb $0,(%0)\n"
32172+ "xorb %3,(%1)\n"
32173+ :
32174+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
32175+ : "memory", "cc");
32176+ pte_unmap_unlock(pte, ptl);
32177+ up_read(&mm->mmap_sem);
32178+ return 1;
32179+}
32180+#endif
32181+
32182 /*
32183 * Handle a spurious fault caused by a stale TLB entry.
32184 *
32185@@ -1006,6 +1211,9 @@ int show_unhandled_signals = 1;
32186 static inline int
32187 access_error(unsigned long error_code, struct vm_area_struct *vma)
32188 {
32189+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
32190+ return 1;
32191+
32192 if (error_code & PF_WRITE) {
32193 /* write, present and write, not present: */
32194 if (unlikely(!(vma->vm_flags & VM_WRITE)))
32195@@ -1040,7 +1248,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
32196 if (error_code & PF_USER)
32197 return false;
32198
32199- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
32200+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
32201 return false;
32202
32203 return true;
32204@@ -1068,6 +1276,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32205 tsk = current;
32206 mm = tsk->mm;
32207
32208+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32209+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
32210+ if (!search_exception_tables(regs->ip)) {
32211+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32212+ bad_area_nosemaphore(regs, error_code, address);
32213+ return;
32214+ }
32215+ if (address < pax_user_shadow_base) {
32216+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32217+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
32218+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
32219+ } else
32220+ address -= pax_user_shadow_base;
32221+ }
32222+#endif
32223+
32224 /*
32225 * Detect and handle instructions that would cause a page fault for
32226 * both a tracked kernel page and a userspace page.
32227@@ -1145,7 +1369,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32228 * User-mode registers count as a user access even for any
32229 * potential system fault or CPU buglet:
32230 */
32231- if (user_mode_vm(regs)) {
32232+ if (user_mode(regs)) {
32233 local_irq_enable();
32234 error_code |= PF_USER;
32235 flags |= FAULT_FLAG_USER;
32236@@ -1192,6 +1416,11 @@ retry:
32237 might_sleep();
32238 }
32239
32240+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32241+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
32242+ return;
32243+#endif
32244+
32245 vma = find_vma(mm, address);
32246 if (unlikely(!vma)) {
32247 bad_area(regs, error_code, address);
32248@@ -1203,18 +1432,24 @@ retry:
32249 bad_area(regs, error_code, address);
32250 return;
32251 }
32252- if (error_code & PF_USER) {
32253- /*
32254- * Accessing the stack below %sp is always a bug.
32255- * The large cushion allows instructions like enter
32256- * and pusha to work. ("enter $65535, $31" pushes
32257- * 32 pointers and then decrements %sp by 65535.)
32258- */
32259- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
32260- bad_area(regs, error_code, address);
32261- return;
32262- }
32263+ /*
32264+ * Accessing the stack below %sp is always a bug.
32265+ * The large cushion allows instructions like enter
32266+ * and pusha to work. ("enter $65535, $31" pushes
32267+ * 32 pointers and then decrements %sp by 65535.)
32268+ */
32269+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
32270+ bad_area(regs, error_code, address);
32271+ return;
32272 }
32273+
32274+#ifdef CONFIG_PAX_SEGMEXEC
32275+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
32276+ bad_area(regs, error_code, address);
32277+ return;
32278+ }
32279+#endif
32280+
32281 if (unlikely(expand_stack(vma, address))) {
32282 bad_area(regs, error_code, address);
32283 return;
32284@@ -1331,3 +1566,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
32285 }
32286 NOKPROBE_SYMBOL(trace_do_page_fault);
32287 #endif /* CONFIG_TRACING */
32288+
32289+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32290+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
32291+{
32292+ struct mm_struct *mm = current->mm;
32293+ unsigned long ip = regs->ip;
32294+
32295+ if (v8086_mode(regs))
32296+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
32297+
32298+#ifdef CONFIG_PAX_PAGEEXEC
32299+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
32300+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
32301+ return true;
32302+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
32303+ return true;
32304+ return false;
32305+ }
32306+#endif
32307+
32308+#ifdef CONFIG_PAX_SEGMEXEC
32309+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
32310+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
32311+ return true;
32312+ return false;
32313+ }
32314+#endif
32315+
32316+ return false;
32317+}
32318+#endif
32319+
32320+#ifdef CONFIG_PAX_EMUTRAMP
32321+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
32322+{
32323+ int err;
32324+
32325+ do { /* PaX: libffi trampoline emulation */
32326+ unsigned char mov, jmp;
32327+ unsigned int addr1, addr2;
32328+
32329+#ifdef CONFIG_X86_64
32330+ if ((regs->ip + 9) >> 32)
32331+ break;
32332+#endif
32333+
32334+ err = get_user(mov, (unsigned char __user *)regs->ip);
32335+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32336+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32337+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32338+
32339+ if (err)
32340+ break;
32341+
32342+ if (mov == 0xB8 && jmp == 0xE9) {
32343+ regs->ax = addr1;
32344+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32345+ return 2;
32346+ }
32347+ } while (0);
32348+
32349+ do { /* PaX: gcc trampoline emulation #1 */
32350+ unsigned char mov1, mov2;
32351+ unsigned short jmp;
32352+ unsigned int addr1, addr2;
32353+
32354+#ifdef CONFIG_X86_64
32355+ if ((regs->ip + 11) >> 32)
32356+ break;
32357+#endif
32358+
32359+ err = get_user(mov1, (unsigned char __user *)regs->ip);
32360+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32361+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
32362+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32363+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
32364+
32365+ if (err)
32366+ break;
32367+
32368+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
32369+ regs->cx = addr1;
32370+ regs->ax = addr2;
32371+ regs->ip = addr2;
32372+ return 2;
32373+ }
32374+ } while (0);
32375+
32376+ do { /* PaX: gcc trampoline emulation #2 */
32377+ unsigned char mov, jmp;
32378+ unsigned int addr1, addr2;
32379+
32380+#ifdef CONFIG_X86_64
32381+ if ((regs->ip + 9) >> 32)
32382+ break;
32383+#endif
32384+
32385+ err = get_user(mov, (unsigned char __user *)regs->ip);
32386+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32387+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32388+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32389+
32390+ if (err)
32391+ break;
32392+
32393+ if (mov == 0xB9 && jmp == 0xE9) {
32394+ regs->cx = addr1;
32395+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32396+ return 2;
32397+ }
32398+ } while (0);
32399+
32400+ return 1; /* PaX in action */
32401+}
32402+
32403+#ifdef CONFIG_X86_64
32404+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
32405+{
32406+ int err;
32407+
32408+ do { /* PaX: libffi trampoline emulation */
32409+ unsigned short mov1, mov2, jmp1;
32410+ unsigned char stcclc, jmp2;
32411+ unsigned long addr1, addr2;
32412+
32413+ err = get_user(mov1, (unsigned short __user *)regs->ip);
32414+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32415+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32416+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32417+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
32418+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
32419+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
32420+
32421+ if (err)
32422+ break;
32423+
32424+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32425+ regs->r11 = addr1;
32426+ regs->r10 = addr2;
32427+ if (stcclc == 0xF8)
32428+ regs->flags &= ~X86_EFLAGS_CF;
32429+ else
32430+ regs->flags |= X86_EFLAGS_CF;
32431+ regs->ip = addr1;
32432+ return 2;
32433+ }
32434+ } while (0);
32435+
32436+ do { /* PaX: gcc trampoline emulation #1 */
32437+ unsigned short mov1, mov2, jmp1;
32438+ unsigned char jmp2;
32439+ unsigned int addr1;
32440+ unsigned long addr2;
32441+
32442+ err = get_user(mov1, (unsigned short __user *)regs->ip);
32443+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
32444+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
32445+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
32446+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
32447+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
32448+
32449+ if (err)
32450+ break;
32451+
32452+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32453+ regs->r11 = addr1;
32454+ regs->r10 = addr2;
32455+ regs->ip = addr1;
32456+ return 2;
32457+ }
32458+ } while (0);
32459+
32460+ do { /* PaX: gcc trampoline emulation #2 */
32461+ unsigned short mov1, mov2, jmp1;
32462+ unsigned char jmp2;
32463+ unsigned long addr1, addr2;
32464+
32465+ err = get_user(mov1, (unsigned short __user *)regs->ip);
32466+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32467+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32468+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32469+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
32470+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
32471+
32472+ if (err)
32473+ break;
32474+
32475+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32476+ regs->r11 = addr1;
32477+ regs->r10 = addr2;
32478+ regs->ip = addr1;
32479+ return 2;
32480+ }
32481+ } while (0);
32482+
32483+ return 1; /* PaX in action */
32484+}
32485+#endif
32486+
32487+/*
32488+ * PaX: decide what to do with offenders (regs->ip = fault address)
32489+ *
32490+ * returns 1 when task should be killed
32491+ * 2 when gcc trampoline was detected
32492+ */
32493+static int pax_handle_fetch_fault(struct pt_regs *regs)
32494+{
32495+ if (v8086_mode(regs))
32496+ return 1;
32497+
32498+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
32499+ return 1;
32500+
32501+#ifdef CONFIG_X86_32
32502+ return pax_handle_fetch_fault_32(regs);
32503+#else
32504+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
32505+ return pax_handle_fetch_fault_32(regs);
32506+ else
32507+ return pax_handle_fetch_fault_64(regs);
32508+#endif
32509+}
32510+#endif
32511+
32512+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32513+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
32514+{
32515+ long i;
32516+
32517+ printk(KERN_ERR "PAX: bytes at PC: ");
32518+ for (i = 0; i < 20; i++) {
32519+ unsigned char c;
32520+ if (get_user(c, (unsigned char __force_user *)pc+i))
32521+ printk(KERN_CONT "?? ");
32522+ else
32523+ printk(KERN_CONT "%02x ", c);
32524+ }
32525+ printk("\n");
32526+
32527+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
32528+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
32529+ unsigned long c;
32530+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
32531+#ifdef CONFIG_X86_32
32532+ printk(KERN_CONT "???????? ");
32533+#else
32534+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
32535+ printk(KERN_CONT "???????? ???????? ");
32536+ else
32537+ printk(KERN_CONT "???????????????? ");
32538+#endif
32539+ } else {
32540+#ifdef CONFIG_X86_64
32541+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
32542+ printk(KERN_CONT "%08x ", (unsigned int)c);
32543+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
32544+ } else
32545+#endif
32546+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
32547+ }
32548+ }
32549+ printk("\n");
32550+}
32551+#endif
32552+
32553+/**
32554+ * probe_kernel_write(): safely attempt to write to a location
32555+ * @dst: address to write to
32556+ * @src: pointer to the data that shall be written
32557+ * @size: size of the data chunk
32558+ *
32559+ * Safely write to address @dst from the buffer at @src. If a kernel fault
32560+ * happens, handle that and return -EFAULT.
32561+ */
32562+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
32563+{
32564+ long ret;
32565+ mm_segment_t old_fs = get_fs();
32566+
32567+ set_fs(KERNEL_DS);
32568+ pagefault_disable();
32569+ pax_open_kernel();
32570+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
32571+ pax_close_kernel();
32572+ pagefault_enable();
32573+ set_fs(old_fs);
32574+
32575+ return ret ? -EFAULT : 0;
32576+}
32577diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
32578index 207d9aef..69030980 100644
32579--- a/arch/x86/mm/gup.c
32580+++ b/arch/x86/mm/gup.c
32581@@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
32582 addr = start;
32583 len = (unsigned long) nr_pages << PAGE_SHIFT;
32584 end = start + len;
32585- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
32586+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32587 (void __user *)start, len)))
32588 return 0;
32589
32590@@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
32591 goto slow_irqon;
32592 #endif
32593
32594+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32595+ (void __user *)start, len)))
32596+ return 0;
32597+
32598 /*
32599 * XXX: batch / limit 'nr', to avoid large irq off latency
32600 * needs some instrumenting to determine the common sizes used by
32601diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
32602index 4500142..53a363c 100644
32603--- a/arch/x86/mm/highmem_32.c
32604+++ b/arch/x86/mm/highmem_32.c
32605@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
32606 idx = type + KM_TYPE_NR*smp_processor_id();
32607 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32608 BUG_ON(!pte_none(*(kmap_pte-idx)));
32609+
32610+ pax_open_kernel();
32611 set_pte(kmap_pte-idx, mk_pte(page, prot));
32612+ pax_close_kernel();
32613+
32614 arch_flush_lazy_mmu_mode();
32615
32616 return (void *)vaddr;
32617diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
32618index 8b977eb..4732c33 100644
32619--- a/arch/x86/mm/hugetlbpage.c
32620+++ b/arch/x86/mm/hugetlbpage.c
32621@@ -80,23 +80,24 @@ int pud_huge(pud_t pud)
32622 #ifdef CONFIG_HUGETLB_PAGE
32623 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
32624 unsigned long addr, unsigned long len,
32625- unsigned long pgoff, unsigned long flags)
32626+ unsigned long pgoff, unsigned long flags, unsigned long offset)
32627 {
32628 struct hstate *h = hstate_file(file);
32629 struct vm_unmapped_area_info info;
32630-
32631+
32632 info.flags = 0;
32633 info.length = len;
32634 info.low_limit = current->mm->mmap_legacy_base;
32635 info.high_limit = TASK_SIZE;
32636 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32637 info.align_offset = 0;
32638+ info.threadstack_offset = offset;
32639 return vm_unmapped_area(&info);
32640 }
32641
32642 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32643 unsigned long addr0, unsigned long len,
32644- unsigned long pgoff, unsigned long flags)
32645+ unsigned long pgoff, unsigned long flags, unsigned long offset)
32646 {
32647 struct hstate *h = hstate_file(file);
32648 struct vm_unmapped_area_info info;
32649@@ -108,6 +109,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32650 info.high_limit = current->mm->mmap_base;
32651 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32652 info.align_offset = 0;
32653+ info.threadstack_offset = offset;
32654 addr = vm_unmapped_area(&info);
32655
32656 /*
32657@@ -120,6 +122,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32658 VM_BUG_ON(addr != -ENOMEM);
32659 info.flags = 0;
32660 info.low_limit = TASK_UNMAPPED_BASE;
32661+
32662+#ifdef CONFIG_PAX_RANDMMAP
32663+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32664+ info.low_limit += current->mm->delta_mmap;
32665+#endif
32666+
32667 info.high_limit = TASK_SIZE;
32668 addr = vm_unmapped_area(&info);
32669 }
32670@@ -134,10 +142,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32671 struct hstate *h = hstate_file(file);
32672 struct mm_struct *mm = current->mm;
32673 struct vm_area_struct *vma;
32674+ unsigned long pax_task_size = TASK_SIZE;
32675+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32676
32677 if (len & ~huge_page_mask(h))
32678 return -EINVAL;
32679- if (len > TASK_SIZE)
32680+
32681+#ifdef CONFIG_PAX_SEGMEXEC
32682+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32683+ pax_task_size = SEGMEXEC_TASK_SIZE;
32684+#endif
32685+
32686+ pax_task_size -= PAGE_SIZE;
32687+
32688+ if (len > pax_task_size)
32689 return -ENOMEM;
32690
32691 if (flags & MAP_FIXED) {
32692@@ -146,19 +164,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32693 return addr;
32694 }
32695
32696+#ifdef CONFIG_PAX_RANDMMAP
32697+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32698+#endif
32699+
32700 if (addr) {
32701 addr = ALIGN(addr, huge_page_size(h));
32702 vma = find_vma(mm, addr);
32703- if (TASK_SIZE - len >= addr &&
32704- (!vma || addr + len <= vma->vm_start))
32705+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32706 return addr;
32707 }
32708 if (mm->get_unmapped_area == arch_get_unmapped_area)
32709 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32710- pgoff, flags);
32711+ pgoff, flags, offset);
32712 else
32713 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32714- pgoff, flags);
32715+ pgoff, flags, offset);
32716 }
32717 #endif /* CONFIG_HUGETLB_PAGE */
32718
32719diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32720index 66dba36..f8082ec 100644
32721--- a/arch/x86/mm/init.c
32722+++ b/arch/x86/mm/init.c
32723@@ -4,6 +4,7 @@
32724 #include <linux/swap.h>
32725 #include <linux/memblock.h>
32726 #include <linux/bootmem.h> /* for max_low_pfn */
32727+#include <linux/tboot.h>
32728
32729 #include <asm/cacheflush.h>
32730 #include <asm/e820.h>
32731@@ -17,6 +18,8 @@
32732 #include <asm/proto.h>
32733 #include <asm/dma.h> /* for MAX_DMA_PFN */
32734 #include <asm/microcode.h>
32735+#include <asm/desc.h>
32736+#include <asm/bios_ebda.h>
32737
32738 /*
32739 * We need to define the tracepoints somewhere, and tlb.c
32740@@ -570,7 +573,18 @@ void __init init_mem_mapping(void)
32741 early_ioremap_page_table_range_init();
32742 #endif
32743
32744+#ifdef CONFIG_PAX_PER_CPU_PGD
32745+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32746+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32747+ KERNEL_PGD_PTRS);
32748+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32749+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32750+ KERNEL_PGD_PTRS);
32751+ load_cr3(get_cpu_pgd(0, kernel));
32752+#else
32753 load_cr3(swapper_pg_dir);
32754+#endif
32755+
32756 __flush_tlb_all();
32757
32758 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32759@@ -586,10 +600,40 @@ void __init init_mem_mapping(void)
32760 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32761 * mmio resources as well as potential bios/acpi data regions.
32762 */
32763+
32764+#ifdef CONFIG_GRKERNSEC_KMEM
32765+static unsigned int ebda_start __read_only;
32766+static unsigned int ebda_end __read_only;
32767+#endif
32768+
32769 int devmem_is_allowed(unsigned long pagenr)
32770 {
32771- if (pagenr < 256)
32772+#ifdef CONFIG_GRKERNSEC_KMEM
32773+ /* allow BDA */
32774+ if (!pagenr)
32775 return 1;
32776+ /* allow EBDA */
32777+ if (pagenr >= ebda_start && pagenr < ebda_end)
32778+ return 1;
32779+ /* if tboot is in use, allow access to its hardcoded serial log range */
32780+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32781+ return 1;
32782+#else
32783+ if (!pagenr)
32784+ return 1;
32785+#ifdef CONFIG_VM86
32786+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32787+ return 1;
32788+#endif
32789+#endif
32790+
32791+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32792+ return 1;
32793+#ifdef CONFIG_GRKERNSEC_KMEM
32794+ /* throw out everything else below 1MB */
32795+ if (pagenr <= 256)
32796+ return 0;
32797+#endif
32798 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32799 return 0;
32800 if (!page_is_ram(pagenr))
32801@@ -635,8 +679,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32802 #endif
32803 }
32804
32805+#ifdef CONFIG_GRKERNSEC_KMEM
32806+static inline void gr_init_ebda(void)
32807+{
32808+ unsigned int ebda_addr;
32809+ unsigned int ebda_size = 0;
32810+
32811+ ebda_addr = get_bios_ebda();
32812+ if (ebda_addr) {
32813+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32814+ ebda_size <<= 10;
32815+ }
32816+ if (ebda_addr && ebda_size) {
32817+ ebda_start = ebda_addr >> PAGE_SHIFT;
32818+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32819+ } else {
32820+ ebda_start = 0x9f000 >> PAGE_SHIFT;
32821+ ebda_end = 0xa0000 >> PAGE_SHIFT;
32822+ }
32823+}
32824+#else
32825+static inline void gr_init_ebda(void) { }
32826+#endif
32827+
32828 void free_initmem(void)
32829 {
32830+#ifdef CONFIG_PAX_KERNEXEC
32831+#ifdef CONFIG_X86_32
32832+ /* PaX: limit KERNEL_CS to actual size */
32833+ unsigned long addr, limit;
32834+ struct desc_struct d;
32835+ int cpu;
32836+#else
32837+ pgd_t *pgd;
32838+ pud_t *pud;
32839+ pmd_t *pmd;
32840+ unsigned long addr, end;
32841+#endif
32842+#endif
32843+
32844+ gr_init_ebda();
32845+
32846+#ifdef CONFIG_PAX_KERNEXEC
32847+#ifdef CONFIG_X86_32
32848+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32849+ limit = (limit - 1UL) >> PAGE_SHIFT;
32850+
32851+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32852+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32853+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32854+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32855+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32856+ }
32857+
32858+ /* PaX: make KERNEL_CS read-only */
32859+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32860+ if (!paravirt_enabled())
32861+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32862+/*
32863+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32864+ pgd = pgd_offset_k(addr);
32865+ pud = pud_offset(pgd, addr);
32866+ pmd = pmd_offset(pud, addr);
32867+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32868+ }
32869+*/
32870+#ifdef CONFIG_X86_PAE
32871+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32872+/*
32873+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32874+ pgd = pgd_offset_k(addr);
32875+ pud = pud_offset(pgd, addr);
32876+ pmd = pmd_offset(pud, addr);
32877+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32878+ }
32879+*/
32880+#endif
32881+
32882+#ifdef CONFIG_MODULES
32883+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32884+#endif
32885+
32886+#else
32887+ /* PaX: make kernel code/rodata read-only, rest non-executable */
32888+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32889+ pgd = pgd_offset_k(addr);
32890+ pud = pud_offset(pgd, addr);
32891+ pmd = pmd_offset(pud, addr);
32892+ if (!pmd_present(*pmd))
32893+ continue;
32894+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32895+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32896+ else
32897+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32898+ }
32899+
32900+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32901+ end = addr + KERNEL_IMAGE_SIZE;
32902+ for (; addr < end; addr += PMD_SIZE) {
32903+ pgd = pgd_offset_k(addr);
32904+ pud = pud_offset(pgd, addr);
32905+ pmd = pmd_offset(pud, addr);
32906+ if (!pmd_present(*pmd))
32907+ continue;
32908+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32909+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32910+ }
32911+#endif
32912+
32913+ flush_tlb_all();
32914+#endif
32915+
32916 free_init_pages("unused kernel",
32917 (unsigned long)(&__init_begin),
32918 (unsigned long)(&__init_end));
32919diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32920index c8140e1..59257fc 100644
32921--- a/arch/x86/mm/init_32.c
32922+++ b/arch/x86/mm/init_32.c
32923@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32924 bool __read_mostly __vmalloc_start_set = false;
32925
32926 /*
32927- * Creates a middle page table and puts a pointer to it in the
32928- * given global directory entry. This only returns the gd entry
32929- * in non-PAE compilation mode, since the middle layer is folded.
32930- */
32931-static pmd_t * __init one_md_table_init(pgd_t *pgd)
32932-{
32933- pud_t *pud;
32934- pmd_t *pmd_table;
32935-
32936-#ifdef CONFIG_X86_PAE
32937- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32938- pmd_table = (pmd_t *)alloc_low_page();
32939- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32940- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32941- pud = pud_offset(pgd, 0);
32942- BUG_ON(pmd_table != pmd_offset(pud, 0));
32943-
32944- return pmd_table;
32945- }
32946-#endif
32947- pud = pud_offset(pgd, 0);
32948- pmd_table = pmd_offset(pud, 0);
32949-
32950- return pmd_table;
32951-}
32952-
32953-/*
32954 * Create a page table and place a pointer to it in a middle page
32955 * directory entry:
32956 */
32957@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32958 pte_t *page_table = (pte_t *)alloc_low_page();
32959
32960 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32961+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32962+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32963+#else
32964 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32965+#endif
32966 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32967 }
32968
32969 return pte_offset_kernel(pmd, 0);
32970 }
32971
32972+static pmd_t * __init one_md_table_init(pgd_t *pgd)
32973+{
32974+ pud_t *pud;
32975+ pmd_t *pmd_table;
32976+
32977+ pud = pud_offset(pgd, 0);
32978+ pmd_table = pmd_offset(pud, 0);
32979+
32980+ return pmd_table;
32981+}
32982+
32983 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32984 {
32985 int pgd_idx = pgd_index(vaddr);
32986@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32987 int pgd_idx, pmd_idx;
32988 unsigned long vaddr;
32989 pgd_t *pgd;
32990+ pud_t *pud;
32991 pmd_t *pmd;
32992 pte_t *pte = NULL;
32993 unsigned long count = page_table_range_init_count(start, end);
32994@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32995 pgd = pgd_base + pgd_idx;
32996
32997 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32998- pmd = one_md_table_init(pgd);
32999- pmd = pmd + pmd_index(vaddr);
33000+ pud = pud_offset(pgd, vaddr);
33001+ pmd = pmd_offset(pud, vaddr);
33002+
33003+#ifdef CONFIG_X86_PAE
33004+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
33005+#endif
33006+
33007 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
33008 pmd++, pmd_idx++) {
33009 pte = page_table_kmap_check(one_page_table_init(pmd),
33010@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33011 }
33012 }
33013
33014-static inline int is_kernel_text(unsigned long addr)
33015+static inline int is_kernel_text(unsigned long start, unsigned long end)
33016 {
33017- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
33018- return 1;
33019- return 0;
33020+ if ((start >= ktla_ktva((unsigned long)_etext) ||
33021+ end <= ktla_ktva((unsigned long)_stext)) &&
33022+ (start >= ktla_ktva((unsigned long)_einittext) ||
33023+ end <= ktla_ktva((unsigned long)_sinittext)) &&
33024+
33025+#ifdef CONFIG_ACPI_SLEEP
33026+ (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
33027+#endif
33028+
33029+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
33030+ return 0;
33031+ return 1;
33032 }
33033
33034 /*
33035@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
33036 unsigned long last_map_addr = end;
33037 unsigned long start_pfn, end_pfn;
33038 pgd_t *pgd_base = swapper_pg_dir;
33039- int pgd_idx, pmd_idx, pte_ofs;
33040+ unsigned int pgd_idx, pmd_idx, pte_ofs;
33041 unsigned long pfn;
33042 pgd_t *pgd;
33043+ pud_t *pud;
33044 pmd_t *pmd;
33045 pte_t *pte;
33046 unsigned pages_2m, pages_4k;
33047@@ -291,8 +295,13 @@ repeat:
33048 pfn = start_pfn;
33049 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33050 pgd = pgd_base + pgd_idx;
33051- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
33052- pmd = one_md_table_init(pgd);
33053+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
33054+ pud = pud_offset(pgd, 0);
33055+ pmd = pmd_offset(pud, 0);
33056+
33057+#ifdef CONFIG_X86_PAE
33058+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
33059+#endif
33060
33061 if (pfn >= end_pfn)
33062 continue;
33063@@ -304,14 +313,13 @@ repeat:
33064 #endif
33065 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
33066 pmd++, pmd_idx++) {
33067- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
33068+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
33069
33070 /*
33071 * Map with big pages if possible, otherwise
33072 * create normal page tables:
33073 */
33074 if (use_pse) {
33075- unsigned int addr2;
33076 pgprot_t prot = PAGE_KERNEL_LARGE;
33077 /*
33078 * first pass will use the same initial
33079@@ -322,11 +330,7 @@ repeat:
33080 _PAGE_PSE);
33081
33082 pfn &= PMD_MASK >> PAGE_SHIFT;
33083- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
33084- PAGE_OFFSET + PAGE_SIZE-1;
33085-
33086- if (is_kernel_text(addr) ||
33087- is_kernel_text(addr2))
33088+ if (is_kernel_text(address, address + PMD_SIZE))
33089 prot = PAGE_KERNEL_LARGE_EXEC;
33090
33091 pages_2m++;
33092@@ -343,7 +347,7 @@ repeat:
33093 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33094 pte += pte_ofs;
33095 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
33096- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
33097+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
33098 pgprot_t prot = PAGE_KERNEL;
33099 /*
33100 * first pass will use the same initial
33101@@ -351,7 +355,7 @@ repeat:
33102 */
33103 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
33104
33105- if (is_kernel_text(addr))
33106+ if (is_kernel_text(address, address + PAGE_SIZE))
33107 prot = PAGE_KERNEL_EXEC;
33108
33109 pages_4k++;
33110@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
33111
33112 pud = pud_offset(pgd, va);
33113 pmd = pmd_offset(pud, va);
33114- if (!pmd_present(*pmd))
33115+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
33116 break;
33117
33118 /* should not be large page here */
33119@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
33120
33121 static void __init pagetable_init(void)
33122 {
33123- pgd_t *pgd_base = swapper_pg_dir;
33124-
33125- permanent_kmaps_init(pgd_base);
33126+ permanent_kmaps_init(swapper_pg_dir);
33127 }
33128
33129-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL);
33130+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL);
33131 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33132
33133 /* user-defined highmem size */
33134@@ -787,10 +789,10 @@ void __init mem_init(void)
33135 ((unsigned long)&__init_end -
33136 (unsigned long)&__init_begin) >> 10,
33137
33138- (unsigned long)&_etext, (unsigned long)&_edata,
33139- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
33140+ (unsigned long)&_sdata, (unsigned long)&_edata,
33141+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
33142
33143- (unsigned long)&_text, (unsigned long)&_etext,
33144+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
33145 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
33146
33147 /*
33148@@ -884,6 +886,7 @@ void set_kernel_text_rw(void)
33149 if (!kernel_set_to_readonly)
33150 return;
33151
33152+ start = ktla_ktva(start);
33153 pr_debug("Set kernel text: %lx - %lx for read write\n",
33154 start, start+size);
33155
33156@@ -898,6 +901,7 @@ void set_kernel_text_ro(void)
33157 if (!kernel_set_to_readonly)
33158 return;
33159
33160+ start = ktla_ktva(start);
33161 pr_debug("Set kernel text: %lx - %lx for read only\n",
33162 start, start+size);
33163
33164@@ -926,6 +930,7 @@ void mark_rodata_ro(void)
33165 unsigned long start = PFN_ALIGN(_text);
33166 unsigned long size = PFN_ALIGN(_etext) - start;
33167
33168+ start = ktla_ktva(start);
33169 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
33170 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
33171 size >> 10);
33172diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
33173index 4e5dfec..6fd6dc5 100644
33174--- a/arch/x86/mm/init_64.c
33175+++ b/arch/x86/mm/init_64.c
33176@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
33177 * around without checking the pgd every time.
33178 */
33179
33180-pteval_t __supported_pte_mask __read_mostly = ~0;
33181+pteval_t __supported_pte_mask __read_only = ~_PAGE_NX;
33182 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33183
33184 int force_personality32;
33185@@ -184,7 +184,12 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33186
33187 for (address = start; address <= end; address += PGDIR_SIZE) {
33188 const pgd_t *pgd_ref = pgd_offset_k(address);
33189+
33190+#ifdef CONFIG_PAX_PER_CPU_PGD
33191+ unsigned long cpu;
33192+#else
33193 struct page *page;
33194+#endif
33195
33196 /*
33197 * When it is called after memory hot remove, pgd_none()
33198@@ -195,6 +200,25 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33199 continue;
33200
33201 spin_lock(&pgd_lock);
33202+
33203+#ifdef CONFIG_PAX_PER_CPU_PGD
33204+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33205+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
33206+
33207+ if (!pgd_none(*pgd_ref) && !pgd_none(*pgd))
33208+ BUG_ON(pgd_page_vaddr(*pgd)
33209+ != pgd_page_vaddr(*pgd_ref));
33210+
33211+ if (removed) {
33212+ if (pgd_none(*pgd_ref) && !pgd_none(*pgd))
33213+ pgd_clear(pgd);
33214+ } else {
33215+ if (pgd_none(*pgd))
33216+ set_pgd(pgd, *pgd_ref);
33217+ }
33218+
33219+ pgd = pgd_offset_cpu(cpu, kernel, address);
33220+#else
33221 list_for_each_entry(page, &pgd_list, lru) {
33222 pgd_t *pgd;
33223 spinlock_t *pgt_lock;
33224@@ -203,6 +227,7 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33225 /* the pgt_lock only for Xen */
33226 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
33227 spin_lock(pgt_lock);
33228+#endif
33229
33230 if (!pgd_none(*pgd_ref) && !pgd_none(*pgd))
33231 BUG_ON(pgd_page_vaddr(*pgd)
33232@@ -216,7 +241,10 @@ void sync_global_pgds(unsigned long start, unsigned long end, int removed)
33233 set_pgd(pgd, *pgd_ref);
33234 }
33235
33236+#ifndef CONFIG_PAX_PER_CPU_PGD
33237 spin_unlock(pgt_lock);
33238+#endif
33239+
33240 }
33241 spin_unlock(&pgd_lock);
33242 }
33243@@ -249,7 +277,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
33244 {
33245 if (pgd_none(*pgd)) {
33246 pud_t *pud = (pud_t *)spp_getpage();
33247- pgd_populate(&init_mm, pgd, pud);
33248+ pgd_populate_kernel(&init_mm, pgd, pud);
33249 if (pud != pud_offset(pgd, 0))
33250 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
33251 pud, pud_offset(pgd, 0));
33252@@ -261,7 +289,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
33253 {
33254 if (pud_none(*pud)) {
33255 pmd_t *pmd = (pmd_t *) spp_getpage();
33256- pud_populate(&init_mm, pud, pmd);
33257+ pud_populate_kernel(&init_mm, pud, pmd);
33258 if (pmd != pmd_offset(pud, 0))
33259 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
33260 pmd, pmd_offset(pud, 0));
33261@@ -290,7 +318,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
33262 pmd = fill_pmd(pud, vaddr);
33263 pte = fill_pte(pmd, vaddr);
33264
33265+ pax_open_kernel();
33266 set_pte(pte, new_pte);
33267+ pax_close_kernel();
33268
33269 /*
33270 * It's enough to flush this one mapping.
33271@@ -349,14 +379,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
33272 pgd = pgd_offset_k((unsigned long)__va(phys));
33273 if (pgd_none(*pgd)) {
33274 pud = (pud_t *) spp_getpage();
33275- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
33276- _PAGE_USER));
33277+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
33278 }
33279 pud = pud_offset(pgd, (unsigned long)__va(phys));
33280 if (pud_none(*pud)) {
33281 pmd = (pmd_t *) spp_getpage();
33282- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
33283- _PAGE_USER));
33284+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
33285 }
33286 pmd = pmd_offset(pud, phys);
33287 BUG_ON(!pmd_none(*pmd));
33288@@ -597,7 +625,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
33289 prot);
33290
33291 spin_lock(&init_mm.page_table_lock);
33292- pud_populate(&init_mm, pud, pmd);
33293+ pud_populate_kernel(&init_mm, pud, pmd);
33294 spin_unlock(&init_mm.page_table_lock);
33295 }
33296 __flush_tlb_all();
33297@@ -638,7 +666,7 @@ kernel_physical_mapping_init(unsigned long start,
33298 page_size_mask);
33299
33300 spin_lock(&init_mm.page_table_lock);
33301- pgd_populate(&init_mm, pgd, pud);
33302+ pgd_populate_kernel(&init_mm, pgd, pud);
33303 spin_unlock(&init_mm.page_table_lock);
33304 pgd_changed = true;
33305 }
33306@@ -1217,8 +1245,8 @@ static struct vm_operations_struct gate_vma_ops = {
33307 static struct vm_area_struct gate_vma = {
33308 .vm_start = VSYSCALL_ADDR,
33309 .vm_end = VSYSCALL_ADDR + PAGE_SIZE,
33310- .vm_page_prot = PAGE_READONLY_EXEC,
33311- .vm_flags = VM_READ | VM_EXEC,
33312+ .vm_page_prot = PAGE_READONLY,
33313+ .vm_flags = VM_READ,
33314 .vm_ops = &gate_vma_ops,
33315 };
33316
33317diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
33318index 7b179b49..6bd17777 100644
33319--- a/arch/x86/mm/iomap_32.c
33320+++ b/arch/x86/mm/iomap_32.c
33321@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
33322 type = kmap_atomic_idx_push();
33323 idx = type + KM_TYPE_NR * smp_processor_id();
33324 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
33325+
33326+ pax_open_kernel();
33327 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
33328+ pax_close_kernel();
33329+
33330 arch_flush_lazy_mmu_mode();
33331
33332 return (void *)vaddr;
33333diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
33334index af78e50..0790b03 100644
33335--- a/arch/x86/mm/ioremap.c
33336+++ b/arch/x86/mm/ioremap.c
33337@@ -56,8 +56,8 @@ static int __ioremap_check_ram(unsigned long start_pfn, unsigned long nr_pages,
33338 unsigned long i;
33339
33340 for (i = 0; i < nr_pages; ++i)
33341- if (pfn_valid(start_pfn + i) &&
33342- !PageReserved(pfn_to_page(start_pfn + i)))
33343+ if (pfn_valid(start_pfn + i) && (start_pfn + i >= 0x100 ||
33344+ !PageReserved(pfn_to_page(start_pfn + i))))
33345 return 1;
33346
33347 WARN_ONCE(1, "ioremap on RAM pfn 0x%lx\n", start_pfn);
33348@@ -280,7 +280,7 @@ EXPORT_SYMBOL(ioremap_prot);
33349 *
33350 * Caller must ensure there is only one unmapping for the same pointer.
33351 */
33352-void iounmap(volatile void __iomem *addr)
33353+void iounmap(const volatile void __iomem *addr)
33354 {
33355 struct vm_struct *p, *o;
33356
33357@@ -334,6 +334,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33358
33359 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
33360 if (page_is_ram(start >> PAGE_SHIFT))
33361+#ifdef CONFIG_HIGHMEM
33362+ if ((start >> PAGE_SHIFT) < max_low_pfn)
33363+#endif
33364 return __va(phys);
33365
33366 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
33367@@ -346,13 +349,16 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33368 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
33369 {
33370 if (page_is_ram(phys >> PAGE_SHIFT))
33371+#ifdef CONFIG_HIGHMEM
33372+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
33373+#endif
33374 return;
33375
33376 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
33377 return;
33378 }
33379
33380-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
33381+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
33382
33383 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
33384 {
33385@@ -388,8 +394,7 @@ void __init early_ioremap_init(void)
33386 early_ioremap_setup();
33387
33388 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
33389- memset(bm_pte, 0, sizeof(bm_pte));
33390- pmd_populate_kernel(&init_mm, pmd, bm_pte);
33391+ pmd_populate_user(&init_mm, pmd, bm_pte);
33392
33393 /*
33394 * The boot-ioremap range spans multiple pmds, for which
33395diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
33396index b4f2e7e..96c9c3e 100644
33397--- a/arch/x86/mm/kmemcheck/kmemcheck.c
33398+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
33399@@ -628,9 +628,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
33400 * memory (e.g. tracked pages)? For now, we need this to avoid
33401 * invoking kmemcheck for PnP BIOS calls.
33402 */
33403- if (regs->flags & X86_VM_MASK)
33404+ if (v8086_mode(regs))
33405 return false;
33406- if (regs->cs != __KERNEL_CS)
33407+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
33408 return false;
33409
33410 pte = kmemcheck_pte_lookup(address);
33411diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
33412index 919b912..9267313 100644
33413--- a/arch/x86/mm/mmap.c
33414+++ b/arch/x86/mm/mmap.c
33415@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
33416 * Leave an at least ~128 MB hole with possible stack randomization.
33417 */
33418 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
33419-#define MAX_GAP (TASK_SIZE/6*5)
33420+#define MAX_GAP (pax_task_size/6*5)
33421
33422 static int mmap_is_legacy(void)
33423 {
33424@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
33425 return rnd << PAGE_SHIFT;
33426 }
33427
33428-static unsigned long mmap_base(void)
33429+static unsigned long mmap_base(struct mm_struct *mm)
33430 {
33431 unsigned long gap = rlimit(RLIMIT_STACK);
33432+ unsigned long pax_task_size = TASK_SIZE;
33433+
33434+#ifdef CONFIG_PAX_SEGMEXEC
33435+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
33436+ pax_task_size = SEGMEXEC_TASK_SIZE;
33437+#endif
33438
33439 if (gap < MIN_GAP)
33440 gap = MIN_GAP;
33441 else if (gap > MAX_GAP)
33442 gap = MAX_GAP;
33443
33444- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
33445+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
33446 }
33447
33448 /*
33449 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
33450 * does, but not when emulating X86_32
33451 */
33452-static unsigned long mmap_legacy_base(void)
33453+static unsigned long mmap_legacy_base(struct mm_struct *mm)
33454 {
33455- if (mmap_is_ia32())
33456+ if (mmap_is_ia32()) {
33457+
33458+#ifdef CONFIG_PAX_SEGMEXEC
33459+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
33460+ return SEGMEXEC_TASK_UNMAPPED_BASE;
33461+ else
33462+#endif
33463+
33464 return TASK_UNMAPPED_BASE;
33465- else
33466+ } else
33467 return TASK_UNMAPPED_BASE + mmap_rnd();
33468 }
33469
33470@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
33471 */
33472 void arch_pick_mmap_layout(struct mm_struct *mm)
33473 {
33474- mm->mmap_legacy_base = mmap_legacy_base();
33475- mm->mmap_base = mmap_base();
33476+ mm->mmap_legacy_base = mmap_legacy_base(mm);
33477+ mm->mmap_base = mmap_base(mm);
33478+
33479+#ifdef CONFIG_PAX_RANDMMAP
33480+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
33481+ mm->mmap_legacy_base += mm->delta_mmap;
33482+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
33483+ }
33484+#endif
33485
33486 if (mmap_is_legacy()) {
33487 mm->mmap_base = mm->mmap_legacy_base;
33488diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
33489index 0057a7a..95c7edd 100644
33490--- a/arch/x86/mm/mmio-mod.c
33491+++ b/arch/x86/mm/mmio-mod.c
33492@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
33493 break;
33494 default:
33495 {
33496- unsigned char *ip = (unsigned char *)instptr;
33497+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
33498 my_trace->opcode = MMIO_UNKNOWN_OP;
33499 my_trace->width = 0;
33500 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
33501@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
33502 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33503 void __iomem *addr)
33504 {
33505- static atomic_t next_id;
33506+ static atomic_unchecked_t next_id;
33507 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
33508 /* These are page-unaligned. */
33509 struct mmiotrace_map map = {
33510@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33511 .private = trace
33512 },
33513 .phys = offset,
33514- .id = atomic_inc_return(&next_id)
33515+ .id = atomic_inc_return_unchecked(&next_id)
33516 };
33517 map.map_id = trace->id;
33518
33519@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
33520 ioremap_trace_core(offset, size, addr);
33521 }
33522
33523-static void iounmap_trace_core(volatile void __iomem *addr)
33524+static void iounmap_trace_core(const volatile void __iomem *addr)
33525 {
33526 struct mmiotrace_map map = {
33527 .phys = 0,
33528@@ -328,7 +328,7 @@ not_enabled:
33529 }
33530 }
33531
33532-void mmiotrace_iounmap(volatile void __iomem *addr)
33533+void mmiotrace_iounmap(const volatile void __iomem *addr)
33534 {
33535 might_sleep();
33536 if (is_enabled()) /* recheck and proper locking in *_core() */
33537diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
33538index 1a88370..3f598b5 100644
33539--- a/arch/x86/mm/numa.c
33540+++ b/arch/x86/mm/numa.c
33541@@ -499,7 +499,7 @@ static void __init numa_clear_kernel_node_hotplug(void)
33542 }
33543 }
33544
33545-static int __init numa_register_memblks(struct numa_meminfo *mi)
33546+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
33547 {
33548 unsigned long uninitialized_var(pfn_align);
33549 int i, nid;
33550diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
33551index 36de293..b820ddc 100644
33552--- a/arch/x86/mm/pageattr.c
33553+++ b/arch/x86/mm/pageattr.c
33554@@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33555 */
33556 #ifdef CONFIG_PCI_BIOS
33557 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
33558- pgprot_val(forbidden) |= _PAGE_NX;
33559+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33560 #endif
33561
33562 /*
33563@@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33564 * Does not cover __inittext since that is gone later on. On
33565 * 64bit we do not enforce !NX on the low mapping
33566 */
33567- if (within(address, (unsigned long)_text, (unsigned long)_etext))
33568- pgprot_val(forbidden) |= _PAGE_NX;
33569+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
33570+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33571
33572+#ifdef CONFIG_DEBUG_RODATA
33573 /*
33574 * The .rodata section needs to be read-only. Using the pfn
33575 * catches all aliases.
33576@@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33577 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
33578 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
33579 pgprot_val(forbidden) |= _PAGE_RW;
33580+#endif
33581
33582 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
33583 /*
33584@@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33585 }
33586 #endif
33587
33588+#ifdef CONFIG_PAX_KERNEXEC
33589+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
33590+ pgprot_val(forbidden) |= _PAGE_RW;
33591+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33592+ }
33593+#endif
33594+
33595 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
33596
33597 return prot;
33598@@ -420,23 +429,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
33599 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
33600 {
33601 /* change init_mm */
33602+ pax_open_kernel();
33603 set_pte_atomic(kpte, pte);
33604+
33605 #ifdef CONFIG_X86_32
33606 if (!SHARED_KERNEL_PMD) {
33607+
33608+#ifdef CONFIG_PAX_PER_CPU_PGD
33609+ unsigned long cpu;
33610+#else
33611 struct page *page;
33612+#endif
33613
33614+#ifdef CONFIG_PAX_PER_CPU_PGD
33615+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33616+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
33617+#else
33618 list_for_each_entry(page, &pgd_list, lru) {
33619- pgd_t *pgd;
33620+ pgd_t *pgd = (pgd_t *)page_address(page);
33621+#endif
33622+
33623 pud_t *pud;
33624 pmd_t *pmd;
33625
33626- pgd = (pgd_t *)page_address(page) + pgd_index(address);
33627+ pgd += pgd_index(address);
33628 pud = pud_offset(pgd, address);
33629 pmd = pmd_offset(pud, address);
33630 set_pte_atomic((pte_t *)pmd, pte);
33631 }
33632 }
33633 #endif
33634+ pax_close_kernel();
33635 }
33636
33637 static int
33638diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33639index 6574388..87e9bef 100644
33640--- a/arch/x86/mm/pat.c
33641+++ b/arch/x86/mm/pat.c
33642@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33643
33644 if (!entry) {
33645 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33646- current->comm, current->pid, start, end - 1);
33647+ current->comm, task_pid_nr(current), start, end - 1);
33648 return -EINVAL;
33649 }
33650
33651@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33652
33653 while (cursor < to) {
33654 if (!devmem_is_allowed(pfn)) {
33655- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33656- current->comm, from, to - 1);
33657+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33658+ current->comm, from, to - 1, cursor);
33659 return 0;
33660 }
33661 cursor += PAGE_SIZE;
33662@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33663 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33664 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33665 "for [mem %#010Lx-%#010Lx]\n",
33666- current->comm, current->pid,
33667+ current->comm, task_pid_nr(current),
33668 cattr_name(flags),
33669 base, (unsigned long long)(base + size-1));
33670 return -EINVAL;
33671@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33672 flags = lookup_memtype(paddr);
33673 if (want_flags != flags) {
33674 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33675- current->comm, current->pid,
33676+ current->comm, task_pid_nr(current),
33677 cattr_name(want_flags),
33678 (unsigned long long)paddr,
33679 (unsigned long long)(paddr + size - 1),
33680@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33681 free_memtype(paddr, paddr + size);
33682 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33683 " for [mem %#010Lx-%#010Lx], got %s\n",
33684- current->comm, current->pid,
33685+ current->comm, task_pid_nr(current),
33686 cattr_name(want_flags),
33687 (unsigned long long)paddr,
33688 (unsigned long long)(paddr + size - 1),
33689diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33690index 415f6c4..d319983 100644
33691--- a/arch/x86/mm/pat_rbtree.c
33692+++ b/arch/x86/mm/pat_rbtree.c
33693@@ -160,7 +160,7 @@ success:
33694
33695 failure:
33696 printk(KERN_INFO "%s:%d conflicting memory types "
33697- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33698+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33699 end, cattr_name(found_type), cattr_name(match->type));
33700 return -EBUSY;
33701 }
33702diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33703index 9f0614d..92ae64a 100644
33704--- a/arch/x86/mm/pf_in.c
33705+++ b/arch/x86/mm/pf_in.c
33706@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33707 int i;
33708 enum reason_type rv = OTHERS;
33709
33710- p = (unsigned char *)ins_addr;
33711+ p = (unsigned char *)ktla_ktva(ins_addr);
33712 p += skip_prefix(p, &prf);
33713 p += get_opcode(p, &opcode);
33714
33715@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33716 struct prefix_bits prf;
33717 int i;
33718
33719- p = (unsigned char *)ins_addr;
33720+ p = (unsigned char *)ktla_ktva(ins_addr);
33721 p += skip_prefix(p, &prf);
33722 p += get_opcode(p, &opcode);
33723
33724@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33725 struct prefix_bits prf;
33726 int i;
33727
33728- p = (unsigned char *)ins_addr;
33729+ p = (unsigned char *)ktla_ktva(ins_addr);
33730 p += skip_prefix(p, &prf);
33731 p += get_opcode(p, &opcode);
33732
33733@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33734 struct prefix_bits prf;
33735 int i;
33736
33737- p = (unsigned char *)ins_addr;
33738+ p = (unsigned char *)ktla_ktva(ins_addr);
33739 p += skip_prefix(p, &prf);
33740 p += get_opcode(p, &opcode);
33741 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33742@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33743 struct prefix_bits prf;
33744 int i;
33745
33746- p = (unsigned char *)ins_addr;
33747+ p = (unsigned char *)ktla_ktva(ins_addr);
33748 p += skip_prefix(p, &prf);
33749 p += get_opcode(p, &opcode);
33750 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33751diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33752index 6fb6927..4fc13c0 100644
33753--- a/arch/x86/mm/pgtable.c
33754+++ b/arch/x86/mm/pgtable.c
33755@@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33756 list_del(&page->lru);
33757 }
33758
33759-#define UNSHARED_PTRS_PER_PGD \
33760- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33761+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33762+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33763
33764+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33765+{
33766+ unsigned int count = USER_PGD_PTRS;
33767
33768+ if (!pax_user_shadow_base)
33769+ return;
33770+
33771+ while (count--)
33772+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33773+}
33774+#endif
33775+
33776+#ifdef CONFIG_PAX_PER_CPU_PGD
33777+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33778+{
33779+ unsigned int count = USER_PGD_PTRS;
33780+
33781+ while (count--) {
33782+ pgd_t pgd;
33783+
33784+#ifdef CONFIG_X86_64
33785+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33786+#else
33787+ pgd = *src++;
33788+#endif
33789+
33790+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33791+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33792+#endif
33793+
33794+ *dst++ = pgd;
33795+ }
33796+
33797+}
33798+#endif
33799+
33800+#ifdef CONFIG_X86_64
33801+#define pxd_t pud_t
33802+#define pyd_t pgd_t
33803+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33804+#define pgtable_pxd_page_ctor(page) true
33805+#define pgtable_pxd_page_dtor(page)
33806+#define pxd_free(mm, pud) pud_free((mm), (pud))
33807+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33808+#define pyd_offset(mm, address) pgd_offset((mm), (address))
33809+#define PYD_SIZE PGDIR_SIZE
33810+#else
33811+#define pxd_t pmd_t
33812+#define pyd_t pud_t
33813+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33814+#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33815+#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33816+#define pxd_free(mm, pud) pmd_free((mm), (pud))
33817+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33818+#define pyd_offset(mm, address) pud_offset((mm), (address))
33819+#define PYD_SIZE PUD_SIZE
33820+#endif
33821+
33822+#ifdef CONFIG_PAX_PER_CPU_PGD
33823+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33824+static inline void pgd_dtor(pgd_t *pgd) {}
33825+#else
33826 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33827 {
33828 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33829@@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33830 pgd_list_del(pgd);
33831 spin_unlock(&pgd_lock);
33832 }
33833+#endif
33834
33835 /*
33836 * List of all pgd's needed for non-PAE so it can invalidate entries
33837@@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33838 * -- nyc
33839 */
33840
33841-#ifdef CONFIG_X86_PAE
33842+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33843 /*
33844 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33845 * updating the top-level pagetable entries to guarantee the
33846@@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33847 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33848 * and initialize the kernel pmds here.
33849 */
33850-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33851+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33852
33853 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33854 {
33855@@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33856 */
33857 flush_tlb_mm(mm);
33858 }
33859+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33860+#define PREALLOCATED_PXDS USER_PGD_PTRS
33861 #else /* !CONFIG_X86_PAE */
33862
33863 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33864-#define PREALLOCATED_PMDS 0
33865+#define PREALLOCATED_PXDS 0
33866
33867 #endif /* CONFIG_X86_PAE */
33868
33869-static void free_pmds(pmd_t *pmds[])
33870+static void free_pxds(pxd_t *pxds[])
33871 {
33872 int i;
33873
33874- for(i = 0; i < PREALLOCATED_PMDS; i++)
33875- if (pmds[i]) {
33876- pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33877- free_page((unsigned long)pmds[i]);
33878+ for(i = 0; i < PREALLOCATED_PXDS; i++)
33879+ if (pxds[i]) {
33880+ pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33881+ free_page((unsigned long)pxds[i]);
33882 }
33883 }
33884
33885-static int preallocate_pmds(pmd_t *pmds[])
33886+static int preallocate_pxds(pxd_t *pxds[])
33887 {
33888 int i;
33889 bool failed = false;
33890
33891- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33892- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33893- if (!pmd)
33894+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33895+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33896+ if (!pxd)
33897 failed = true;
33898- if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33899- free_page((unsigned long)pmd);
33900- pmd = NULL;
33901+ if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33902+ free_page((unsigned long)pxd);
33903+ pxd = NULL;
33904 failed = true;
33905 }
33906- pmds[i] = pmd;
33907+ pxds[i] = pxd;
33908 }
33909
33910 if (failed) {
33911- free_pmds(pmds);
33912+ free_pxds(pxds);
33913 return -ENOMEM;
33914 }
33915
33916@@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33917 * preallocate which never got a corresponding vma will need to be
33918 * freed manually.
33919 */
33920-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33921+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33922 {
33923 int i;
33924
33925- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33926+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33927 pgd_t pgd = pgdp[i];
33928
33929 if (pgd_val(pgd) != 0) {
33930- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33931+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33932
33933- pgdp[i] = native_make_pgd(0);
33934+ set_pgd(pgdp + i, native_make_pgd(0));
33935
33936- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33937- pmd_free(mm, pmd);
33938+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33939+ pxd_free(mm, pxd);
33940 }
33941 }
33942 }
33943
33944-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33945+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33946 {
33947- pud_t *pud;
33948+ pyd_t *pyd;
33949 int i;
33950
33951- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33952+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33953 return;
33954
33955- pud = pud_offset(pgd, 0);
33956-
33957- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33958- pmd_t *pmd = pmds[i];
33959+#ifdef CONFIG_X86_64
33960+ pyd = pyd_offset(mm, 0L);
33961+#else
33962+ pyd = pyd_offset(pgd, 0L);
33963+#endif
33964
33965+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33966+ pxd_t *pxd = pxds[i];
33967 if (i >= KERNEL_PGD_BOUNDARY)
33968- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33969- sizeof(pmd_t) * PTRS_PER_PMD);
33970+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33971+ sizeof(pxd_t) * PTRS_PER_PMD);
33972
33973- pud_populate(mm, pud, pmd);
33974+ pyd_populate(mm, pyd, pxd);
33975 }
33976 }
33977
33978 pgd_t *pgd_alloc(struct mm_struct *mm)
33979 {
33980 pgd_t *pgd;
33981- pmd_t *pmds[PREALLOCATED_PMDS];
33982+ pxd_t *pxds[PREALLOCATED_PXDS];
33983
33984 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33985
33986@@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33987
33988 mm->pgd = pgd;
33989
33990- if (preallocate_pmds(pmds) != 0)
33991+ if (preallocate_pxds(pxds) != 0)
33992 goto out_free_pgd;
33993
33994 if (paravirt_pgd_alloc(mm) != 0)
33995- goto out_free_pmds;
33996+ goto out_free_pxds;
33997
33998 /*
33999 * Make sure that pre-populating the pmds is atomic with
34000@@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
34001 spin_lock(&pgd_lock);
34002
34003 pgd_ctor(mm, pgd);
34004- pgd_prepopulate_pmd(mm, pgd, pmds);
34005+ pgd_prepopulate_pxd(mm, pgd, pxds);
34006
34007 spin_unlock(&pgd_lock);
34008
34009 return pgd;
34010
34011-out_free_pmds:
34012- free_pmds(pmds);
34013+out_free_pxds:
34014+ free_pxds(pxds);
34015 out_free_pgd:
34016 free_page((unsigned long)pgd);
34017 out:
34018@@ -313,7 +380,7 @@ out:
34019
34020 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
34021 {
34022- pgd_mop_up_pmds(mm, pgd);
34023+ pgd_mop_up_pxds(mm, pgd);
34024 pgd_dtor(pgd);
34025 paravirt_pgd_free(mm, pgd);
34026 free_page((unsigned long)pgd);
34027diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
34028index 75cc097..79a097f 100644
34029--- a/arch/x86/mm/pgtable_32.c
34030+++ b/arch/x86/mm/pgtable_32.c
34031@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
34032 return;
34033 }
34034 pte = pte_offset_kernel(pmd, vaddr);
34035+
34036+ pax_open_kernel();
34037 if (pte_val(pteval))
34038 set_pte_at(&init_mm, vaddr, pte, pteval);
34039 else
34040 pte_clear(&init_mm, vaddr, pte);
34041+ pax_close_kernel();
34042
34043 /*
34044 * It's enough to flush this one mapping.
34045diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
34046index e666cbb..61788c45 100644
34047--- a/arch/x86/mm/physaddr.c
34048+++ b/arch/x86/mm/physaddr.c
34049@@ -10,7 +10,7 @@
34050 #ifdef CONFIG_X86_64
34051
34052 #ifdef CONFIG_DEBUG_VIRTUAL
34053-unsigned long __phys_addr(unsigned long x)
34054+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34055 {
34056 unsigned long y = x - __START_KERNEL_map;
34057
34058@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
34059 #else
34060
34061 #ifdef CONFIG_DEBUG_VIRTUAL
34062-unsigned long __phys_addr(unsigned long x)
34063+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34064 {
34065 unsigned long phys_addr = x - PAGE_OFFSET;
34066 /* VMALLOC_* aren't constants */
34067diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
34068index 90555bf..f5f1828 100644
34069--- a/arch/x86/mm/setup_nx.c
34070+++ b/arch/x86/mm/setup_nx.c
34071@@ -5,8 +5,10 @@
34072 #include <asm/pgtable.h>
34073 #include <asm/proto.h>
34074
34075+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34076 static int disable_nx;
34077
34078+#ifndef CONFIG_PAX_PAGEEXEC
34079 /*
34080 * noexec = on|off
34081 *
34082@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
34083 return 0;
34084 }
34085 early_param("noexec", noexec_setup);
34086+#endif
34087+
34088+#endif
34089
34090 void x86_configure_nx(void)
34091 {
34092+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34093 if (cpu_has_nx && !disable_nx)
34094 __supported_pte_mask |= _PAGE_NX;
34095 else
34096+#endif
34097 __supported_pte_mask &= ~_PAGE_NX;
34098 }
34099
34100diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
34101index ee61c36..e6fedeb 100644
34102--- a/arch/x86/mm/tlb.c
34103+++ b/arch/x86/mm/tlb.c
34104@@ -48,7 +48,11 @@ void leave_mm(int cpu)
34105 BUG();
34106 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
34107 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
34108+
34109+#ifndef CONFIG_PAX_PER_CPU_PGD
34110 load_cr3(swapper_pg_dir);
34111+#endif
34112+
34113 /*
34114 * This gets called in the idle path where RCU
34115 * functions differently. Tracing normally
34116diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
34117new file mode 100644
34118index 0000000..dace51c
34119--- /dev/null
34120+++ b/arch/x86/mm/uderef_64.c
34121@@ -0,0 +1,37 @@
34122+#include <linux/mm.h>
34123+#include <asm/pgtable.h>
34124+#include <asm/uaccess.h>
34125+
34126+#ifdef CONFIG_PAX_MEMORY_UDEREF
34127+/* PaX: due to the special call convention these functions must
34128+ * - remain leaf functions under all configurations,
34129+ * - never be called directly, only dereferenced from the wrappers.
34130+ */
34131+void __pax_open_userland(void)
34132+{
34133+ unsigned int cpu;
34134+
34135+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
34136+ return;
34137+
34138+ cpu = raw_get_cpu();
34139+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
34140+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
34141+ raw_put_cpu_no_resched();
34142+}
34143+EXPORT_SYMBOL(__pax_open_userland);
34144+
34145+void __pax_close_userland(void)
34146+{
34147+ unsigned int cpu;
34148+
34149+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
34150+ return;
34151+
34152+ cpu = raw_get_cpu();
34153+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
34154+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
34155+ raw_put_cpu_no_resched();
34156+}
34157+EXPORT_SYMBOL(__pax_close_userland);
34158+#endif
34159diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
34160index 6440221..f84b5c7 100644
34161--- a/arch/x86/net/bpf_jit.S
34162+++ b/arch/x86/net/bpf_jit.S
34163@@ -9,6 +9,7 @@
34164 */
34165 #include <linux/linkage.h>
34166 #include <asm/dwarf2.h>
34167+#include <asm/alternative-asm.h>
34168
34169 /*
34170 * Calling convention :
34171@@ -38,6 +39,7 @@ sk_load_word_positive_offset:
34172 jle bpf_slow_path_word
34173 mov (SKBDATA,%rsi),%eax
34174 bswap %eax /* ntohl() */
34175+ pax_force_retaddr
34176 ret
34177
34178 sk_load_half:
34179@@ -55,6 +57,7 @@ sk_load_half_positive_offset:
34180 jle bpf_slow_path_half
34181 movzwl (SKBDATA,%rsi),%eax
34182 rol $8,%ax # ntohs()
34183+ pax_force_retaddr
34184 ret
34185
34186 sk_load_byte:
34187@@ -69,6 +72,7 @@ sk_load_byte_positive_offset:
34188 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
34189 jle bpf_slow_path_byte
34190 movzbl (SKBDATA,%rsi),%eax
34191+ pax_force_retaddr
34192 ret
34193
34194 /* rsi contains offset and can be scratched */
34195@@ -90,6 +94,7 @@ bpf_slow_path_word:
34196 js bpf_error
34197 mov - MAX_BPF_STACK + 32(%rbp),%eax
34198 bswap %eax
34199+ pax_force_retaddr
34200 ret
34201
34202 bpf_slow_path_half:
34203@@ -98,12 +103,14 @@ bpf_slow_path_half:
34204 mov - MAX_BPF_STACK + 32(%rbp),%ax
34205 rol $8,%ax
34206 movzwl %ax,%eax
34207+ pax_force_retaddr
34208 ret
34209
34210 bpf_slow_path_byte:
34211 bpf_slow_path_common(1)
34212 js bpf_error
34213 movzbl - MAX_BPF_STACK + 32(%rbp),%eax
34214+ pax_force_retaddr
34215 ret
34216
34217 #define sk_negative_common(SIZE) \
34218@@ -126,6 +133,7 @@ sk_load_word_negative_offset:
34219 sk_negative_common(4)
34220 mov (%rax), %eax
34221 bswap %eax
34222+ pax_force_retaddr
34223 ret
34224
34225 bpf_slow_path_half_neg:
34226@@ -137,6 +145,7 @@ sk_load_half_negative_offset:
34227 mov (%rax),%ax
34228 rol $8,%ax
34229 movzwl %ax,%eax
34230+ pax_force_retaddr
34231 ret
34232
34233 bpf_slow_path_byte_neg:
34234@@ -146,6 +155,7 @@ sk_load_byte_negative_offset:
34235 .globl sk_load_byte_negative_offset
34236 sk_negative_common(1)
34237 movzbl (%rax), %eax
34238+ pax_force_retaddr
34239 ret
34240
34241 bpf_error:
34242@@ -156,4 +166,5 @@ bpf_error:
34243 mov - MAX_BPF_STACK + 16(%rbp),%r14
34244 mov - MAX_BPF_STACK + 24(%rbp),%r15
34245 leaveq
34246+ pax_force_retaddr
34247 ret
34248diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
34249index 3f62734..a57894f 100644
34250--- a/arch/x86/net/bpf_jit_comp.c
34251+++ b/arch/x86/net/bpf_jit_comp.c
34252@@ -13,7 +13,11 @@
34253 #include <linux/if_vlan.h>
34254 #include <asm/cacheflush.h>
34255
34256+#ifdef CONFIG_GRKERNSEC_BPF_HARDEN
34257+int bpf_jit_enable __read_only;
34258+#else
34259 int bpf_jit_enable __read_mostly;
34260+#endif
34261
34262 /*
34263 * assembly code in arch/x86/net/bpf_jit.S
34264@@ -174,7 +178,9 @@ static inline u8 add_2reg(u8 byte, u32 dst_reg, u32 src_reg)
34265 static void jit_fill_hole(void *area, unsigned int size)
34266 {
34267 /* fill whole space with int3 instructions */
34268+ pax_open_kernel();
34269 memset(area, 0xcc, size);
34270+ pax_close_kernel();
34271 }
34272
34273 struct jit_context {
34274@@ -894,7 +900,9 @@ common_load:
34275 pr_err("bpf_jit_compile fatal error\n");
34276 return -EFAULT;
34277 }
34278+ pax_open_kernel();
34279 memcpy(image + proglen, temp, ilen);
34280+ pax_close_kernel();
34281 }
34282 proglen += ilen;
34283 addrs[i] = proglen;
34284@@ -966,7 +974,6 @@ void bpf_int_jit_compile(struct bpf_prog *prog)
34285
34286 if (image) {
34287 bpf_flush_icache(header, image + proglen);
34288- set_memory_ro((unsigned long)header, header->pages);
34289 prog->bpf_func = (void *)image;
34290 prog->jited = true;
34291 }
34292@@ -979,12 +986,8 @@ void bpf_jit_free(struct bpf_prog *fp)
34293 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
34294 struct bpf_binary_header *header = (void *)addr;
34295
34296- if (!fp->jited)
34297- goto free_filter;
34298+ if (fp->jited)
34299+ bpf_jit_binary_free(header);
34300
34301- set_memory_rw(addr, header->pages);
34302- bpf_jit_binary_free(header);
34303-
34304-free_filter:
34305 bpf_prog_unlock_free(fp);
34306 }
34307diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
34308index 5d04be5..2beeaa2 100644
34309--- a/arch/x86/oprofile/backtrace.c
34310+++ b/arch/x86/oprofile/backtrace.c
34311@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
34312 struct stack_frame_ia32 *fp;
34313 unsigned long bytes;
34314
34315- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34316+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34317 if (bytes != 0)
34318 return NULL;
34319
34320- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
34321+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
34322
34323 oprofile_add_trace(bufhead[0].return_address);
34324
34325@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
34326 struct stack_frame bufhead[2];
34327 unsigned long bytes;
34328
34329- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34330+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34331 if (bytes != 0)
34332 return NULL;
34333
34334@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
34335 {
34336 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
34337
34338- if (!user_mode_vm(regs)) {
34339+ if (!user_mode(regs)) {
34340 unsigned long stack = kernel_stack_pointer(regs);
34341 if (depth)
34342 dump_trace(NULL, regs, (unsigned long *)stack, 0,
34343diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
34344index 1d2e639..f6ef82a 100644
34345--- a/arch/x86/oprofile/nmi_int.c
34346+++ b/arch/x86/oprofile/nmi_int.c
34347@@ -23,6 +23,7 @@
34348 #include <asm/nmi.h>
34349 #include <asm/msr.h>
34350 #include <asm/apic.h>
34351+#include <asm/pgtable.h>
34352
34353 #include "op_counter.h"
34354 #include "op_x86_model.h"
34355@@ -785,8 +786,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
34356 if (ret)
34357 return ret;
34358
34359- if (!model->num_virt_counters)
34360- model->num_virt_counters = model->num_counters;
34361+ if (!model->num_virt_counters) {
34362+ pax_open_kernel();
34363+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
34364+ pax_close_kernel();
34365+ }
34366
34367 mux_init(ops);
34368
34369diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34370index 50d86c0..7985318 100644
34371--- a/arch/x86/oprofile/op_model_amd.c
34372+++ b/arch/x86/oprofile/op_model_amd.c
34373@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34374 num_counters = AMD64_NUM_COUNTERS;
34375 }
34376
34377- op_amd_spec.num_counters = num_counters;
34378- op_amd_spec.num_controls = num_counters;
34379- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34380+ pax_open_kernel();
34381+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34382+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34383+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34384+ pax_close_kernel();
34385
34386 return 0;
34387 }
34388diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34389index d90528e..0127e2b 100644
34390--- a/arch/x86/oprofile/op_model_ppro.c
34391+++ b/arch/x86/oprofile/op_model_ppro.c
34392@@ -19,6 +19,7 @@
34393 #include <asm/msr.h>
34394 #include <asm/apic.h>
34395 #include <asm/nmi.h>
34396+#include <asm/pgtable.h>
34397
34398 #include "op_x86_model.h"
34399 #include "op_counter.h"
34400@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34401
34402 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34403
34404- op_arch_perfmon_spec.num_counters = num_counters;
34405- op_arch_perfmon_spec.num_controls = num_counters;
34406+ pax_open_kernel();
34407+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34408+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34409+ pax_close_kernel();
34410 }
34411
34412 static int arch_perfmon_init(struct oprofile_operations *ignore)
34413diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34414index 71e8a67..6a313bb 100644
34415--- a/arch/x86/oprofile/op_x86_model.h
34416+++ b/arch/x86/oprofile/op_x86_model.h
34417@@ -52,7 +52,7 @@ struct op_x86_model_spec {
34418 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34419 struct op_msrs const * const msrs);
34420 #endif
34421-};
34422+} __do_const;
34423
34424 struct op_counter_config;
34425
34426diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34427index b9958c3..24229ab 100644
34428--- a/arch/x86/pci/intel_mid_pci.c
34429+++ b/arch/x86/pci/intel_mid_pci.c
34430@@ -250,7 +250,7 @@ int __init intel_mid_pci_init(void)
34431 pci_mmcfg_late_init();
34432 pcibios_enable_irq = intel_mid_pci_irq_enable;
34433 pcibios_disable_irq = intel_mid_pci_irq_disable;
34434- pci_root_ops = intel_mid_pci_ops;
34435+ memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34436 pci_soc_mode = 1;
34437 /* Continue with standard init */
34438 return 1;
34439diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34440index eb500c2..eab9e70 100644
34441--- a/arch/x86/pci/irq.c
34442+++ b/arch/x86/pci/irq.c
34443@@ -51,7 +51,7 @@ struct irq_router {
34444 struct irq_router_handler {
34445 u16 vendor;
34446 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34447-};
34448+} __do_const;
34449
34450 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34451 void (*pcibios_disable_irq)(struct pci_dev *dev) = pirq_disable_irq;
34452@@ -791,7 +791,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34453 return 0;
34454 }
34455
34456-static __initdata struct irq_router_handler pirq_routers[] = {
34457+static __initconst const struct irq_router_handler pirq_routers[] = {
34458 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34459 { PCI_VENDOR_ID_AL, ali_router_probe },
34460 { PCI_VENDOR_ID_ITE, ite_router_probe },
34461@@ -818,7 +818,7 @@ static struct pci_dev *pirq_router_dev;
34462 static void __init pirq_find_router(struct irq_router *r)
34463 {
34464 struct irq_routing_table *rt = pirq_table;
34465- struct irq_router_handler *h;
34466+ const struct irq_router_handler *h;
34467
34468 #ifdef CONFIG_PCI_BIOS
34469 if (!rt->signature) {
34470@@ -1091,7 +1091,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34471 return 0;
34472 }
34473
34474-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34475+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34476 {
34477 .callback = fix_broken_hp_bios_irq9,
34478 .ident = "HP Pavilion N5400 Series Laptop",
34479diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34480index 9b83b90..4112152 100644
34481--- a/arch/x86/pci/pcbios.c
34482+++ b/arch/x86/pci/pcbios.c
34483@@ -79,7 +79,7 @@ union bios32 {
34484 static struct {
34485 unsigned long address;
34486 unsigned short segment;
34487-} bios32_indirect __initdata = { 0, __KERNEL_CS };
34488+} bios32_indirect __initconst = { 0, __PCIBIOS_CS };
34489
34490 /*
34491 * Returns the entry point for the given service, NULL on error
34492@@ -92,37 +92,80 @@ static unsigned long __init bios32_service(unsigned long service)
34493 unsigned long length; /* %ecx */
34494 unsigned long entry; /* %edx */
34495 unsigned long flags;
34496+ struct desc_struct d, *gdt;
34497
34498 local_irq_save(flags);
34499- __asm__("lcall *(%%edi); cld"
34500+
34501+ gdt = get_cpu_gdt_table(smp_processor_id());
34502+
34503+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34504+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34505+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34506+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34507+
34508+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34509 : "=a" (return_code),
34510 "=b" (address),
34511 "=c" (length),
34512 "=d" (entry)
34513 : "0" (service),
34514 "1" (0),
34515- "D" (&bios32_indirect));
34516+ "D" (&bios32_indirect),
34517+ "r"(__PCIBIOS_DS)
34518+ : "memory");
34519+
34520+ pax_open_kernel();
34521+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34522+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34523+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34524+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34525+ pax_close_kernel();
34526+
34527 local_irq_restore(flags);
34528
34529 switch (return_code) {
34530- case 0:
34531- return address + entry;
34532- case 0x80: /* Not present */
34533- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34534- return 0;
34535- default: /* Shouldn't happen */
34536- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34537- service, return_code);
34538+ case 0: {
34539+ int cpu;
34540+ unsigned char flags;
34541+
34542+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34543+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34544+ printk(KERN_WARNING "bios32_service: not valid\n");
34545 return 0;
34546+ }
34547+ address = address + PAGE_OFFSET;
34548+ length += 16UL; /* some BIOSs underreport this... */
34549+ flags = 4;
34550+ if (length >= 64*1024*1024) {
34551+ length >>= PAGE_SHIFT;
34552+ flags |= 8;
34553+ }
34554+
34555+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34556+ gdt = get_cpu_gdt_table(cpu);
34557+ pack_descriptor(&d, address, length, 0x9b, flags);
34558+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34559+ pack_descriptor(&d, address, length, 0x93, flags);
34560+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34561+ }
34562+ return entry;
34563+ }
34564+ case 0x80: /* Not present */
34565+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34566+ return 0;
34567+ default: /* Shouldn't happen */
34568+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34569+ service, return_code);
34570+ return 0;
34571 }
34572 }
34573
34574 static struct {
34575 unsigned long address;
34576 unsigned short segment;
34577-} pci_indirect = { 0, __KERNEL_CS };
34578+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34579
34580-static int pci_bios_present;
34581+static int pci_bios_present __read_only;
34582
34583 static int __init check_pcibios(void)
34584 {
34585@@ -131,11 +174,13 @@ static int __init check_pcibios(void)
34586 unsigned long flags, pcibios_entry;
34587
34588 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34589- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34590+ pci_indirect.address = pcibios_entry;
34591
34592 local_irq_save(flags);
34593- __asm__(
34594- "lcall *(%%edi); cld\n\t"
34595+ __asm__("movw %w6, %%ds\n\t"
34596+ "lcall *%%ss:(%%edi); cld\n\t"
34597+ "push %%ss\n\t"
34598+ "pop %%ds\n\t"
34599 "jc 1f\n\t"
34600 "xor %%ah, %%ah\n"
34601 "1:"
34602@@ -144,7 +189,8 @@ static int __init check_pcibios(void)
34603 "=b" (ebx),
34604 "=c" (ecx)
34605 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34606- "D" (&pci_indirect)
34607+ "D" (&pci_indirect),
34608+ "r" (__PCIBIOS_DS)
34609 : "memory");
34610 local_irq_restore(flags);
34611
34612@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34613
34614 switch (len) {
34615 case 1:
34616- __asm__("lcall *(%%esi); cld\n\t"
34617+ __asm__("movw %w6, %%ds\n\t"
34618+ "lcall *%%ss:(%%esi); cld\n\t"
34619+ "push %%ss\n\t"
34620+ "pop %%ds\n\t"
34621 "jc 1f\n\t"
34622 "xor %%ah, %%ah\n"
34623 "1:"
34624@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34625 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34626 "b" (bx),
34627 "D" ((long)reg),
34628- "S" (&pci_indirect));
34629+ "S" (&pci_indirect),
34630+ "r" (__PCIBIOS_DS));
34631 /*
34632 * Zero-extend the result beyond 8 bits, do not trust the
34633 * BIOS having done it:
34634@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34635 *value &= 0xff;
34636 break;
34637 case 2:
34638- __asm__("lcall *(%%esi); cld\n\t"
34639+ __asm__("movw %w6, %%ds\n\t"
34640+ "lcall *%%ss:(%%esi); cld\n\t"
34641+ "push %%ss\n\t"
34642+ "pop %%ds\n\t"
34643 "jc 1f\n\t"
34644 "xor %%ah, %%ah\n"
34645 "1:"
34646@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34647 : "1" (PCIBIOS_READ_CONFIG_WORD),
34648 "b" (bx),
34649 "D" ((long)reg),
34650- "S" (&pci_indirect));
34651+ "S" (&pci_indirect),
34652+ "r" (__PCIBIOS_DS));
34653 /*
34654 * Zero-extend the result beyond 16 bits, do not trust the
34655 * BIOS having done it:
34656@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34657 *value &= 0xffff;
34658 break;
34659 case 4:
34660- __asm__("lcall *(%%esi); cld\n\t"
34661+ __asm__("movw %w6, %%ds\n\t"
34662+ "lcall *%%ss:(%%esi); cld\n\t"
34663+ "push %%ss\n\t"
34664+ "pop %%ds\n\t"
34665 "jc 1f\n\t"
34666 "xor %%ah, %%ah\n"
34667 "1:"
34668@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34669 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34670 "b" (bx),
34671 "D" ((long)reg),
34672- "S" (&pci_indirect));
34673+ "S" (&pci_indirect),
34674+ "r" (__PCIBIOS_DS));
34675 break;
34676 }
34677
34678@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34679
34680 switch (len) {
34681 case 1:
34682- __asm__("lcall *(%%esi); cld\n\t"
34683+ __asm__("movw %w6, %%ds\n\t"
34684+ "lcall *%%ss:(%%esi); cld\n\t"
34685+ "push %%ss\n\t"
34686+ "pop %%ds\n\t"
34687 "jc 1f\n\t"
34688 "xor %%ah, %%ah\n"
34689 "1:"
34690@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34691 "c" (value),
34692 "b" (bx),
34693 "D" ((long)reg),
34694- "S" (&pci_indirect));
34695+ "S" (&pci_indirect),
34696+ "r" (__PCIBIOS_DS));
34697 break;
34698 case 2:
34699- __asm__("lcall *(%%esi); cld\n\t"
34700+ __asm__("movw %w6, %%ds\n\t"
34701+ "lcall *%%ss:(%%esi); cld\n\t"
34702+ "push %%ss\n\t"
34703+ "pop %%ds\n\t"
34704 "jc 1f\n\t"
34705 "xor %%ah, %%ah\n"
34706 "1:"
34707@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34708 "c" (value),
34709 "b" (bx),
34710 "D" ((long)reg),
34711- "S" (&pci_indirect));
34712+ "S" (&pci_indirect),
34713+ "r" (__PCIBIOS_DS));
34714 break;
34715 case 4:
34716- __asm__("lcall *(%%esi); cld\n\t"
34717+ __asm__("movw %w6, %%ds\n\t"
34718+ "lcall *%%ss:(%%esi); cld\n\t"
34719+ "push %%ss\n\t"
34720+ "pop %%ds\n\t"
34721 "jc 1f\n\t"
34722 "xor %%ah, %%ah\n"
34723 "1:"
34724@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34725 "c" (value),
34726 "b" (bx),
34727 "D" ((long)reg),
34728- "S" (&pci_indirect));
34729+ "S" (&pci_indirect),
34730+ "r" (__PCIBIOS_DS));
34731 break;
34732 }
34733
34734@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34735
34736 DBG("PCI: Fetching IRQ routing table... ");
34737 __asm__("push %%es\n\t"
34738+ "movw %w8, %%ds\n\t"
34739 "push %%ds\n\t"
34740 "pop %%es\n\t"
34741- "lcall *(%%esi); cld\n\t"
34742+ "lcall *%%ss:(%%esi); cld\n\t"
34743 "pop %%es\n\t"
34744+ "push %%ss\n\t"
34745+ "pop %%ds\n"
34746 "jc 1f\n\t"
34747 "xor %%ah, %%ah\n"
34748 "1:"
34749@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34750 "1" (0),
34751 "D" ((long) &opt),
34752 "S" (&pci_indirect),
34753- "m" (opt)
34754+ "m" (opt),
34755+ "r" (__PCIBIOS_DS)
34756 : "memory");
34757 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34758 if (ret & 0xff00)
34759@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34760 {
34761 int ret;
34762
34763- __asm__("lcall *(%%esi); cld\n\t"
34764+ __asm__("movw %w5, %%ds\n\t"
34765+ "lcall *%%ss:(%%esi); cld\n\t"
34766+ "push %%ss\n\t"
34767+ "pop %%ds\n"
34768 "jc 1f\n\t"
34769 "xor %%ah, %%ah\n"
34770 "1:"
34771@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34772 : "0" (PCIBIOS_SET_PCI_HW_INT),
34773 "b" ((dev->bus->number << 8) | dev->devfn),
34774 "c" ((irq << 8) | (pin + 10)),
34775- "S" (&pci_indirect));
34776+ "S" (&pci_indirect),
34777+ "r" (__PCIBIOS_DS));
34778 return !(ret & 0xff00);
34779 }
34780 EXPORT_SYMBOL(pcibios_set_irq_routing);
34781diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34782index 40e7cda..c7e6672 100644
34783--- a/arch/x86/platform/efi/efi_32.c
34784+++ b/arch/x86/platform/efi/efi_32.c
34785@@ -61,11 +61,22 @@ void __init efi_call_phys_prolog(void)
34786 {
34787 struct desc_ptr gdt_descr;
34788
34789+#ifdef CONFIG_PAX_KERNEXEC
34790+ struct desc_struct d;
34791+#endif
34792+
34793 local_irq_save(efi_rt_eflags);
34794
34795 load_cr3(initial_page_table);
34796 __flush_tlb_all();
34797
34798+#ifdef CONFIG_PAX_KERNEXEC
34799+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34800+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34801+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34802+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34803+#endif
34804+
34805 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34806 gdt_descr.size = GDT_SIZE - 1;
34807 load_gdt(&gdt_descr);
34808@@ -75,11 +86,24 @@ void __init efi_call_phys_epilog(void)
34809 {
34810 struct desc_ptr gdt_descr;
34811
34812+#ifdef CONFIG_PAX_KERNEXEC
34813+ struct desc_struct d;
34814+
34815+ memset(&d, 0, sizeof d);
34816+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34817+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34818+#endif
34819+
34820 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34821 gdt_descr.size = GDT_SIZE - 1;
34822 load_gdt(&gdt_descr);
34823
34824+#ifdef CONFIG_PAX_PER_CPU_PGD
34825+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34826+#else
34827 load_cr3(swapper_pg_dir);
34828+#endif
34829+
34830 __flush_tlb_all();
34831
34832 local_irq_restore(efi_rt_eflags);
34833diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34834index 35aecb6..46177db 100644
34835--- a/arch/x86/platform/efi/efi_64.c
34836+++ b/arch/x86/platform/efi/efi_64.c
34837@@ -99,6 +99,11 @@ void __init efi_call_phys_prolog(void)
34838 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34839 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34840 }
34841+
34842+#ifdef CONFIG_PAX_PER_CPU_PGD
34843+ load_cr3(swapper_pg_dir);
34844+#endif
34845+
34846 __flush_tlb_all();
34847 }
34848
34849@@ -116,6 +121,11 @@ void __init efi_call_phys_epilog(void)
34850 for (pgd = 0; pgd < n_pgds; pgd++)
34851 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34852 kfree(save_pgd);
34853+
34854+#ifdef CONFIG_PAX_PER_CPU_PGD
34855+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34856+#endif
34857+
34858 __flush_tlb_all();
34859 local_irq_restore(efi_flags);
34860 early_code_mapping_set_exec(0);
34861@@ -146,8 +156,23 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
34862 unsigned npages;
34863 pgd_t *pgd;
34864
34865- if (efi_enabled(EFI_OLD_MEMMAP))
34866+ if (efi_enabled(EFI_OLD_MEMMAP)) {
34867+ /* PaX: We need to disable the NX bit in the PGD, otherwise we won't be
34868+ * able to execute the EFI services.
34869+ */
34870+ if (__supported_pte_mask & _PAGE_NX) {
34871+ unsigned long addr = (unsigned long) __va(0);
34872+ pgd_t pe = __pgd(pgd_val(*pgd_offset_k(addr)) & ~_PAGE_NX);
34873+
34874+ pr_alert("PAX: Disabling NX protection for low memory map. Try booting without \"efi=old_map\"\n");
34875+#ifdef CONFIG_PAX_PER_CPU_PGD
34876+ set_pgd(pgd_offset_cpu(0, kernel, addr), pe);
34877+#endif
34878+ set_pgd(pgd_offset_k(addr), pe);
34879+ }
34880+
34881 return 0;
34882+ }
34883
34884 efi_scratch.efi_pgt = (pgd_t *)(unsigned long)real_mode_header->trampoline_pgd;
34885 pgd = __va(efi_scratch.efi_pgt);
34886diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34887index 040192b..7d3300f 100644
34888--- a/arch/x86/platform/efi/efi_stub_32.S
34889+++ b/arch/x86/platform/efi/efi_stub_32.S
34890@@ -6,7 +6,9 @@
34891 */
34892
34893 #include <linux/linkage.h>
34894+#include <linux/init.h>
34895 #include <asm/page_types.h>
34896+#include <asm/segment.h>
34897
34898 /*
34899 * efi_call_phys(void *, ...) is a function with variable parameters.
34900@@ -20,7 +22,7 @@
34901 * service functions will comply with gcc calling convention, too.
34902 */
34903
34904-.text
34905+__INIT
34906 ENTRY(efi_call_phys)
34907 /*
34908 * 0. The function can only be called in Linux kernel. So CS has been
34909@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34910 * The mapping of lower virtual memory has been created in prolog and
34911 * epilog.
34912 */
34913- movl $1f, %edx
34914- subl $__PAGE_OFFSET, %edx
34915- jmp *%edx
34916+#ifdef CONFIG_PAX_KERNEXEC
34917+ movl $(__KERNEXEC_EFI_DS), %edx
34918+ mov %edx, %ds
34919+ mov %edx, %es
34920+ mov %edx, %ss
34921+ addl $2f,(1f)
34922+ ljmp *(1f)
34923+
34924+__INITDATA
34925+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34926+.previous
34927+
34928+2:
34929+ subl $2b,(1b)
34930+#else
34931+ jmp 1f-__PAGE_OFFSET
34932 1:
34933+#endif
34934
34935 /*
34936 * 2. Now on the top of stack is the return
34937@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34938 * parameter 2, ..., param n. To make things easy, we save the return
34939 * address of efi_call_phys in a global variable.
34940 */
34941- popl %edx
34942- movl %edx, saved_return_addr
34943- /* get the function pointer into ECX*/
34944- popl %ecx
34945- movl %ecx, efi_rt_function_ptr
34946- movl $2f, %edx
34947- subl $__PAGE_OFFSET, %edx
34948- pushl %edx
34949+ popl (saved_return_addr)
34950+ popl (efi_rt_function_ptr)
34951
34952 /*
34953 * 3. Clear PG bit in %CR0.
34954@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34955 /*
34956 * 5. Call the physical function.
34957 */
34958- jmp *%ecx
34959+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
34960
34961-2:
34962 /*
34963 * 6. After EFI runtime service returns, control will return to
34964 * following instruction. We'd better readjust stack pointer first.
34965@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34966 movl %cr0, %edx
34967 orl $0x80000000, %edx
34968 movl %edx, %cr0
34969- jmp 1f
34970-1:
34971+
34972 /*
34973 * 8. Now restore the virtual mode from flat mode by
34974 * adding EIP with PAGE_OFFSET.
34975 */
34976- movl $1f, %edx
34977- jmp *%edx
34978+#ifdef CONFIG_PAX_KERNEXEC
34979+ movl $(__KERNEL_DS), %edx
34980+ mov %edx, %ds
34981+ mov %edx, %es
34982+ mov %edx, %ss
34983+ ljmp $(__KERNEL_CS),$1f
34984+#else
34985+ jmp 1f+__PAGE_OFFSET
34986+#endif
34987 1:
34988
34989 /*
34990 * 9. Balance the stack. And because EAX contain the return value,
34991 * we'd better not clobber it.
34992 */
34993- leal efi_rt_function_ptr, %edx
34994- movl (%edx), %ecx
34995- pushl %ecx
34996+ pushl (efi_rt_function_ptr)
34997
34998 /*
34999- * 10. Push the saved return address onto the stack and return.
35000+ * 10. Return to the saved return address.
35001 */
35002- leal saved_return_addr, %edx
35003- movl (%edx), %ecx
35004- pushl %ecx
35005- ret
35006+ jmpl *(saved_return_addr)
35007 ENDPROC(efi_call_phys)
35008 .previous
35009
35010-.data
35011+__INITDATA
35012 saved_return_addr:
35013 .long 0
35014 efi_rt_function_ptr:
35015diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
35016index 5fcda72..cd4dc41 100644
35017--- a/arch/x86/platform/efi/efi_stub_64.S
35018+++ b/arch/x86/platform/efi/efi_stub_64.S
35019@@ -11,6 +11,7 @@
35020 #include <asm/msr.h>
35021 #include <asm/processor-flags.h>
35022 #include <asm/page_types.h>
35023+#include <asm/alternative-asm.h>
35024
35025 #define SAVE_XMM \
35026 mov %rsp, %rax; \
35027@@ -88,6 +89,7 @@ ENTRY(efi_call)
35028 RESTORE_PGT
35029 addq $48, %rsp
35030 RESTORE_XMM
35031+ pax_force_retaddr 0, 1
35032 ret
35033 ENDPROC(efi_call)
35034
35035@@ -245,8 +247,8 @@ efi_gdt64:
35036 .long 0 /* Filled out by user */
35037 .word 0
35038 .quad 0x0000000000000000 /* NULL descriptor */
35039- .quad 0x00af9a000000ffff /* __KERNEL_CS */
35040- .quad 0x00cf92000000ffff /* __KERNEL_DS */
35041+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
35042+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
35043 .quad 0x0080890000000000 /* TS descriptor */
35044 .quad 0x0000000000000000 /* TS continued */
35045 efi_gdt64_end:
35046diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
35047index 1bbedc4..eb795b5 100644
35048--- a/arch/x86/platform/intel-mid/intel-mid.c
35049+++ b/arch/x86/platform/intel-mid/intel-mid.c
35050@@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
35051 {
35052 };
35053
35054-static void intel_mid_reboot(void)
35055+static void __noreturn intel_mid_reboot(void)
35056 {
35057 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
35058+ BUG();
35059 }
35060
35061 static unsigned long __init intel_mid_calibrate_tsc(void)
35062diff --git a/arch/x86/platform/intel-mid/intel_mid_weak_decls.h b/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
35063index 3c1c386..59a68ed 100644
35064--- a/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
35065+++ b/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
35066@@ -13,6 +13,6 @@
35067 /* For every CPU addition a new get_<cpuname>_ops interface needs
35068 * to be added.
35069 */
35070-extern void *get_penwell_ops(void);
35071-extern void *get_cloverview_ops(void);
35072-extern void *get_tangier_ops(void);
35073+extern const void *get_penwell_ops(void);
35074+extern const void *get_cloverview_ops(void);
35075+extern const void *get_tangier_ops(void);
35076diff --git a/arch/x86/platform/intel-mid/mfld.c b/arch/x86/platform/intel-mid/mfld.c
35077index 23381d2..8ddc10e 100644
35078--- a/arch/x86/platform/intel-mid/mfld.c
35079+++ b/arch/x86/platform/intel-mid/mfld.c
35080@@ -64,12 +64,12 @@ static void __init penwell_arch_setup(void)
35081 pm_power_off = mfld_power_off;
35082 }
35083
35084-void *get_penwell_ops(void)
35085+const void *get_penwell_ops(void)
35086 {
35087 return &penwell_ops;
35088 }
35089
35090-void *get_cloverview_ops(void)
35091+const void *get_cloverview_ops(void)
35092 {
35093 return &penwell_ops;
35094 }
35095diff --git a/arch/x86/platform/intel-mid/mrfl.c b/arch/x86/platform/intel-mid/mrfl.c
35096index aaca917..66eadbc 100644
35097--- a/arch/x86/platform/intel-mid/mrfl.c
35098+++ b/arch/x86/platform/intel-mid/mrfl.c
35099@@ -97,7 +97,7 @@ static struct intel_mid_ops tangier_ops = {
35100 .arch_setup = tangier_arch_setup,
35101 };
35102
35103-void *get_tangier_ops(void)
35104+const void *get_tangier_ops(void)
35105 {
35106 return &tangier_ops;
35107 }
35108diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
35109index d6ee929..3637cb5 100644
35110--- a/arch/x86/platform/olpc/olpc_dt.c
35111+++ b/arch/x86/platform/olpc/olpc_dt.c
35112@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
35113 return res;
35114 }
35115
35116-static struct of_pdt_ops prom_olpc_ops __initdata = {
35117+static struct of_pdt_ops prom_olpc_ops __initconst = {
35118 .nextprop = olpc_dt_nextprop,
35119 .getproplen = olpc_dt_getproplen,
35120 .getproperty = olpc_dt_getproperty,
35121diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
35122index 6ec7910..ecdbb11 100644
35123--- a/arch/x86/power/cpu.c
35124+++ b/arch/x86/power/cpu.c
35125@@ -137,11 +137,8 @@ static void do_fpu_end(void)
35126 static void fix_processor_context(void)
35127 {
35128 int cpu = smp_processor_id();
35129- struct tss_struct *t = &per_cpu(init_tss, cpu);
35130-#ifdef CONFIG_X86_64
35131- struct desc_struct *desc = get_cpu_gdt_table(cpu);
35132- tss_desc tss;
35133-#endif
35134+ struct tss_struct *t = init_tss + cpu;
35135+
35136 set_tss_desc(cpu, t); /*
35137 * This just modifies memory; should not be
35138 * necessary. But... This is necessary, because
35139@@ -150,10 +147,6 @@ static void fix_processor_context(void)
35140 */
35141
35142 #ifdef CONFIG_X86_64
35143- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
35144- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
35145- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
35146-
35147 syscall_init(); /* This sets MSR_*STAR and related */
35148 #endif
35149 load_TR_desc(); /* This does ltr */
35150diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
35151index bad628a..a102610 100644
35152--- a/arch/x86/realmode/init.c
35153+++ b/arch/x86/realmode/init.c
35154@@ -68,7 +68,13 @@ void __init setup_real_mode(void)
35155 __va(real_mode_header->trampoline_header);
35156
35157 #ifdef CONFIG_X86_32
35158- trampoline_header->start = __pa_symbol(startup_32_smp);
35159+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
35160+
35161+#ifdef CONFIG_PAX_KERNEXEC
35162+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
35163+#endif
35164+
35165+ trampoline_header->boot_cs = __BOOT_CS;
35166 trampoline_header->gdt_limit = __BOOT_DS + 7;
35167 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
35168 #else
35169@@ -84,7 +90,7 @@ void __init setup_real_mode(void)
35170 *trampoline_cr4_features = read_cr4();
35171
35172 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
35173- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
35174+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
35175 trampoline_pgd[511] = init_level4_pgt[511].pgd;
35176 #endif
35177 }
35178diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
35179index 7c0d7be..d24dc88 100644
35180--- a/arch/x86/realmode/rm/Makefile
35181+++ b/arch/x86/realmode/rm/Makefile
35182@@ -67,5 +67,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
35183
35184 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
35185 -I$(srctree)/arch/x86/boot
35186+ifdef CONSTIFY_PLUGIN
35187+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
35188+endif
35189 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
35190 GCOV_PROFILE := n
35191diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
35192index a28221d..93c40f1 100644
35193--- a/arch/x86/realmode/rm/header.S
35194+++ b/arch/x86/realmode/rm/header.S
35195@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
35196 #endif
35197 /* APM/BIOS reboot */
35198 .long pa_machine_real_restart_asm
35199-#ifdef CONFIG_X86_64
35200+#ifdef CONFIG_X86_32
35201+ .long __KERNEL_CS
35202+#else
35203 .long __KERNEL32_CS
35204 #endif
35205 END(real_mode_header)
35206diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
35207index 48ddd76..c26749f 100644
35208--- a/arch/x86/realmode/rm/trampoline_32.S
35209+++ b/arch/x86/realmode/rm/trampoline_32.S
35210@@ -24,6 +24,12 @@
35211 #include <asm/page_types.h>
35212 #include "realmode.h"
35213
35214+#ifdef CONFIG_PAX_KERNEXEC
35215+#define ta(X) (X)
35216+#else
35217+#define ta(X) (pa_ ## X)
35218+#endif
35219+
35220 .text
35221 .code16
35222
35223@@ -38,8 +44,6 @@ ENTRY(trampoline_start)
35224
35225 cli # We should be safe anyway
35226
35227- movl tr_start, %eax # where we need to go
35228-
35229 movl $0xA5A5A5A5, trampoline_status
35230 # write marker for master knows we're running
35231
35232@@ -55,7 +59,7 @@ ENTRY(trampoline_start)
35233 movw $1, %dx # protected mode (PE) bit
35234 lmsw %dx # into protected mode
35235
35236- ljmpl $__BOOT_CS, $pa_startup_32
35237+ ljmpl *(trampoline_header)
35238
35239 .section ".text32","ax"
35240 .code32
35241@@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
35242 .balign 8
35243 GLOBAL(trampoline_header)
35244 tr_start: .space 4
35245- tr_gdt_pad: .space 2
35246+ tr_boot_cs: .space 2
35247 tr_gdt: .space 6
35248 END(trampoline_header)
35249
35250diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
35251index dac7b20..72dbaca 100644
35252--- a/arch/x86/realmode/rm/trampoline_64.S
35253+++ b/arch/x86/realmode/rm/trampoline_64.S
35254@@ -93,6 +93,7 @@ ENTRY(startup_32)
35255 movl %edx, %gs
35256
35257 movl pa_tr_cr4, %eax
35258+ andl $~X86_CR4_PCIDE, %eax
35259 movl %eax, %cr4 # Enable PAE mode
35260
35261 # Setup trampoline 4 level pagetables
35262@@ -106,7 +107,7 @@ ENTRY(startup_32)
35263 wrmsr
35264
35265 # Enable paging and in turn activate Long Mode
35266- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
35267+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
35268 movl %eax, %cr0
35269
35270 /*
35271diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
35272index 9e7e147..25a4158 100644
35273--- a/arch/x86/realmode/rm/wakeup_asm.S
35274+++ b/arch/x86/realmode/rm/wakeup_asm.S
35275@@ -126,11 +126,10 @@ ENTRY(wakeup_start)
35276 lgdtl pmode_gdt
35277
35278 /* This really couldn't... */
35279- movl pmode_entry, %eax
35280 movl pmode_cr0, %ecx
35281 movl %ecx, %cr0
35282- ljmpl $__KERNEL_CS, $pa_startup_32
35283- /* -> jmp *%eax in trampoline_32.S */
35284+
35285+ ljmpl *pmode_entry
35286 #else
35287 jmp trampoline_start
35288 #endif
35289diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
35290index 604a37e..e49702a 100644
35291--- a/arch/x86/tools/Makefile
35292+++ b/arch/x86/tools/Makefile
35293@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
35294
35295 $(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
35296
35297-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
35298+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
35299 hostprogs-y += relocs
35300 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
35301 PHONY += relocs
35302diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
35303index a5efb21..97490e9 100644
35304--- a/arch/x86/tools/relocs.c
35305+++ b/arch/x86/tools/relocs.c
35306@@ -1,5 +1,7 @@
35307 /* This is included from relocs_32/64.c */
35308
35309+#include "../../../include/generated/autoconf.h"
35310+
35311 #define ElfW(type) _ElfW(ELF_BITS, type)
35312 #define _ElfW(bits, type) __ElfW(bits, type)
35313 #define __ElfW(bits, type) Elf##bits##_##type
35314@@ -11,6 +13,7 @@
35315 #define Elf_Sym ElfW(Sym)
35316
35317 static Elf_Ehdr ehdr;
35318+static Elf_Phdr *phdr;
35319
35320 struct relocs {
35321 uint32_t *offset;
35322@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
35323 }
35324 }
35325
35326+static void read_phdrs(FILE *fp)
35327+{
35328+ unsigned int i;
35329+
35330+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
35331+ if (!phdr) {
35332+ die("Unable to allocate %d program headers\n",
35333+ ehdr.e_phnum);
35334+ }
35335+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
35336+ die("Seek to %d failed: %s\n",
35337+ ehdr.e_phoff, strerror(errno));
35338+ }
35339+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
35340+ die("Cannot read ELF program headers: %s\n",
35341+ strerror(errno));
35342+ }
35343+ for(i = 0; i < ehdr.e_phnum; i++) {
35344+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
35345+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
35346+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
35347+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
35348+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
35349+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
35350+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
35351+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
35352+ }
35353+
35354+}
35355+
35356 static void read_shdrs(FILE *fp)
35357 {
35358- int i;
35359+ unsigned int i;
35360 Elf_Shdr shdr;
35361
35362 secs = calloc(ehdr.e_shnum, sizeof(struct section));
35363@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
35364
35365 static void read_strtabs(FILE *fp)
35366 {
35367- int i;
35368+ unsigned int i;
35369 for (i = 0; i < ehdr.e_shnum; i++) {
35370 struct section *sec = &secs[i];
35371 if (sec->shdr.sh_type != SHT_STRTAB) {
35372@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
35373
35374 static void read_symtabs(FILE *fp)
35375 {
35376- int i,j;
35377+ unsigned int i,j;
35378 for (i = 0; i < ehdr.e_shnum; i++) {
35379 struct section *sec = &secs[i];
35380 if (sec->shdr.sh_type != SHT_SYMTAB) {
35381@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
35382 }
35383
35384
35385-static void read_relocs(FILE *fp)
35386+static void read_relocs(FILE *fp, int use_real_mode)
35387 {
35388- int i,j;
35389+ unsigned int i,j;
35390+ uint32_t base;
35391+
35392 for (i = 0; i < ehdr.e_shnum; i++) {
35393 struct section *sec = &secs[i];
35394 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35395@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
35396 die("Cannot read symbol table: %s\n",
35397 strerror(errno));
35398 }
35399+ base = 0;
35400+
35401+#ifdef CONFIG_X86_32
35402+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
35403+ if (phdr[j].p_type != PT_LOAD )
35404+ continue;
35405+ 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)
35406+ continue;
35407+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
35408+ break;
35409+ }
35410+#endif
35411+
35412 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
35413 Elf_Rel *rel = &sec->reltab[j];
35414- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
35415+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
35416 rel->r_info = elf_xword_to_cpu(rel->r_info);
35417 #if (SHT_REL_TYPE == SHT_RELA)
35418 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
35419@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
35420
35421 static void print_absolute_symbols(void)
35422 {
35423- int i;
35424+ unsigned int i;
35425 const char *format;
35426
35427 if (ELF_BITS == 64)
35428@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35429 for (i = 0; i < ehdr.e_shnum; i++) {
35430 struct section *sec = &secs[i];
35431 char *sym_strtab;
35432- int j;
35433+ unsigned int j;
35434
35435 if (sec->shdr.sh_type != SHT_SYMTAB) {
35436 continue;
35437@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35438
35439 static void print_absolute_relocs(void)
35440 {
35441- int i, printed = 0;
35442+ unsigned int i, printed = 0;
35443 const char *format;
35444
35445 if (ELF_BITS == 64)
35446@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35447 struct section *sec_applies, *sec_symtab;
35448 char *sym_strtab;
35449 Elf_Sym *sh_symtab;
35450- int j;
35451+ unsigned int j;
35452 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35453 continue;
35454 }
35455@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35456 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35457 Elf_Sym *sym, const char *symname))
35458 {
35459- int i;
35460+ unsigned int i;
35461 /* Walk through the relocations */
35462 for (i = 0; i < ehdr.e_shnum; i++) {
35463 char *sym_strtab;
35464 Elf_Sym *sh_symtab;
35465 struct section *sec_applies, *sec_symtab;
35466- int j;
35467+ unsigned int j;
35468 struct section *sec = &secs[i];
35469
35470 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35471@@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35472 {
35473 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35474 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35475+ char *sym_strtab = sec->link->link->strtab;
35476+
35477+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35478+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35479+ return 0;
35480+
35481+#ifdef CONFIG_PAX_KERNEXEC
35482+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35483+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35484+ return 0;
35485+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35486+ return 0;
35487+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35488+ return 0;
35489+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35490+ return 0;
35491+#endif
35492
35493 switch (r_type) {
35494 case R_386_NONE:
35495@@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35496
35497 static void emit_relocs(int as_text, int use_real_mode)
35498 {
35499- int i;
35500+ unsigned int i;
35501 int (*write_reloc)(uint32_t, FILE *) = write32;
35502 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35503 const char *symname);
35504@@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35505 {
35506 regex_init(use_real_mode);
35507 read_ehdr(fp);
35508+ read_phdrs(fp);
35509 read_shdrs(fp);
35510 read_strtabs(fp);
35511 read_symtabs(fp);
35512- read_relocs(fp);
35513+ read_relocs(fp, use_real_mode);
35514 if (ELF_BITS == 64)
35515 percpu_init();
35516 if (show_absolute_syms) {
35517diff --git a/arch/x86/um/mem_32.c b/arch/x86/um/mem_32.c
35518index f40281e..92728c9 100644
35519--- a/arch/x86/um/mem_32.c
35520+++ b/arch/x86/um/mem_32.c
35521@@ -21,7 +21,7 @@ static int __init gate_vma_init(void)
35522 gate_vma.vm_start = FIXADDR_USER_START;
35523 gate_vma.vm_end = FIXADDR_USER_END;
35524 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35525- gate_vma.vm_page_prot = __P101;
35526+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35527
35528 return 0;
35529 }
35530diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35531index 80ffa5b..a33bd15 100644
35532--- a/arch/x86/um/tls_32.c
35533+++ b/arch/x86/um/tls_32.c
35534@@ -260,7 +260,7 @@ out:
35535 if (unlikely(task == current &&
35536 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35537 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35538- "without flushed TLS.", current->pid);
35539+ "without flushed TLS.", task_pid_nr(current));
35540 }
35541
35542 return 0;
35543diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35544index 5a4affe..9e2d522 100644
35545--- a/arch/x86/vdso/Makefile
35546+++ b/arch/x86/vdso/Makefile
35547@@ -174,7 +174,7 @@ quiet_cmd_vdso = VDSO $@
35548 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35549 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35550
35551-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35552+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35553 $(call cc-ldoption, -Wl$(comma)--build-id) -Wl,-Bsymbolic $(LTO_CFLAGS)
35554 GCOV_PROFILE := n
35555
35556diff --git a/arch/x86/vdso/vdso2c.h b/arch/x86/vdso/vdso2c.h
35557index 0224987..c7d65a5 100644
35558--- a/arch/x86/vdso/vdso2c.h
35559+++ b/arch/x86/vdso/vdso2c.h
35560@@ -12,7 +12,7 @@ static void BITSFUNC(go)(void *raw_addr, size_t raw_len,
35561 unsigned long load_size = -1; /* Work around bogus warning */
35562 unsigned long mapping_size;
35563 ELF(Ehdr) *hdr = (ELF(Ehdr) *)raw_addr;
35564- int i;
35565+ unsigned int i;
35566 unsigned long j;
35567 ELF(Shdr) *symtab_hdr = NULL, *strtab_hdr, *secstrings_hdr,
35568 *alt_sec = NULL;
35569diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35570index e904c27..b9eaa03 100644
35571--- a/arch/x86/vdso/vdso32-setup.c
35572+++ b/arch/x86/vdso/vdso32-setup.c
35573@@ -14,6 +14,7 @@
35574 #include <asm/cpufeature.h>
35575 #include <asm/processor.h>
35576 #include <asm/vdso.h>
35577+#include <asm/mman.h>
35578
35579 #ifdef CONFIG_COMPAT_VDSO
35580 #define VDSO_DEFAULT 0
35581diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35582index 970463b..da82d3e 100644
35583--- a/arch/x86/vdso/vma.c
35584+++ b/arch/x86/vdso/vma.c
35585@@ -16,10 +16,9 @@
35586 #include <asm/vdso.h>
35587 #include <asm/page.h>
35588 #include <asm/hpet.h>
35589+#include <asm/mman.h>
35590
35591 #if defined(CONFIG_X86_64)
35592-unsigned int __read_mostly vdso64_enabled = 1;
35593-
35594 extern unsigned short vdso_sync_cpuid;
35595 #endif
35596
35597@@ -101,6 +100,11 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
35598 .pages = no_pages,
35599 };
35600
35601+#ifdef CONFIG_PAX_RANDMMAP
35602+ if (mm->pax_flags & MF_PAX_RANDMMAP)
35603+ calculate_addr = false;
35604+#endif
35605+
35606 if (calculate_addr) {
35607 addr = vdso_addr(current->mm->start_stack,
35608 image->size - image->sym_vvar_start);
35609@@ -111,14 +115,14 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
35610 down_write(&mm->mmap_sem);
35611
35612 addr = get_unmapped_area(NULL, addr,
35613- image->size - image->sym_vvar_start, 0, 0);
35614+ image->size - image->sym_vvar_start, 0, MAP_EXECUTABLE);
35615 if (IS_ERR_VALUE(addr)) {
35616 ret = addr;
35617 goto up_fail;
35618 }
35619
35620 text_start = addr - image->sym_vvar_start;
35621- current->mm->context.vdso = (void __user *)text_start;
35622+ mm->context.vdso = text_start;
35623
35624 /*
35625 * MAYWRITE to allow gdb to COW and set breakpoints
35626@@ -163,15 +167,12 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
35627 hpet_address >> PAGE_SHIFT,
35628 PAGE_SIZE,
35629 pgprot_noncached(PAGE_READONLY));
35630-
35631- if (ret)
35632- goto up_fail;
35633 }
35634 #endif
35635
35636 up_fail:
35637 if (ret)
35638- current->mm->context.vdso = NULL;
35639+ current->mm->context.vdso = 0;
35640
35641 up_write(&mm->mmap_sem);
35642 return ret;
35643@@ -191,8 +192,8 @@ static int load_vdso32(void)
35644
35645 if (selected_vdso32->sym_VDSO32_SYSENTER_RETURN)
35646 current_thread_info()->sysenter_return =
35647- current->mm->context.vdso +
35648- selected_vdso32->sym_VDSO32_SYSENTER_RETURN;
35649+ (void __force_user *)(current->mm->context.vdso +
35650+ selected_vdso32->sym_VDSO32_SYSENTER_RETURN);
35651
35652 return 0;
35653 }
35654@@ -201,9 +202,6 @@ static int load_vdso32(void)
35655 #ifdef CONFIG_X86_64
35656 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35657 {
35658- if (!vdso64_enabled)
35659- return 0;
35660-
35661 return map_vdso(&vdso_image_64, true);
35662 }
35663
35664@@ -212,12 +210,8 @@ int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
35665 int uses_interp)
35666 {
35667 #ifdef CONFIG_X86_X32_ABI
35668- if (test_thread_flag(TIF_X32)) {
35669- if (!vdso64_enabled)
35670- return 0;
35671-
35672+ if (test_thread_flag(TIF_X32))
35673 return map_vdso(&vdso_image_x32, true);
35674- }
35675 #endif
35676
35677 return load_vdso32();
35678@@ -229,12 +223,3 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35679 return load_vdso32();
35680 }
35681 #endif
35682-
35683-#ifdef CONFIG_X86_64
35684-static __init int vdso_setup(char *s)
35685-{
35686- vdso64_enabled = simple_strtoul(s, NULL, 0);
35687- return 0;
35688-}
35689-__setup("vdso=", vdso_setup);
35690-#endif
35691diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35692index e88fda8..76ce7ce 100644
35693--- a/arch/x86/xen/Kconfig
35694+++ b/arch/x86/xen/Kconfig
35695@@ -9,6 +9,7 @@ config XEN
35696 select XEN_HAVE_PVMMU
35697 depends on X86_64 || (X86_32 && X86_PAE)
35698 depends on X86_TSC
35699+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35700 help
35701 This is the Linux Xen port. Enabling this will allow the
35702 kernel to boot in a paravirtualized environment under the
35703diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35704index fac5e4f..5b5cf4f 100644
35705--- a/arch/x86/xen/enlighten.c
35706+++ b/arch/x86/xen/enlighten.c
35707@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35708
35709 struct shared_info xen_dummy_shared_info;
35710
35711-void *xen_initial_gdt;
35712-
35713 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35714 __read_mostly int xen_have_vector_callback;
35715 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35716@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35717 {
35718 unsigned long va = dtr->address;
35719 unsigned int size = dtr->size + 1;
35720- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35721- unsigned long frames[pages];
35722+ unsigned long frames[65536 / PAGE_SIZE];
35723 int f;
35724
35725 /*
35726@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35727 {
35728 unsigned long va = dtr->address;
35729 unsigned int size = dtr->size + 1;
35730- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35731- unsigned long frames[pages];
35732+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35733 int f;
35734
35735 /*
35736@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35737 * 8-byte entries, or 16 4k pages..
35738 */
35739
35740- BUG_ON(size > 65536);
35741+ BUG_ON(size > GDT_SIZE);
35742 BUG_ON(va & ~PAGE_MASK);
35743
35744 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35745@@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35746 return 0;
35747 }
35748
35749-static void set_xen_basic_apic_ops(void)
35750+static void __init set_xen_basic_apic_ops(void)
35751 {
35752 apic->read = xen_apic_read;
35753 apic->write = xen_apic_write;
35754@@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35755 #endif
35756 };
35757
35758-static void xen_reboot(int reason)
35759+static __noreturn void xen_reboot(int reason)
35760 {
35761 struct sched_shutdown r = { .reason = reason };
35762
35763- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35764- BUG();
35765+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35766+ BUG();
35767 }
35768
35769-static void xen_restart(char *msg)
35770+static __noreturn void xen_restart(char *msg)
35771 {
35772 xen_reboot(SHUTDOWN_reboot);
35773 }
35774
35775-static void xen_emergency_restart(void)
35776+static __noreturn void xen_emergency_restart(void)
35777 {
35778 xen_reboot(SHUTDOWN_reboot);
35779 }
35780
35781-static void xen_machine_halt(void)
35782+static __noreturn void xen_machine_halt(void)
35783 {
35784 xen_reboot(SHUTDOWN_poweroff);
35785 }
35786
35787-static void xen_machine_power_off(void)
35788+static __noreturn void xen_machine_power_off(void)
35789 {
35790 if (pm_power_off)
35791 pm_power_off();
35792@@ -1573,7 +1569,17 @@ asmlinkage __visible void __init xen_start_kernel(void)
35793 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35794
35795 /* Work out if we support NX */
35796- x86_configure_nx();
35797+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35798+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35799+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35800+ unsigned l, h;
35801+
35802+ __supported_pte_mask |= _PAGE_NX;
35803+ rdmsr(MSR_EFER, l, h);
35804+ l |= EFER_NX;
35805+ wrmsr(MSR_EFER, l, h);
35806+ }
35807+#endif
35808
35809 /* Get mfn list */
35810 xen_build_dynamic_phys_to_machine();
35811@@ -1601,13 +1607,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
35812
35813 machine_ops = xen_machine_ops;
35814
35815- /*
35816- * The only reliable way to retain the initial address of the
35817- * percpu gdt_page is to remember it here, so we can go and
35818- * mark it RW later, when the initial percpu area is freed.
35819- */
35820- xen_initial_gdt = &per_cpu(gdt_page, 0);
35821-
35822 xen_smp_init();
35823
35824 #ifdef CONFIG_ACPI_NUMA
35825diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35826index a8a1a3d..8216142 100644
35827--- a/arch/x86/xen/mmu.c
35828+++ b/arch/x86/xen/mmu.c
35829@@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35830 return val;
35831 }
35832
35833-static pteval_t pte_pfn_to_mfn(pteval_t val)
35834+static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35835 {
35836 if (val & _PAGE_PRESENT) {
35837 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35838@@ -1867,7 +1867,11 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35839 * L3_k[511] -> level2_fixmap_pgt */
35840 convert_pfn_mfn(level3_kernel_pgt);
35841
35842+ convert_pfn_mfn(level3_vmalloc_start_pgt);
35843+ convert_pfn_mfn(level3_vmalloc_end_pgt);
35844+ convert_pfn_mfn(level3_vmemmap_pgt);
35845 /* L3_k[511][506] -> level1_fixmap_pgt */
35846+ /* L3_k[511][507] -> level1_vsyscall_pgt */
35847 convert_pfn_mfn(level2_fixmap_pgt);
35848 }
35849 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35850@@ -1892,11 +1896,16 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35851 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35852 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35853 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35854+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35855+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35856+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35857 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35858 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35859+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35860 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35861 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35862 set_page_prot(level1_fixmap_pgt, PAGE_KERNEL_RO);
35863+ set_page_prot(level1_vsyscall_pgt, PAGE_KERNEL_RO);
35864
35865 /* Pin down new L4 */
35866 pin_pagetable_pfn(MMUEXT_PIN_L4_TABLE,
35867@@ -2080,6 +2089,7 @@ static void __init xen_post_allocator_init(void)
35868 pv_mmu_ops.set_pud = xen_set_pud;
35869 #if PAGETABLE_LEVELS == 4
35870 pv_mmu_ops.set_pgd = xen_set_pgd;
35871+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35872 #endif
35873
35874 /* This will work as long as patching hasn't happened yet
35875@@ -2158,6 +2168,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35876 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35877 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35878 .set_pgd = xen_set_pgd_hyper,
35879+ .set_pgd_batched = xen_set_pgd_hyper,
35880
35881 .alloc_pud = xen_alloc_pmd_init,
35882 .release_pud = xen_release_pmd_init,
35883diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35884index 4c071ae..00e7049 100644
35885--- a/arch/x86/xen/smp.c
35886+++ b/arch/x86/xen/smp.c
35887@@ -288,17 +288,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
35888
35889 if (xen_pv_domain()) {
35890 if (!xen_feature(XENFEAT_writable_page_tables))
35891- /* We've switched to the "real" per-cpu gdt, so make
35892- * sure the old memory can be recycled. */
35893- make_lowmem_page_readwrite(xen_initial_gdt);
35894-
35895 #ifdef CONFIG_X86_32
35896 /*
35897 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
35898 * expects __USER_DS
35899 */
35900- loadsegment(ds, __USER_DS);
35901- loadsegment(es, __USER_DS);
35902+ loadsegment(ds, __KERNEL_DS);
35903+ loadsegment(es, __KERNEL_DS);
35904 #endif
35905
35906 xen_filter_cpu_maps();
35907@@ -379,7 +375,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35908 #ifdef CONFIG_X86_32
35909 /* Note: PVH is not yet supported on x86_32. */
35910 ctxt->user_regs.fs = __KERNEL_PERCPU;
35911- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35912+ savesegment(gs, ctxt->user_regs.gs);
35913 #endif
35914 memset(&ctxt->fpu_ctxt, 0, sizeof(ctxt->fpu_ctxt));
35915
35916@@ -387,8 +383,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35917 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
35918 ctxt->flags = VGCF_IN_KERNEL;
35919 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35920- ctxt->user_regs.ds = __USER_DS;
35921- ctxt->user_regs.es = __USER_DS;
35922+ ctxt->user_regs.ds = __KERNEL_DS;
35923+ ctxt->user_regs.es = __KERNEL_DS;
35924 ctxt->user_regs.ss = __KERNEL_DS;
35925
35926 xen_copy_trap_info(ctxt->trap_ctxt);
35927@@ -446,14 +442,13 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35928 int rc;
35929
35930 per_cpu(current_task, cpu) = idle;
35931+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
35932 #ifdef CONFIG_X86_32
35933 irq_ctx_init(cpu);
35934 #else
35935 clear_tsk_thread_flag(idle, TIF_FORK);
35936 #endif
35937- per_cpu(kernel_stack, cpu) =
35938- (unsigned long)task_stack_page(idle) -
35939- KERNEL_STACK_OFFSET + THREAD_SIZE;
35940+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
35941
35942 xen_setup_runstate_info(cpu);
35943 xen_setup_timer(cpu);
35944@@ -732,7 +727,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35945
35946 void __init xen_smp_init(void)
35947 {
35948- smp_ops = xen_smp_ops;
35949+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35950 xen_fill_possible_map();
35951 }
35952
35953diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35954index fd92a64..1f72641 100644
35955--- a/arch/x86/xen/xen-asm_32.S
35956+++ b/arch/x86/xen/xen-asm_32.S
35957@@ -99,7 +99,7 @@ ENTRY(xen_iret)
35958 pushw %fs
35959 movl $(__KERNEL_PERCPU), %eax
35960 movl %eax, %fs
35961- movl %fs:xen_vcpu, %eax
35962+ mov PER_CPU_VAR(xen_vcpu), %eax
35963 POP_FS
35964 #else
35965 movl %ss:xen_vcpu, %eax
35966diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
35967index 674b2225..f1f5dc1 100644
35968--- a/arch/x86/xen/xen-head.S
35969+++ b/arch/x86/xen/xen-head.S
35970@@ -39,6 +39,17 @@ ENTRY(startup_xen)
35971 #ifdef CONFIG_X86_32
35972 mov %esi,xen_start_info
35973 mov $init_thread_union+THREAD_SIZE,%esp
35974+#ifdef CONFIG_SMP
35975+ movl $cpu_gdt_table,%edi
35976+ movl $__per_cpu_load,%eax
35977+ movw %ax,__KERNEL_PERCPU + 2(%edi)
35978+ rorl $16,%eax
35979+ movb %al,__KERNEL_PERCPU + 4(%edi)
35980+ movb %ah,__KERNEL_PERCPU + 7(%edi)
35981+ movl $__per_cpu_end - 1,%eax
35982+ subl $__per_cpu_start,%eax
35983+ movw %ax,__KERNEL_PERCPU + 0(%edi)
35984+#endif
35985 #else
35986 mov %rsi,xen_start_info
35987 mov $init_thread_union+THREAD_SIZE,%rsp
35988diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35989index 28c7e0b..2acfec7 100644
35990--- a/arch/x86/xen/xen-ops.h
35991+++ b/arch/x86/xen/xen-ops.h
35992@@ -10,8 +10,6 @@
35993 extern const char xen_hypervisor_callback[];
35994 extern const char xen_failsafe_callback[];
35995
35996-extern void *xen_initial_gdt;
35997-
35998 struct trap_info;
35999 void xen_copy_trap_info(struct trap_info *traps);
36000
36001diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
36002index 525bd3d..ef888b1 100644
36003--- a/arch/xtensa/variants/dc232b/include/variant/core.h
36004+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
36005@@ -119,9 +119,9 @@
36006 ----------------------------------------------------------------------*/
36007
36008 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
36009-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
36010 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
36011 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
36012+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36013
36014 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
36015 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
36016diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
36017index 2f33760..835e50a 100644
36018--- a/arch/xtensa/variants/fsf/include/variant/core.h
36019+++ b/arch/xtensa/variants/fsf/include/variant/core.h
36020@@ -11,6 +11,7 @@
36021 #ifndef _XTENSA_CORE_H
36022 #define _XTENSA_CORE_H
36023
36024+#include <linux/const.h>
36025
36026 /****************************************************************************
36027 Parameters Useful for Any Code, USER or PRIVILEGED
36028@@ -112,9 +113,9 @@
36029 ----------------------------------------------------------------------*/
36030
36031 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36032-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36033 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36034 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36035+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36036
36037 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
36038 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
36039diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
36040index af00795..2bb8105 100644
36041--- a/arch/xtensa/variants/s6000/include/variant/core.h
36042+++ b/arch/xtensa/variants/s6000/include/variant/core.h
36043@@ -11,6 +11,7 @@
36044 #ifndef _XTENSA_CORE_CONFIGURATION_H
36045 #define _XTENSA_CORE_CONFIGURATION_H
36046
36047+#include <linux/const.h>
36048
36049 /****************************************************************************
36050 Parameters Useful for Any Code, USER or PRIVILEGED
36051@@ -118,9 +119,9 @@
36052 ----------------------------------------------------------------------*/
36053
36054 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36055-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36056 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36057 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36058+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36059
36060 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
36061 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
36062diff --git a/block/bio.c b/block/bio.c
36063index 3e6e198..5c65199 100644
36064--- a/block/bio.c
36065+++ b/block/bio.c
36066@@ -1163,7 +1163,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
36067 /*
36068 * Overflow, abort
36069 */
36070- if (end < start)
36071+ if (end < start || end - start > INT_MAX - nr_pages)
36072 return ERR_PTR(-EINVAL);
36073
36074 nr_pages += end - start;
36075@@ -1297,7 +1297,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
36076 /*
36077 * Overflow, abort
36078 */
36079- if (end < start)
36080+ if (end < start || end - start > INT_MAX - nr_pages)
36081 return ERR_PTR(-EINVAL);
36082
36083 nr_pages += end - start;
36084@@ -1559,7 +1559,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
36085 const int read = bio_data_dir(bio) == READ;
36086 struct bio_map_data *bmd = bio->bi_private;
36087 int i;
36088- char *p = bmd->sgvecs[0].iov_base;
36089+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
36090
36091 bio_for_each_segment_all(bvec, bio, i) {
36092 char *addr = page_address(bvec->bv_page);
36093diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
36094index 0736729..2ec3b48 100644
36095--- a/block/blk-iopoll.c
36096+++ b/block/blk-iopoll.c
36097@@ -74,7 +74,7 @@ void blk_iopoll_complete(struct blk_iopoll *iop)
36098 }
36099 EXPORT_SYMBOL(blk_iopoll_complete);
36100
36101-static void blk_iopoll_softirq(struct softirq_action *h)
36102+static __latent_entropy void blk_iopoll_softirq(void)
36103 {
36104 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
36105 int rearm = 0, budget = blk_iopoll_budget;
36106diff --git a/block/blk-map.c b/block/blk-map.c
36107index f890d43..97b0482 100644
36108--- a/block/blk-map.c
36109+++ b/block/blk-map.c
36110@@ -300,7 +300,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
36111 if (!len || !kbuf)
36112 return -EINVAL;
36113
36114- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
36115+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
36116 if (do_copy)
36117 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
36118 else
36119diff --git a/block/blk-softirq.c b/block/blk-softirq.c
36120index 53b1737..08177d2e 100644
36121--- a/block/blk-softirq.c
36122+++ b/block/blk-softirq.c
36123@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
36124 * Softirq action handler - move entries to local list and loop over them
36125 * while passing them to the queue registered handler.
36126 */
36127-static void blk_done_softirq(struct softirq_action *h)
36128+static __latent_entropy void blk_done_softirq(void)
36129 {
36130 struct list_head *cpu_list, local_list;
36131
36132diff --git a/block/bsg.c b/block/bsg.c
36133index 276e869..6fe4c61 100644
36134--- a/block/bsg.c
36135+++ b/block/bsg.c
36136@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
36137 struct sg_io_v4 *hdr, struct bsg_device *bd,
36138 fmode_t has_write_perm)
36139 {
36140+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36141+ unsigned char *cmdptr;
36142+
36143 if (hdr->request_len > BLK_MAX_CDB) {
36144 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
36145 if (!rq->cmd)
36146 return -ENOMEM;
36147- }
36148+ cmdptr = rq->cmd;
36149+ } else
36150+ cmdptr = tmpcmd;
36151
36152- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
36153+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
36154 hdr->request_len))
36155 return -EFAULT;
36156
36157+ if (cmdptr != rq->cmd)
36158+ memcpy(rq->cmd, cmdptr, hdr->request_len);
36159+
36160 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
36161 if (blk_verify_command(rq->cmd, has_write_perm))
36162 return -EPERM;
36163diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
36164index f678c73..f35aa18 100644
36165--- a/block/compat_ioctl.c
36166+++ b/block/compat_ioctl.c
36167@@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
36168 cgc = compat_alloc_user_space(sizeof(*cgc));
36169 cgc32 = compat_ptr(arg);
36170
36171- if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
36172+ if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
36173 get_user(data, &cgc32->buffer) ||
36174 put_user(compat_ptr(data), &cgc->buffer) ||
36175 copy_in_user(&cgc->buflen, &cgc32->buflen,
36176@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
36177 err |= __get_user(f->spec1, &uf->spec1);
36178 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
36179 err |= __get_user(name, &uf->name);
36180- f->name = compat_ptr(name);
36181+ f->name = (void __force_kernel *)compat_ptr(name);
36182 if (err) {
36183 err = -EFAULT;
36184 goto out;
36185diff --git a/block/genhd.c b/block/genhd.c
36186index bd30606..bbc9b90 100644
36187--- a/block/genhd.c
36188+++ b/block/genhd.c
36189@@ -469,21 +469,24 @@ static char *bdevt_str(dev_t devt, char *buf)
36190
36191 /*
36192 * Register device numbers dev..(dev+range-1)
36193- * range must be nonzero
36194+ * Noop if @range is zero.
36195 * The hash chain is sorted on range, so that subranges can override.
36196 */
36197 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
36198 struct kobject *(*probe)(dev_t, int *, void *),
36199 int (*lock)(dev_t, void *), void *data)
36200 {
36201- kobj_map(bdev_map, devt, range, module, probe, lock, data);
36202+ if (range)
36203+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
36204 }
36205
36206 EXPORT_SYMBOL(blk_register_region);
36207
36208+/* undo blk_register_region(), noop if @range is zero */
36209 void blk_unregister_region(dev_t devt, unsigned long range)
36210 {
36211- kobj_unmap(bdev_map, devt, range);
36212+ if (range)
36213+ kobj_unmap(bdev_map, devt, range);
36214 }
36215
36216 EXPORT_SYMBOL(blk_unregister_region);
36217diff --git a/block/partitions/efi.c b/block/partitions/efi.c
36218index 56d08fd..2e07090 100644
36219--- a/block/partitions/efi.c
36220+++ b/block/partitions/efi.c
36221@@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
36222 if (!gpt)
36223 return NULL;
36224
36225+ if (!le32_to_cpu(gpt->num_partition_entries))
36226+ return NULL;
36227+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
36228+ if (!pte)
36229+ return NULL;
36230+
36231 count = le32_to_cpu(gpt->num_partition_entries) *
36232 le32_to_cpu(gpt->sizeof_partition_entry);
36233- if (!count)
36234- return NULL;
36235- pte = kmalloc(count, GFP_KERNEL);
36236- if (!pte)
36237- return NULL;
36238-
36239 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
36240 (u8 *) pte, count) < count) {
36241 kfree(pte);
36242diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
36243index b0c2a61..10bb6ec 100644
36244--- a/block/scsi_ioctl.c
36245+++ b/block/scsi_ioctl.c
36246@@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
36247 return put_user(0, p);
36248 }
36249
36250-static int sg_get_timeout(struct request_queue *q)
36251+static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
36252 {
36253 return jiffies_to_clock_t(q->sg_timeout);
36254 }
36255@@ -227,8 +227,20 @@ EXPORT_SYMBOL(blk_verify_command);
36256 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
36257 struct sg_io_hdr *hdr, fmode_t mode)
36258 {
36259- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
36260+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36261+ unsigned char *cmdptr;
36262+
36263+ if (rq->cmd != rq->__cmd)
36264+ cmdptr = rq->cmd;
36265+ else
36266+ cmdptr = tmpcmd;
36267+
36268+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
36269 return -EFAULT;
36270+
36271+ if (cmdptr != rq->cmd)
36272+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
36273+
36274 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
36275 return -EPERM;
36276
36277@@ -431,6 +443,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36278 int err;
36279 unsigned int in_len, out_len, bytes, opcode, cmdlen;
36280 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
36281+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36282+ unsigned char *cmdptr;
36283
36284 if (!sic)
36285 return -EINVAL;
36286@@ -469,9 +483,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36287 */
36288 err = -EFAULT;
36289 rq->cmd_len = cmdlen;
36290- if (copy_from_user(rq->cmd, sic->data, cmdlen))
36291+
36292+ if (rq->cmd != rq->__cmd)
36293+ cmdptr = rq->cmd;
36294+ else
36295+ cmdptr = tmpcmd;
36296+
36297+ if (copy_from_user(cmdptr, sic->data, cmdlen))
36298 goto error;
36299
36300+ if (rq->cmd != cmdptr)
36301+ memcpy(rq->cmd, cmdptr, cmdlen);
36302+
36303 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
36304 goto error;
36305
36306diff --git a/crypto/cryptd.c b/crypto/cryptd.c
36307index e592c90..c566114 100644
36308--- a/crypto/cryptd.c
36309+++ b/crypto/cryptd.c
36310@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
36311
36312 struct cryptd_blkcipher_request_ctx {
36313 crypto_completion_t complete;
36314-};
36315+} __no_const;
36316
36317 struct cryptd_hash_ctx {
36318 struct crypto_shash *child;
36319@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
36320
36321 struct cryptd_aead_request_ctx {
36322 crypto_completion_t complete;
36323-};
36324+} __no_const;
36325
36326 static void cryptd_queue_worker(struct work_struct *work);
36327
36328diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
36329index 309d345..1632720 100644
36330--- a/crypto/pcrypt.c
36331+++ b/crypto/pcrypt.c
36332@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
36333 int ret;
36334
36335 pinst->kobj.kset = pcrypt_kset;
36336- ret = kobject_add(&pinst->kobj, NULL, name);
36337+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
36338 if (!ret)
36339 kobject_uevent(&pinst->kobj, KOBJ_ADD);
36340
36341diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
36342index 6921c7f..78e1af7 100644
36343--- a/drivers/acpi/acpica/hwxfsleep.c
36344+++ b/drivers/acpi/acpica/hwxfsleep.c
36345@@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
36346 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
36347
36348 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
36349- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36350- acpi_hw_extended_sleep},
36351- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36352- acpi_hw_extended_wake_prep},
36353- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
36354+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36355+ .extended_function = acpi_hw_extended_sleep},
36356+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36357+ .extended_function = acpi_hw_extended_wake_prep},
36358+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
36359+ .extended_function = acpi_hw_extended_wake}
36360 };
36361
36362 /*
36363diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
36364index 16129c7..8b675cd 100644
36365--- a/drivers/acpi/apei/apei-internal.h
36366+++ b/drivers/acpi/apei/apei-internal.h
36367@@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
36368 struct apei_exec_ins_type {
36369 u32 flags;
36370 apei_exec_ins_func_t run;
36371-};
36372+} __do_const;
36373
36374 struct apei_exec_context {
36375 u32 ip;
36376diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
36377index fc5f780..e5ac91a 100644
36378--- a/drivers/acpi/apei/ghes.c
36379+++ b/drivers/acpi/apei/ghes.c
36380@@ -478,7 +478,7 @@ static void __ghes_print_estatus(const char *pfx,
36381 const struct acpi_hest_generic *generic,
36382 const struct acpi_hest_generic_status *estatus)
36383 {
36384- static atomic_t seqno;
36385+ static atomic_unchecked_t seqno;
36386 unsigned int curr_seqno;
36387 char pfx_seq[64];
36388
36389@@ -489,7 +489,7 @@ static void __ghes_print_estatus(const char *pfx,
36390 else
36391 pfx = KERN_ERR;
36392 }
36393- curr_seqno = atomic_inc_return(&seqno);
36394+ curr_seqno = atomic_inc_return_unchecked(&seqno);
36395 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
36396 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
36397 pfx_seq, generic->header.source_id);
36398diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
36399index a83e3c6..c3d617f 100644
36400--- a/drivers/acpi/bgrt.c
36401+++ b/drivers/acpi/bgrt.c
36402@@ -86,8 +86,10 @@ static int __init bgrt_init(void)
36403 if (!bgrt_image)
36404 return -ENODEV;
36405
36406- bin_attr_image.private = bgrt_image;
36407- bin_attr_image.size = bgrt_image_size;
36408+ pax_open_kernel();
36409+ *(void **)&bin_attr_image.private = bgrt_image;
36410+ *(size_t *)&bin_attr_image.size = bgrt_image_size;
36411+ pax_close_kernel();
36412
36413 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36414 if (!bgrt_kobj)
36415diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36416index 7556e7c..89a96bd 100644
36417--- a/drivers/acpi/blacklist.c
36418+++ b/drivers/acpi/blacklist.c
36419@@ -51,7 +51,7 @@ struct acpi_blacklist_item {
36420 u32 is_critical_error;
36421 };
36422
36423-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36424+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36425
36426 /*
36427 * POLICY: If *anything* doesn't work, put it on the blacklist.
36428@@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36429 return 0;
36430 }
36431
36432-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36433+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36434 {
36435 .callback = dmi_disable_osi_vista,
36436 .ident = "Fujitsu Siemens",
36437diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36438index c68e724..e863008 100644
36439--- a/drivers/acpi/custom_method.c
36440+++ b/drivers/acpi/custom_method.c
36441@@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36442 struct acpi_table_header table;
36443 acpi_status status;
36444
36445+#ifdef CONFIG_GRKERNSEC_KMEM
36446+ return -EPERM;
36447+#endif
36448+
36449 if (!(*ppos)) {
36450 /* parse the table header to get the table length */
36451 if (count <= sizeof(struct acpi_table_header))
36452diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
36453index 7db1931..302dd5f 100644
36454--- a/drivers/acpi/device_pm.c
36455+++ b/drivers/acpi/device_pm.c
36456@@ -1021,6 +1021,8 @@ EXPORT_SYMBOL_GPL(acpi_subsys_freeze);
36457
36458 #endif /* CONFIG_PM_SLEEP */
36459
36460+static void acpi_dev_pm_detach(struct device *dev, bool power_off);
36461+
36462 static struct dev_pm_domain acpi_general_pm_domain = {
36463 .ops = {
36464 #ifdef CONFIG_PM_RUNTIME
36465@@ -1039,6 +1041,7 @@ static struct dev_pm_domain acpi_general_pm_domain = {
36466 .restore_early = acpi_subsys_resume_early,
36467 #endif
36468 },
36469+ .detach = acpi_dev_pm_detach
36470 };
36471
36472 /**
36473@@ -1108,7 +1111,6 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on)
36474 acpi_device_wakeup(adev, ACPI_STATE_S0, false);
36475 }
36476
36477- dev->pm_domain->detach = acpi_dev_pm_detach;
36478 return 0;
36479 }
36480 EXPORT_SYMBOL_GPL(acpi_dev_pm_attach);
36481diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36482index 17f9ec5..d9a455e 100644
36483--- a/drivers/acpi/processor_idle.c
36484+++ b/drivers/acpi/processor_idle.c
36485@@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36486 {
36487 int i, count = CPUIDLE_DRIVER_STATE_START;
36488 struct acpi_processor_cx *cx;
36489- struct cpuidle_state *state;
36490+ cpuidle_state_no_const *state;
36491 struct cpuidle_driver *drv = &acpi_idle_driver;
36492
36493 if (!pr->flags.power_setup_done)
36494diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36495index 13e577c..cef11ee 100644
36496--- a/drivers/acpi/sysfs.c
36497+++ b/drivers/acpi/sysfs.c
36498@@ -423,11 +423,11 @@ static u32 num_counters;
36499 static struct attribute **all_attrs;
36500 static u32 acpi_gpe_count;
36501
36502-static struct attribute_group interrupt_stats_attr_group = {
36503+static attribute_group_no_const interrupt_stats_attr_group = {
36504 .name = "interrupts",
36505 };
36506
36507-static struct kobj_attribute *counter_attrs;
36508+static kobj_attribute_no_const *counter_attrs;
36509
36510 static void delete_gpe_attr_array(void)
36511 {
36512diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36513index 97683e4..655f6ba 100644
36514--- a/drivers/ata/libahci.c
36515+++ b/drivers/ata/libahci.c
36516@@ -1252,7 +1252,7 @@ int ahci_kick_engine(struct ata_port *ap)
36517 }
36518 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36519
36520-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36521+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36522 struct ata_taskfile *tf, int is_cmd, u16 flags,
36523 unsigned long timeout_msec)
36524 {
36525diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36526index c5ba15a..75ec7a8 100644
36527--- a/drivers/ata/libata-core.c
36528+++ b/drivers/ata/libata-core.c
36529@@ -99,7 +99,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36530 static void ata_dev_xfermask(struct ata_device *dev);
36531 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36532
36533-atomic_t ata_print_id = ATOMIC_INIT(0);
36534+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36535
36536 struct ata_force_param {
36537 const char *name;
36538@@ -4797,7 +4797,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36539 struct ata_port *ap;
36540 unsigned int tag;
36541
36542- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36543+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36544 ap = qc->ap;
36545
36546 qc->flags = 0;
36547@@ -4813,7 +4813,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36548 struct ata_port *ap;
36549 struct ata_link *link;
36550
36551- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36552+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36553 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36554 ap = qc->ap;
36555 link = qc->dev->link;
36556@@ -5917,6 +5917,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36557 return;
36558
36559 spin_lock(&lock);
36560+ pax_open_kernel();
36561
36562 for (cur = ops->inherits; cur; cur = cur->inherits) {
36563 void **inherit = (void **)cur;
36564@@ -5930,8 +5931,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36565 if (IS_ERR(*pp))
36566 *pp = NULL;
36567
36568- ops->inherits = NULL;
36569+ *(struct ata_port_operations **)&ops->inherits = NULL;
36570
36571+ pax_close_kernel();
36572 spin_unlock(&lock);
36573 }
36574
36575@@ -6127,7 +6129,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36576
36577 /* give ports names and add SCSI hosts */
36578 for (i = 0; i < host->n_ports; i++) {
36579- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36580+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36581 host->ports[i]->local_port_no = i + 1;
36582 }
36583
36584diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36585index 0586f66..1a8f74a 100644
36586--- a/drivers/ata/libata-scsi.c
36587+++ b/drivers/ata/libata-scsi.c
36588@@ -4151,7 +4151,7 @@ int ata_sas_port_init(struct ata_port *ap)
36589
36590 if (rc)
36591 return rc;
36592- ap->print_id = atomic_inc_return(&ata_print_id);
36593+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36594 return 0;
36595 }
36596 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36597diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36598index 5f4e0cc..ff2c347 100644
36599--- a/drivers/ata/libata.h
36600+++ b/drivers/ata/libata.h
36601@@ -53,7 +53,7 @@ enum {
36602 ATA_DNXFER_QUIET = (1 << 31),
36603 };
36604
36605-extern atomic_t ata_print_id;
36606+extern atomic_unchecked_t ata_print_id;
36607 extern int atapi_passthru16;
36608 extern int libata_fua;
36609 extern int libata_noacpi;
36610diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36611index 38216b9..4ec6aeb 100644
36612--- a/drivers/ata/pata_arasan_cf.c
36613+++ b/drivers/ata/pata_arasan_cf.c
36614@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36615 /* Handle platform specific quirks */
36616 if (quirk) {
36617 if (quirk & CF_BROKEN_PIO) {
36618- ap->ops->set_piomode = NULL;
36619+ pax_open_kernel();
36620+ *(void **)&ap->ops->set_piomode = NULL;
36621+ pax_close_kernel();
36622 ap->pio_mask = 0;
36623 }
36624 if (quirk & CF_BROKEN_MWDMA)
36625diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36626index f9b983a..887b9d8 100644
36627--- a/drivers/atm/adummy.c
36628+++ b/drivers/atm/adummy.c
36629@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36630 vcc->pop(vcc, skb);
36631 else
36632 dev_kfree_skb_any(skb);
36633- atomic_inc(&vcc->stats->tx);
36634+ atomic_inc_unchecked(&vcc->stats->tx);
36635
36636 return 0;
36637 }
36638diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36639index f1a9198..f466a4a 100644
36640--- a/drivers/atm/ambassador.c
36641+++ b/drivers/atm/ambassador.c
36642@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36643 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36644
36645 // VC layer stats
36646- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36647+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36648
36649 // free the descriptor
36650 kfree (tx_descr);
36651@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36652 dump_skb ("<<<", vc, skb);
36653
36654 // VC layer stats
36655- atomic_inc(&atm_vcc->stats->rx);
36656+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36657 __net_timestamp(skb);
36658 // end of our responsibility
36659 atm_vcc->push (atm_vcc, skb);
36660@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36661 } else {
36662 PRINTK (KERN_INFO, "dropped over-size frame");
36663 // should we count this?
36664- atomic_inc(&atm_vcc->stats->rx_drop);
36665+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36666 }
36667
36668 } else {
36669@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36670 }
36671
36672 if (check_area (skb->data, skb->len)) {
36673- atomic_inc(&atm_vcc->stats->tx_err);
36674+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36675 return -ENOMEM; // ?
36676 }
36677
36678diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36679index 480fa6f..947067c 100644
36680--- a/drivers/atm/atmtcp.c
36681+++ b/drivers/atm/atmtcp.c
36682@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36683 if (vcc->pop) vcc->pop(vcc,skb);
36684 else dev_kfree_skb(skb);
36685 if (dev_data) return 0;
36686- atomic_inc(&vcc->stats->tx_err);
36687+ atomic_inc_unchecked(&vcc->stats->tx_err);
36688 return -ENOLINK;
36689 }
36690 size = skb->len+sizeof(struct atmtcp_hdr);
36691@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36692 if (!new_skb) {
36693 if (vcc->pop) vcc->pop(vcc,skb);
36694 else dev_kfree_skb(skb);
36695- atomic_inc(&vcc->stats->tx_err);
36696+ atomic_inc_unchecked(&vcc->stats->tx_err);
36697 return -ENOBUFS;
36698 }
36699 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36700@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36701 if (vcc->pop) vcc->pop(vcc,skb);
36702 else dev_kfree_skb(skb);
36703 out_vcc->push(out_vcc,new_skb);
36704- atomic_inc(&vcc->stats->tx);
36705- atomic_inc(&out_vcc->stats->rx);
36706+ atomic_inc_unchecked(&vcc->stats->tx);
36707+ atomic_inc_unchecked(&out_vcc->stats->rx);
36708 return 0;
36709 }
36710
36711@@ -300,7 +300,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36712 read_unlock(&vcc_sklist_lock);
36713 if (!out_vcc) {
36714 result = -EUNATCH;
36715- atomic_inc(&vcc->stats->tx_err);
36716+ atomic_inc_unchecked(&vcc->stats->tx_err);
36717 goto done;
36718 }
36719 skb_pull(skb,sizeof(struct atmtcp_hdr));
36720@@ -312,8 +312,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36721 __net_timestamp(new_skb);
36722 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36723 out_vcc->push(out_vcc,new_skb);
36724- atomic_inc(&vcc->stats->tx);
36725- atomic_inc(&out_vcc->stats->rx);
36726+ atomic_inc_unchecked(&vcc->stats->tx);
36727+ atomic_inc_unchecked(&out_vcc->stats->rx);
36728 done:
36729 if (vcc->pop) vcc->pop(vcc,skb);
36730 else dev_kfree_skb(skb);
36731diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36732index d65975a..0b87e20 100644
36733--- a/drivers/atm/eni.c
36734+++ b/drivers/atm/eni.c
36735@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36736 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36737 vcc->dev->number);
36738 length = 0;
36739- atomic_inc(&vcc->stats->rx_err);
36740+ atomic_inc_unchecked(&vcc->stats->rx_err);
36741 }
36742 else {
36743 length = ATM_CELL_SIZE-1; /* no HEC */
36744@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36745 size);
36746 }
36747 eff = length = 0;
36748- atomic_inc(&vcc->stats->rx_err);
36749+ atomic_inc_unchecked(&vcc->stats->rx_err);
36750 }
36751 else {
36752 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36753@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36754 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36755 vcc->dev->number,vcc->vci,length,size << 2,descr);
36756 length = eff = 0;
36757- atomic_inc(&vcc->stats->rx_err);
36758+ atomic_inc_unchecked(&vcc->stats->rx_err);
36759 }
36760 }
36761 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36762@@ -767,7 +767,7 @@ rx_dequeued++;
36763 vcc->push(vcc,skb);
36764 pushed++;
36765 }
36766- atomic_inc(&vcc->stats->rx);
36767+ atomic_inc_unchecked(&vcc->stats->rx);
36768 }
36769 wake_up(&eni_dev->rx_wait);
36770 }
36771@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36772 PCI_DMA_TODEVICE);
36773 if (vcc->pop) vcc->pop(vcc,skb);
36774 else dev_kfree_skb_irq(skb);
36775- atomic_inc(&vcc->stats->tx);
36776+ atomic_inc_unchecked(&vcc->stats->tx);
36777 wake_up(&eni_dev->tx_wait);
36778 dma_complete++;
36779 }
36780diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36781index 82f2ae0..f205c02 100644
36782--- a/drivers/atm/firestream.c
36783+++ b/drivers/atm/firestream.c
36784@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36785 }
36786 }
36787
36788- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36789+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36790
36791 fs_dprintk (FS_DEBUG_TXMEM, "i");
36792 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36793@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36794 #endif
36795 skb_put (skb, qe->p1 & 0xffff);
36796 ATM_SKB(skb)->vcc = atm_vcc;
36797- atomic_inc(&atm_vcc->stats->rx);
36798+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36799 __net_timestamp(skb);
36800 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36801 atm_vcc->push (atm_vcc, skb);
36802@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36803 kfree (pe);
36804 }
36805 if (atm_vcc)
36806- atomic_inc(&atm_vcc->stats->rx_drop);
36807+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36808 break;
36809 case 0x1f: /* Reassembly abort: no buffers. */
36810 /* Silently increment error counter. */
36811 if (atm_vcc)
36812- atomic_inc(&atm_vcc->stats->rx_drop);
36813+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36814 break;
36815 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36816 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36817diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36818index d4725fc..2d4ea65 100644
36819--- a/drivers/atm/fore200e.c
36820+++ b/drivers/atm/fore200e.c
36821@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36822 #endif
36823 /* check error condition */
36824 if (*entry->status & STATUS_ERROR)
36825- atomic_inc(&vcc->stats->tx_err);
36826+ atomic_inc_unchecked(&vcc->stats->tx_err);
36827 else
36828- atomic_inc(&vcc->stats->tx);
36829+ atomic_inc_unchecked(&vcc->stats->tx);
36830 }
36831 }
36832
36833@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36834 if (skb == NULL) {
36835 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36836
36837- atomic_inc(&vcc->stats->rx_drop);
36838+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36839 return -ENOMEM;
36840 }
36841
36842@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36843
36844 dev_kfree_skb_any(skb);
36845
36846- atomic_inc(&vcc->stats->rx_drop);
36847+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36848 return -ENOMEM;
36849 }
36850
36851 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36852
36853 vcc->push(vcc, skb);
36854- atomic_inc(&vcc->stats->rx);
36855+ atomic_inc_unchecked(&vcc->stats->rx);
36856
36857 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36858
36859@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36860 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36861 fore200e->atm_dev->number,
36862 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36863- atomic_inc(&vcc->stats->rx_err);
36864+ atomic_inc_unchecked(&vcc->stats->rx_err);
36865 }
36866 }
36867
36868@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36869 goto retry_here;
36870 }
36871
36872- atomic_inc(&vcc->stats->tx_err);
36873+ atomic_inc_unchecked(&vcc->stats->tx_err);
36874
36875 fore200e->tx_sat++;
36876 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36877diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36878index c39702b..785b73b 100644
36879--- a/drivers/atm/he.c
36880+++ b/drivers/atm/he.c
36881@@ -1689,7 +1689,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36882
36883 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36884 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36885- atomic_inc(&vcc->stats->rx_drop);
36886+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36887 goto return_host_buffers;
36888 }
36889
36890@@ -1716,7 +1716,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36891 RBRQ_LEN_ERR(he_dev->rbrq_head)
36892 ? "LEN_ERR" : "",
36893 vcc->vpi, vcc->vci);
36894- atomic_inc(&vcc->stats->rx_err);
36895+ atomic_inc_unchecked(&vcc->stats->rx_err);
36896 goto return_host_buffers;
36897 }
36898
36899@@ -1768,7 +1768,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36900 vcc->push(vcc, skb);
36901 spin_lock(&he_dev->global_lock);
36902
36903- atomic_inc(&vcc->stats->rx);
36904+ atomic_inc_unchecked(&vcc->stats->rx);
36905
36906 return_host_buffers:
36907 ++pdus_assembled;
36908@@ -2094,7 +2094,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36909 tpd->vcc->pop(tpd->vcc, tpd->skb);
36910 else
36911 dev_kfree_skb_any(tpd->skb);
36912- atomic_inc(&tpd->vcc->stats->tx_err);
36913+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
36914 }
36915 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
36916 return;
36917@@ -2506,7 +2506,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36918 vcc->pop(vcc, skb);
36919 else
36920 dev_kfree_skb_any(skb);
36921- atomic_inc(&vcc->stats->tx_err);
36922+ atomic_inc_unchecked(&vcc->stats->tx_err);
36923 return -EINVAL;
36924 }
36925
36926@@ -2517,7 +2517,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36927 vcc->pop(vcc, skb);
36928 else
36929 dev_kfree_skb_any(skb);
36930- atomic_inc(&vcc->stats->tx_err);
36931+ atomic_inc_unchecked(&vcc->stats->tx_err);
36932 return -EINVAL;
36933 }
36934 #endif
36935@@ -2529,7 +2529,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36936 vcc->pop(vcc, skb);
36937 else
36938 dev_kfree_skb_any(skb);
36939- atomic_inc(&vcc->stats->tx_err);
36940+ atomic_inc_unchecked(&vcc->stats->tx_err);
36941 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36942 return -ENOMEM;
36943 }
36944@@ -2571,7 +2571,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36945 vcc->pop(vcc, skb);
36946 else
36947 dev_kfree_skb_any(skb);
36948- atomic_inc(&vcc->stats->tx_err);
36949+ atomic_inc_unchecked(&vcc->stats->tx_err);
36950 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36951 return -ENOMEM;
36952 }
36953@@ -2602,7 +2602,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36954 __enqueue_tpd(he_dev, tpd, cid);
36955 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36956
36957- atomic_inc(&vcc->stats->tx);
36958+ atomic_inc_unchecked(&vcc->stats->tx);
36959
36960 return 0;
36961 }
36962diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
36963index 1dc0519..1aadaf7 100644
36964--- a/drivers/atm/horizon.c
36965+++ b/drivers/atm/horizon.c
36966@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
36967 {
36968 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
36969 // VC layer stats
36970- atomic_inc(&vcc->stats->rx);
36971+ atomic_inc_unchecked(&vcc->stats->rx);
36972 __net_timestamp(skb);
36973 // end of our responsibility
36974 vcc->push (vcc, skb);
36975@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
36976 dev->tx_iovec = NULL;
36977
36978 // VC layer stats
36979- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36980+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36981
36982 // free the skb
36983 hrz_kfree_skb (skb);
36984diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
36985index 2b24ed0..b3d6acc 100644
36986--- a/drivers/atm/idt77252.c
36987+++ b/drivers/atm/idt77252.c
36988@@ -810,7 +810,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
36989 else
36990 dev_kfree_skb(skb);
36991
36992- atomic_inc(&vcc->stats->tx);
36993+ atomic_inc_unchecked(&vcc->stats->tx);
36994 }
36995
36996 atomic_dec(&scq->used);
36997@@ -1072,13 +1072,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36998 if ((sb = dev_alloc_skb(64)) == NULL) {
36999 printk("%s: Can't allocate buffers for aal0.\n",
37000 card->name);
37001- atomic_add(i, &vcc->stats->rx_drop);
37002+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
37003 break;
37004 }
37005 if (!atm_charge(vcc, sb->truesize)) {
37006 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
37007 card->name);
37008- atomic_add(i - 1, &vcc->stats->rx_drop);
37009+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
37010 dev_kfree_skb(sb);
37011 break;
37012 }
37013@@ -1095,7 +1095,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37014 ATM_SKB(sb)->vcc = vcc;
37015 __net_timestamp(sb);
37016 vcc->push(vcc, sb);
37017- atomic_inc(&vcc->stats->rx);
37018+ atomic_inc_unchecked(&vcc->stats->rx);
37019
37020 cell += ATM_CELL_PAYLOAD;
37021 }
37022@@ -1132,13 +1132,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37023 "(CDC: %08x)\n",
37024 card->name, len, rpp->len, readl(SAR_REG_CDC));
37025 recycle_rx_pool_skb(card, rpp);
37026- atomic_inc(&vcc->stats->rx_err);
37027+ atomic_inc_unchecked(&vcc->stats->rx_err);
37028 return;
37029 }
37030 if (stat & SAR_RSQE_CRC) {
37031 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
37032 recycle_rx_pool_skb(card, rpp);
37033- atomic_inc(&vcc->stats->rx_err);
37034+ atomic_inc_unchecked(&vcc->stats->rx_err);
37035 return;
37036 }
37037 if (skb_queue_len(&rpp->queue) > 1) {
37038@@ -1149,7 +1149,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37039 RXPRINTK("%s: Can't alloc RX skb.\n",
37040 card->name);
37041 recycle_rx_pool_skb(card, rpp);
37042- atomic_inc(&vcc->stats->rx_err);
37043+ atomic_inc_unchecked(&vcc->stats->rx_err);
37044 return;
37045 }
37046 if (!atm_charge(vcc, skb->truesize)) {
37047@@ -1168,7 +1168,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37048 __net_timestamp(skb);
37049
37050 vcc->push(vcc, skb);
37051- atomic_inc(&vcc->stats->rx);
37052+ atomic_inc_unchecked(&vcc->stats->rx);
37053
37054 return;
37055 }
37056@@ -1190,7 +1190,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37057 __net_timestamp(skb);
37058
37059 vcc->push(vcc, skb);
37060- atomic_inc(&vcc->stats->rx);
37061+ atomic_inc_unchecked(&vcc->stats->rx);
37062
37063 if (skb->truesize > SAR_FB_SIZE_3)
37064 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
37065@@ -1301,14 +1301,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
37066 if (vcc->qos.aal != ATM_AAL0) {
37067 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
37068 card->name, vpi, vci);
37069- atomic_inc(&vcc->stats->rx_drop);
37070+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37071 goto drop;
37072 }
37073
37074 if ((sb = dev_alloc_skb(64)) == NULL) {
37075 printk("%s: Can't allocate buffers for AAL0.\n",
37076 card->name);
37077- atomic_inc(&vcc->stats->rx_err);
37078+ atomic_inc_unchecked(&vcc->stats->rx_err);
37079 goto drop;
37080 }
37081
37082@@ -1327,7 +1327,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
37083 ATM_SKB(sb)->vcc = vcc;
37084 __net_timestamp(sb);
37085 vcc->push(vcc, sb);
37086- atomic_inc(&vcc->stats->rx);
37087+ atomic_inc_unchecked(&vcc->stats->rx);
37088
37089 drop:
37090 skb_pull(queue, 64);
37091@@ -1952,13 +1952,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37092
37093 if (vc == NULL) {
37094 printk("%s: NULL connection in send().\n", card->name);
37095- atomic_inc(&vcc->stats->tx_err);
37096+ atomic_inc_unchecked(&vcc->stats->tx_err);
37097 dev_kfree_skb(skb);
37098 return -EINVAL;
37099 }
37100 if (!test_bit(VCF_TX, &vc->flags)) {
37101 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
37102- atomic_inc(&vcc->stats->tx_err);
37103+ atomic_inc_unchecked(&vcc->stats->tx_err);
37104 dev_kfree_skb(skb);
37105 return -EINVAL;
37106 }
37107@@ -1970,14 +1970,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37108 break;
37109 default:
37110 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
37111- atomic_inc(&vcc->stats->tx_err);
37112+ atomic_inc_unchecked(&vcc->stats->tx_err);
37113 dev_kfree_skb(skb);
37114 return -EINVAL;
37115 }
37116
37117 if (skb_shinfo(skb)->nr_frags != 0) {
37118 printk("%s: No scatter-gather yet.\n", card->name);
37119- atomic_inc(&vcc->stats->tx_err);
37120+ atomic_inc_unchecked(&vcc->stats->tx_err);
37121 dev_kfree_skb(skb);
37122 return -EINVAL;
37123 }
37124@@ -1985,7 +1985,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37125
37126 err = queue_skb(card, vc, skb, oam);
37127 if (err) {
37128- atomic_inc(&vcc->stats->tx_err);
37129+ atomic_inc_unchecked(&vcc->stats->tx_err);
37130 dev_kfree_skb(skb);
37131 return err;
37132 }
37133@@ -2008,7 +2008,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
37134 skb = dev_alloc_skb(64);
37135 if (!skb) {
37136 printk("%s: Out of memory in send_oam().\n", card->name);
37137- atomic_inc(&vcc->stats->tx_err);
37138+ atomic_inc_unchecked(&vcc->stats->tx_err);
37139 return -ENOMEM;
37140 }
37141 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
37142diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
37143index 4217f29..88f547a 100644
37144--- a/drivers/atm/iphase.c
37145+++ b/drivers/atm/iphase.c
37146@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
37147 status = (u_short) (buf_desc_ptr->desc_mode);
37148 if (status & (RX_CER | RX_PTE | RX_OFL))
37149 {
37150- atomic_inc(&vcc->stats->rx_err);
37151+ atomic_inc_unchecked(&vcc->stats->rx_err);
37152 IF_ERR(printk("IA: bad packet, dropping it");)
37153 if (status & RX_CER) {
37154 IF_ERR(printk(" cause: packet CRC error\n");)
37155@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
37156 len = dma_addr - buf_addr;
37157 if (len > iadev->rx_buf_sz) {
37158 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
37159- atomic_inc(&vcc->stats->rx_err);
37160+ atomic_inc_unchecked(&vcc->stats->rx_err);
37161 goto out_free_desc;
37162 }
37163
37164@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37165 ia_vcc = INPH_IA_VCC(vcc);
37166 if (ia_vcc == NULL)
37167 {
37168- atomic_inc(&vcc->stats->rx_err);
37169+ atomic_inc_unchecked(&vcc->stats->rx_err);
37170 atm_return(vcc, skb->truesize);
37171 dev_kfree_skb_any(skb);
37172 goto INCR_DLE;
37173@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37174 if ((length > iadev->rx_buf_sz) || (length >
37175 (skb->len - sizeof(struct cpcs_trailer))))
37176 {
37177- atomic_inc(&vcc->stats->rx_err);
37178+ atomic_inc_unchecked(&vcc->stats->rx_err);
37179 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
37180 length, skb->len);)
37181 atm_return(vcc, skb->truesize);
37182@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37183
37184 IF_RX(printk("rx_dle_intr: skb push");)
37185 vcc->push(vcc,skb);
37186- atomic_inc(&vcc->stats->rx);
37187+ atomic_inc_unchecked(&vcc->stats->rx);
37188 iadev->rx_pkt_cnt++;
37189 }
37190 INCR_DLE:
37191@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
37192 {
37193 struct k_sonet_stats *stats;
37194 stats = &PRIV(_ia_dev[board])->sonet_stats;
37195- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
37196- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
37197- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
37198- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
37199- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
37200- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
37201- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
37202- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
37203- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
37204+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
37205+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
37206+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
37207+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
37208+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
37209+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
37210+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
37211+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
37212+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
37213 }
37214 ia_cmds.status = 0;
37215 break;
37216@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37217 if ((desc == 0) || (desc > iadev->num_tx_desc))
37218 {
37219 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
37220- atomic_inc(&vcc->stats->tx);
37221+ atomic_inc_unchecked(&vcc->stats->tx);
37222 if (vcc->pop)
37223 vcc->pop(vcc, skb);
37224 else
37225@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37226 ATM_DESC(skb) = vcc->vci;
37227 skb_queue_tail(&iadev->tx_dma_q, skb);
37228
37229- atomic_inc(&vcc->stats->tx);
37230+ atomic_inc_unchecked(&vcc->stats->tx);
37231 iadev->tx_pkt_cnt++;
37232 /* Increment transaction counter */
37233 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
37234
37235 #if 0
37236 /* add flow control logic */
37237- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
37238+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
37239 if (iavcc->vc_desc_cnt > 10) {
37240 vcc->tx_quota = vcc->tx_quota * 3 / 4;
37241 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
37242diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
37243index 93eaf8d..b4ca7da 100644
37244--- a/drivers/atm/lanai.c
37245+++ b/drivers/atm/lanai.c
37246@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
37247 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
37248 lanai_endtx(lanai, lvcc);
37249 lanai_free_skb(lvcc->tx.atmvcc, skb);
37250- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
37251+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
37252 }
37253
37254 /* Try to fill the buffer - don't call unless there is backlog */
37255@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
37256 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
37257 __net_timestamp(skb);
37258 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
37259- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
37260+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
37261 out:
37262 lvcc->rx.buf.ptr = end;
37263 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
37264@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37265 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
37266 "vcc %d\n", lanai->number, (unsigned int) s, vci);
37267 lanai->stats.service_rxnotaal5++;
37268- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37269+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37270 return 0;
37271 }
37272 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
37273@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37274 int bytes;
37275 read_unlock(&vcc_sklist_lock);
37276 DPRINTK("got trashed rx pdu on vci %d\n", vci);
37277- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37278+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37279 lvcc->stats.x.aal5.service_trash++;
37280 bytes = (SERVICE_GET_END(s) * 16) -
37281 (((unsigned long) lvcc->rx.buf.ptr) -
37282@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37283 }
37284 if (s & SERVICE_STREAM) {
37285 read_unlock(&vcc_sklist_lock);
37286- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37287+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37288 lvcc->stats.x.aal5.service_stream++;
37289 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
37290 "PDU on VCI %d!\n", lanai->number, vci);
37291@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37292 return 0;
37293 }
37294 DPRINTK("got rx crc error on vci %d\n", vci);
37295- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37296+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37297 lvcc->stats.x.aal5.service_rxcrc++;
37298 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
37299 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
37300diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
37301index 9988ac9..7c52585 100644
37302--- a/drivers/atm/nicstar.c
37303+++ b/drivers/atm/nicstar.c
37304@@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37305 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
37306 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
37307 card->index);
37308- atomic_inc(&vcc->stats->tx_err);
37309+ atomic_inc_unchecked(&vcc->stats->tx_err);
37310 dev_kfree_skb_any(skb);
37311 return -EINVAL;
37312 }
37313@@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37314 if (!vc->tx) {
37315 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
37316 card->index);
37317- atomic_inc(&vcc->stats->tx_err);
37318+ atomic_inc_unchecked(&vcc->stats->tx_err);
37319 dev_kfree_skb_any(skb);
37320 return -EINVAL;
37321 }
37322@@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37323 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
37324 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
37325 card->index);
37326- atomic_inc(&vcc->stats->tx_err);
37327+ atomic_inc_unchecked(&vcc->stats->tx_err);
37328 dev_kfree_skb_any(skb);
37329 return -EINVAL;
37330 }
37331
37332 if (skb_shinfo(skb)->nr_frags != 0) {
37333 printk("nicstar%d: No scatter-gather yet.\n", card->index);
37334- atomic_inc(&vcc->stats->tx_err);
37335+ atomic_inc_unchecked(&vcc->stats->tx_err);
37336 dev_kfree_skb_any(skb);
37337 return -EINVAL;
37338 }
37339@@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37340 }
37341
37342 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
37343- atomic_inc(&vcc->stats->tx_err);
37344+ atomic_inc_unchecked(&vcc->stats->tx_err);
37345 dev_kfree_skb_any(skb);
37346 return -EIO;
37347 }
37348- atomic_inc(&vcc->stats->tx);
37349+ atomic_inc_unchecked(&vcc->stats->tx);
37350
37351 return 0;
37352 }
37353@@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37354 printk
37355 ("nicstar%d: Can't allocate buffers for aal0.\n",
37356 card->index);
37357- atomic_add(i, &vcc->stats->rx_drop);
37358+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
37359 break;
37360 }
37361 if (!atm_charge(vcc, sb->truesize)) {
37362 RXPRINTK
37363 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
37364 card->index);
37365- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37366+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37367 dev_kfree_skb_any(sb);
37368 break;
37369 }
37370@@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37371 ATM_SKB(sb)->vcc = vcc;
37372 __net_timestamp(sb);
37373 vcc->push(vcc, sb);
37374- atomic_inc(&vcc->stats->rx);
37375+ atomic_inc_unchecked(&vcc->stats->rx);
37376 cell += ATM_CELL_PAYLOAD;
37377 }
37378
37379@@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37380 if (iovb == NULL) {
37381 printk("nicstar%d: Out of iovec buffers.\n",
37382 card->index);
37383- atomic_inc(&vcc->stats->rx_drop);
37384+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37385 recycle_rx_buf(card, skb);
37386 return;
37387 }
37388@@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37389 small or large buffer itself. */
37390 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
37391 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
37392- atomic_inc(&vcc->stats->rx_err);
37393+ atomic_inc_unchecked(&vcc->stats->rx_err);
37394 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37395 NS_MAX_IOVECS);
37396 NS_PRV_IOVCNT(iovb) = 0;
37397@@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37398 ("nicstar%d: Expected a small buffer, and this is not one.\n",
37399 card->index);
37400 which_list(card, skb);
37401- atomic_inc(&vcc->stats->rx_err);
37402+ atomic_inc_unchecked(&vcc->stats->rx_err);
37403 recycle_rx_buf(card, skb);
37404 vc->rx_iov = NULL;
37405 recycle_iov_buf(card, iovb);
37406@@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37407 ("nicstar%d: Expected a large buffer, and this is not one.\n",
37408 card->index);
37409 which_list(card, skb);
37410- atomic_inc(&vcc->stats->rx_err);
37411+ atomic_inc_unchecked(&vcc->stats->rx_err);
37412 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37413 NS_PRV_IOVCNT(iovb));
37414 vc->rx_iov = NULL;
37415@@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37416 printk(" - PDU size mismatch.\n");
37417 else
37418 printk(".\n");
37419- atomic_inc(&vcc->stats->rx_err);
37420+ atomic_inc_unchecked(&vcc->stats->rx_err);
37421 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37422 NS_PRV_IOVCNT(iovb));
37423 vc->rx_iov = NULL;
37424@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37425 /* skb points to a small buffer */
37426 if (!atm_charge(vcc, skb->truesize)) {
37427 push_rxbufs(card, skb);
37428- atomic_inc(&vcc->stats->rx_drop);
37429+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37430 } else {
37431 skb_put(skb, len);
37432 dequeue_sm_buf(card, skb);
37433@@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37434 ATM_SKB(skb)->vcc = vcc;
37435 __net_timestamp(skb);
37436 vcc->push(vcc, skb);
37437- atomic_inc(&vcc->stats->rx);
37438+ atomic_inc_unchecked(&vcc->stats->rx);
37439 }
37440 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
37441 struct sk_buff *sb;
37442@@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37443 if (len <= NS_SMBUFSIZE) {
37444 if (!atm_charge(vcc, sb->truesize)) {
37445 push_rxbufs(card, sb);
37446- atomic_inc(&vcc->stats->rx_drop);
37447+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37448 } else {
37449 skb_put(sb, len);
37450 dequeue_sm_buf(card, sb);
37451@@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37452 ATM_SKB(sb)->vcc = vcc;
37453 __net_timestamp(sb);
37454 vcc->push(vcc, sb);
37455- atomic_inc(&vcc->stats->rx);
37456+ atomic_inc_unchecked(&vcc->stats->rx);
37457 }
37458
37459 push_rxbufs(card, skb);
37460@@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37461
37462 if (!atm_charge(vcc, skb->truesize)) {
37463 push_rxbufs(card, skb);
37464- atomic_inc(&vcc->stats->rx_drop);
37465+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37466 } else {
37467 dequeue_lg_buf(card, skb);
37468 #ifdef NS_USE_DESTRUCTORS
37469@@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37470 ATM_SKB(skb)->vcc = vcc;
37471 __net_timestamp(skb);
37472 vcc->push(vcc, skb);
37473- atomic_inc(&vcc->stats->rx);
37474+ atomic_inc_unchecked(&vcc->stats->rx);
37475 }
37476
37477 push_rxbufs(card, sb);
37478@@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37479 printk
37480 ("nicstar%d: Out of huge buffers.\n",
37481 card->index);
37482- atomic_inc(&vcc->stats->rx_drop);
37483+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37484 recycle_iovec_rx_bufs(card,
37485 (struct iovec *)
37486 iovb->data,
37487@@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37488 card->hbpool.count++;
37489 } else
37490 dev_kfree_skb_any(hb);
37491- atomic_inc(&vcc->stats->rx_drop);
37492+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37493 } else {
37494 /* Copy the small buffer to the huge buffer */
37495 sb = (struct sk_buff *)iov->iov_base;
37496@@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37497 #endif /* NS_USE_DESTRUCTORS */
37498 __net_timestamp(hb);
37499 vcc->push(vcc, hb);
37500- atomic_inc(&vcc->stats->rx);
37501+ atomic_inc_unchecked(&vcc->stats->rx);
37502 }
37503 }
37504
37505diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37506index 21b0bc6..b5f40ba 100644
37507--- a/drivers/atm/solos-pci.c
37508+++ b/drivers/atm/solos-pci.c
37509@@ -838,7 +838,7 @@ static void solos_bh(unsigned long card_arg)
37510 }
37511 atm_charge(vcc, skb->truesize);
37512 vcc->push(vcc, skb);
37513- atomic_inc(&vcc->stats->rx);
37514+ atomic_inc_unchecked(&vcc->stats->rx);
37515 break;
37516
37517 case PKT_STATUS:
37518@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37519 vcc = SKB_CB(oldskb)->vcc;
37520
37521 if (vcc) {
37522- atomic_inc(&vcc->stats->tx);
37523+ atomic_inc_unchecked(&vcc->stats->tx);
37524 solos_pop(vcc, oldskb);
37525 } else {
37526 dev_kfree_skb_irq(oldskb);
37527diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37528index 0215934..ce9f5b1 100644
37529--- a/drivers/atm/suni.c
37530+++ b/drivers/atm/suni.c
37531@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37532
37533
37534 #define ADD_LIMITED(s,v) \
37535- atomic_add((v),&stats->s); \
37536- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37537+ atomic_add_unchecked((v),&stats->s); \
37538+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37539
37540
37541 static void suni_hz(unsigned long from_timer)
37542diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37543index 5120a96..e2572bd 100644
37544--- a/drivers/atm/uPD98402.c
37545+++ b/drivers/atm/uPD98402.c
37546@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37547 struct sonet_stats tmp;
37548 int error = 0;
37549
37550- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37551+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37552 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37553 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37554 if (zero && !error) {
37555@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37556
37557
37558 #define ADD_LIMITED(s,v) \
37559- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37560- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37561- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37562+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37563+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37564+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37565
37566
37567 static void stat_event(struct atm_dev *dev)
37568@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37569 if (reason & uPD98402_INT_PFM) stat_event(dev);
37570 if (reason & uPD98402_INT_PCO) {
37571 (void) GET(PCOCR); /* clear interrupt cause */
37572- atomic_add(GET(HECCT),
37573+ atomic_add_unchecked(GET(HECCT),
37574 &PRIV(dev)->sonet_stats.uncorr_hcs);
37575 }
37576 if ((reason & uPD98402_INT_RFO) &&
37577@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37578 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37579 uPD98402_INT_LOS),PIMR); /* enable them */
37580 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37581- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37582- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37583- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37584+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37585+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37586+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37587 return 0;
37588 }
37589
37590diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37591index 969c3c2..9b72956 100644
37592--- a/drivers/atm/zatm.c
37593+++ b/drivers/atm/zatm.c
37594@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37595 }
37596 if (!size) {
37597 dev_kfree_skb_irq(skb);
37598- if (vcc) atomic_inc(&vcc->stats->rx_err);
37599+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37600 continue;
37601 }
37602 if (!atm_charge(vcc,skb->truesize)) {
37603@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37604 skb->len = size;
37605 ATM_SKB(skb)->vcc = vcc;
37606 vcc->push(vcc,skb);
37607- atomic_inc(&vcc->stats->rx);
37608+ atomic_inc_unchecked(&vcc->stats->rx);
37609 }
37610 zout(pos & 0xffff,MTA(mbx));
37611 #if 0 /* probably a stupid idea */
37612@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37613 skb_queue_head(&zatm_vcc->backlog,skb);
37614 break;
37615 }
37616- atomic_inc(&vcc->stats->tx);
37617+ atomic_inc_unchecked(&vcc->stats->tx);
37618 wake_up(&zatm_vcc->tx_wait);
37619 }
37620
37621diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37622index 83e910a..b224a73 100644
37623--- a/drivers/base/bus.c
37624+++ b/drivers/base/bus.c
37625@@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37626 return -EINVAL;
37627
37628 mutex_lock(&subsys->p->mutex);
37629- list_add_tail(&sif->node, &subsys->p->interfaces);
37630+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37631 if (sif->add_dev) {
37632 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37633 while ((dev = subsys_dev_iter_next(&iter)))
37634@@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37635 subsys = sif->subsys;
37636
37637 mutex_lock(&subsys->p->mutex);
37638- list_del_init(&sif->node);
37639+ pax_list_del_init((struct list_head *)&sif->node);
37640 if (sif->remove_dev) {
37641 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37642 while ((dev = subsys_dev_iter_next(&iter)))
37643diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37644index 25798db..15f130e 100644
37645--- a/drivers/base/devtmpfs.c
37646+++ b/drivers/base/devtmpfs.c
37647@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37648 if (!thread)
37649 return 0;
37650
37651- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37652+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37653 if (err)
37654 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37655 else
37656@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37657 *err = sys_unshare(CLONE_NEWNS);
37658 if (*err)
37659 goto out;
37660- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37661+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37662 if (*err)
37663 goto out;
37664- sys_chdir("/.."); /* will traverse into overmounted root */
37665- sys_chroot(".");
37666+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37667+ sys_chroot((char __force_user *)".");
37668 complete(&setup_done);
37669 while (1) {
37670 spin_lock(&req_lock);
37671diff --git a/drivers/base/node.c b/drivers/base/node.c
37672index 472168c..4af587e 100644
37673--- a/drivers/base/node.c
37674+++ b/drivers/base/node.c
37675@@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37676 struct node_attr {
37677 struct device_attribute attr;
37678 enum node_states state;
37679-};
37680+} __do_const;
37681
37682 static ssize_t show_node_state(struct device *dev,
37683 struct device_attribute *attr, char *buf)
37684diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37685index fb83d4a..4aa50ec 100644
37686--- a/drivers/base/power/domain.c
37687+++ b/drivers/base/power/domain.c
37688@@ -1725,7 +1725,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37689 {
37690 struct cpuidle_driver *cpuidle_drv;
37691 struct gpd_cpuidle_data *cpuidle_data;
37692- struct cpuidle_state *idle_state;
37693+ cpuidle_state_no_const *idle_state;
37694 int ret = 0;
37695
37696 if (IS_ERR_OR_NULL(genpd) || state < 0)
37697@@ -1793,7 +1793,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37698 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37699 {
37700 struct gpd_cpuidle_data *cpuidle_data;
37701- struct cpuidle_state *idle_state;
37702+ cpuidle_state_no_const *idle_state;
37703 int ret = 0;
37704
37705 if (IS_ERR_OR_NULL(genpd))
37706diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37707index a9d26ed..74b8405 100644
37708--- a/drivers/base/power/sysfs.c
37709+++ b/drivers/base/power/sysfs.c
37710@@ -182,7 +182,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37711 return -EIO;
37712 }
37713 }
37714- return sprintf(buf, p);
37715+ return sprintf(buf, "%s", p);
37716 }
37717
37718 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37719diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37720index c2744b3..08fac19 100644
37721--- a/drivers/base/power/wakeup.c
37722+++ b/drivers/base/power/wakeup.c
37723@@ -32,14 +32,14 @@ static bool pm_abort_suspend __read_mostly;
37724 * They need to be modified together atomically, so it's better to use one
37725 * atomic variable to hold them both.
37726 */
37727-static atomic_t combined_event_count = ATOMIC_INIT(0);
37728+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37729
37730 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37731 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37732
37733 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37734 {
37735- unsigned int comb = atomic_read(&combined_event_count);
37736+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
37737
37738 *cnt = (comb >> IN_PROGRESS_BITS);
37739 *inpr = comb & MAX_IN_PROGRESS;
37740@@ -404,7 +404,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37741 ws->start_prevent_time = ws->last_time;
37742
37743 /* Increment the counter of events in progress. */
37744- cec = atomic_inc_return(&combined_event_count);
37745+ cec = atomic_inc_return_unchecked(&combined_event_count);
37746
37747 trace_wakeup_source_activate(ws->name, cec);
37748 }
37749@@ -530,7 +530,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37750 * Increment the counter of registered wakeup events and decrement the
37751 * couter of wakeup events in progress simultaneously.
37752 */
37753- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37754+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37755 trace_wakeup_source_deactivate(ws->name, cec);
37756
37757 split_counters(&cnt, &inpr);
37758diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37759index 8d98a32..61d3165 100644
37760--- a/drivers/base/syscore.c
37761+++ b/drivers/base/syscore.c
37762@@ -22,7 +22,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37763 void register_syscore_ops(struct syscore_ops *ops)
37764 {
37765 mutex_lock(&syscore_ops_lock);
37766- list_add_tail(&ops->node, &syscore_ops_list);
37767+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37768 mutex_unlock(&syscore_ops_lock);
37769 }
37770 EXPORT_SYMBOL_GPL(register_syscore_ops);
37771@@ -34,7 +34,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37772 void unregister_syscore_ops(struct syscore_ops *ops)
37773 {
37774 mutex_lock(&syscore_ops_lock);
37775- list_del(&ops->node);
37776+ pax_list_del((struct list_head *)&ops->node);
37777 mutex_unlock(&syscore_ops_lock);
37778 }
37779 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37780diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37781index ff20f19..018f1da 100644
37782--- a/drivers/block/cciss.c
37783+++ b/drivers/block/cciss.c
37784@@ -3008,7 +3008,7 @@ static void start_io(ctlr_info_t *h)
37785 while (!list_empty(&h->reqQ)) {
37786 c = list_entry(h->reqQ.next, CommandList_struct, list);
37787 /* can't do anything if fifo is full */
37788- if ((h->access.fifo_full(h))) {
37789+ if ((h->access->fifo_full(h))) {
37790 dev_warn(&h->pdev->dev, "fifo full\n");
37791 break;
37792 }
37793@@ -3018,7 +3018,7 @@ static void start_io(ctlr_info_t *h)
37794 h->Qdepth--;
37795
37796 /* Tell the controller execute command */
37797- h->access.submit_command(h, c);
37798+ h->access->submit_command(h, c);
37799
37800 /* Put job onto the completed Q */
37801 addQ(&h->cmpQ, c);
37802@@ -3444,17 +3444,17 @@ startio:
37803
37804 static inline unsigned long get_next_completion(ctlr_info_t *h)
37805 {
37806- return h->access.command_completed(h);
37807+ return h->access->command_completed(h);
37808 }
37809
37810 static inline int interrupt_pending(ctlr_info_t *h)
37811 {
37812- return h->access.intr_pending(h);
37813+ return h->access->intr_pending(h);
37814 }
37815
37816 static inline long interrupt_not_for_us(ctlr_info_t *h)
37817 {
37818- return ((h->access.intr_pending(h) == 0) ||
37819+ return ((h->access->intr_pending(h) == 0) ||
37820 (h->interrupts_enabled == 0));
37821 }
37822
37823@@ -3487,7 +3487,7 @@ static inline u32 next_command(ctlr_info_t *h)
37824 u32 a;
37825
37826 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37827- return h->access.command_completed(h);
37828+ return h->access->command_completed(h);
37829
37830 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37831 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37832@@ -4044,7 +4044,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37833 trans_support & CFGTBL_Trans_use_short_tags);
37834
37835 /* Change the access methods to the performant access methods */
37836- h->access = SA5_performant_access;
37837+ h->access = &SA5_performant_access;
37838 h->transMethod = CFGTBL_Trans_Performant;
37839
37840 return;
37841@@ -4318,7 +4318,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37842 if (prod_index < 0)
37843 return -ENODEV;
37844 h->product_name = products[prod_index].product_name;
37845- h->access = *(products[prod_index].access);
37846+ h->access = products[prod_index].access;
37847
37848 if (cciss_board_disabled(h)) {
37849 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37850@@ -5050,7 +5050,7 @@ reinit_after_soft_reset:
37851 }
37852
37853 /* make sure the board interrupts are off */
37854- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37855+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37856 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37857 if (rc)
37858 goto clean2;
37859@@ -5100,7 +5100,7 @@ reinit_after_soft_reset:
37860 * fake ones to scoop up any residual completions.
37861 */
37862 spin_lock_irqsave(&h->lock, flags);
37863- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37864+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37865 spin_unlock_irqrestore(&h->lock, flags);
37866 free_irq(h->intr[h->intr_mode], h);
37867 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37868@@ -5120,9 +5120,9 @@ reinit_after_soft_reset:
37869 dev_info(&h->pdev->dev, "Board READY.\n");
37870 dev_info(&h->pdev->dev,
37871 "Waiting for stale completions to drain.\n");
37872- h->access.set_intr_mask(h, CCISS_INTR_ON);
37873+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37874 msleep(10000);
37875- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37876+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37877
37878 rc = controller_reset_failed(h->cfgtable);
37879 if (rc)
37880@@ -5145,7 +5145,7 @@ reinit_after_soft_reset:
37881 cciss_scsi_setup(h);
37882
37883 /* Turn the interrupts on so we can service requests */
37884- h->access.set_intr_mask(h, CCISS_INTR_ON);
37885+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37886
37887 /* Get the firmware version */
37888 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37889@@ -5217,7 +5217,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37890 kfree(flush_buf);
37891 if (return_code != IO_OK)
37892 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37893- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37894+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37895 free_irq(h->intr[h->intr_mode], h);
37896 }
37897
37898diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37899index 7fda30e..2f27946 100644
37900--- a/drivers/block/cciss.h
37901+++ b/drivers/block/cciss.h
37902@@ -101,7 +101,7 @@ struct ctlr_info
37903 /* information about each logical volume */
37904 drive_info_struct *drv[CISS_MAX_LUN];
37905
37906- struct access_method access;
37907+ struct access_method *access;
37908
37909 /* queue and queue Info */
37910 struct list_head reqQ;
37911@@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
37912 }
37913
37914 static struct access_method SA5_access = {
37915- SA5_submit_command,
37916- SA5_intr_mask,
37917- SA5_fifo_full,
37918- SA5_intr_pending,
37919- SA5_completed,
37920+ .submit_command = SA5_submit_command,
37921+ .set_intr_mask = SA5_intr_mask,
37922+ .fifo_full = SA5_fifo_full,
37923+ .intr_pending = SA5_intr_pending,
37924+ .command_completed = SA5_completed,
37925 };
37926
37927 static struct access_method SA5B_access = {
37928- SA5_submit_command,
37929- SA5B_intr_mask,
37930- SA5_fifo_full,
37931- SA5B_intr_pending,
37932- SA5_completed,
37933+ .submit_command = SA5_submit_command,
37934+ .set_intr_mask = SA5B_intr_mask,
37935+ .fifo_full = SA5_fifo_full,
37936+ .intr_pending = SA5B_intr_pending,
37937+ .command_completed = SA5_completed,
37938 };
37939
37940 static struct access_method SA5_performant_access = {
37941- SA5_submit_command,
37942- SA5_performant_intr_mask,
37943- SA5_fifo_full,
37944- SA5_performant_intr_pending,
37945- SA5_performant_completed,
37946+ .submit_command = SA5_submit_command,
37947+ .set_intr_mask = SA5_performant_intr_mask,
37948+ .fifo_full = SA5_fifo_full,
37949+ .intr_pending = SA5_performant_intr_pending,
37950+ .command_completed = SA5_performant_completed,
37951 };
37952
37953 struct board_type {
37954diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
37955index 2b94403..fd6ad1f 100644
37956--- a/drivers/block/cpqarray.c
37957+++ b/drivers/block/cpqarray.c
37958@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37959 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
37960 goto Enomem4;
37961 }
37962- hba[i]->access.set_intr_mask(hba[i], 0);
37963+ hba[i]->access->set_intr_mask(hba[i], 0);
37964 if (request_irq(hba[i]->intr, do_ida_intr,
37965 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
37966 {
37967@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37968 add_timer(&hba[i]->timer);
37969
37970 /* Enable IRQ now that spinlock and rate limit timer are set up */
37971- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37972+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37973
37974 for(j=0; j<NWD; j++) {
37975 struct gendisk *disk = ida_gendisk[i][j];
37976@@ -694,7 +694,7 @@ DBGINFO(
37977 for(i=0; i<NR_PRODUCTS; i++) {
37978 if (board_id == products[i].board_id) {
37979 c->product_name = products[i].product_name;
37980- c->access = *(products[i].access);
37981+ c->access = products[i].access;
37982 break;
37983 }
37984 }
37985@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
37986 hba[ctlr]->intr = intr;
37987 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
37988 hba[ctlr]->product_name = products[j].product_name;
37989- hba[ctlr]->access = *(products[j].access);
37990+ hba[ctlr]->access = products[j].access;
37991 hba[ctlr]->ctlr = ctlr;
37992 hba[ctlr]->board_id = board_id;
37993 hba[ctlr]->pci_dev = NULL; /* not PCI */
37994@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
37995
37996 while((c = h->reqQ) != NULL) {
37997 /* Can't do anything if we're busy */
37998- if (h->access.fifo_full(h) == 0)
37999+ if (h->access->fifo_full(h) == 0)
38000 return;
38001
38002 /* Get the first entry from the request Q */
38003@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
38004 h->Qdepth--;
38005
38006 /* Tell the controller to do our bidding */
38007- h->access.submit_command(h, c);
38008+ h->access->submit_command(h, c);
38009
38010 /* Get onto the completion Q */
38011 addQ(&h->cmpQ, c);
38012@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
38013 unsigned long flags;
38014 __u32 a,a1;
38015
38016- istat = h->access.intr_pending(h);
38017+ istat = h->access->intr_pending(h);
38018 /* Is this interrupt for us? */
38019 if (istat == 0)
38020 return IRQ_NONE;
38021@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
38022 */
38023 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
38024 if (istat & FIFO_NOT_EMPTY) {
38025- while((a = h->access.command_completed(h))) {
38026+ while((a = h->access->command_completed(h))) {
38027 a1 = a; a &= ~3;
38028 if ((c = h->cmpQ) == NULL)
38029 {
38030@@ -1448,11 +1448,11 @@ static int sendcmd(
38031 /*
38032 * Disable interrupt
38033 */
38034- info_p->access.set_intr_mask(info_p, 0);
38035+ info_p->access->set_intr_mask(info_p, 0);
38036 /* Make sure there is room in the command FIFO */
38037 /* Actually it should be completely empty at this time. */
38038 for (i = 200000; i > 0; i--) {
38039- temp = info_p->access.fifo_full(info_p);
38040+ temp = info_p->access->fifo_full(info_p);
38041 if (temp != 0) {
38042 break;
38043 }
38044@@ -1465,7 +1465,7 @@ DBG(
38045 /*
38046 * Send the cmd
38047 */
38048- info_p->access.submit_command(info_p, c);
38049+ info_p->access->submit_command(info_p, c);
38050 complete = pollcomplete(ctlr);
38051
38052 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
38053@@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
38054 * we check the new geometry. Then turn interrupts back on when
38055 * we're done.
38056 */
38057- host->access.set_intr_mask(host, 0);
38058+ host->access->set_intr_mask(host, 0);
38059 getgeometry(ctlr);
38060- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
38061+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
38062
38063 for(i=0; i<NWD; i++) {
38064 struct gendisk *disk = ida_gendisk[ctlr][i];
38065@@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
38066 /* Wait (up to 2 seconds) for a command to complete */
38067
38068 for (i = 200000; i > 0; i--) {
38069- done = hba[ctlr]->access.command_completed(hba[ctlr]);
38070+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
38071 if (done == 0) {
38072 udelay(10); /* a short fixed delay */
38073 } else
38074diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
38075index be73e9d..7fbf140 100644
38076--- a/drivers/block/cpqarray.h
38077+++ b/drivers/block/cpqarray.h
38078@@ -99,7 +99,7 @@ struct ctlr_info {
38079 drv_info_t drv[NWD];
38080 struct proc_dir_entry *proc;
38081
38082- struct access_method access;
38083+ struct access_method *access;
38084
38085 cmdlist_t *reqQ;
38086 cmdlist_t *cmpQ;
38087diff --git a/drivers/block/drbd/drbd_bitmap.c b/drivers/block/drbd/drbd_bitmap.c
38088index 434c77d..6d3219a 100644
38089--- a/drivers/block/drbd/drbd_bitmap.c
38090+++ b/drivers/block/drbd/drbd_bitmap.c
38091@@ -1036,7 +1036,7 @@ static void bm_page_io_async(struct drbd_bm_aio_ctx *ctx, int page_nr) __must_ho
38092 submit_bio(rw, bio);
38093 /* this should not count as user activity and cause the
38094 * resync to throttle -- see drbd_rs_should_slow_down(). */
38095- atomic_add(len >> 9, &device->rs_sect_ev);
38096+ atomic_add_unchecked(len >> 9, &device->rs_sect_ev);
38097 }
38098 }
38099
38100diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
38101index 9b22f8f..f2932af 100644
38102--- a/drivers/block/drbd/drbd_int.h
38103+++ b/drivers/block/drbd/drbd_int.h
38104@@ -385,7 +385,7 @@ struct drbd_epoch {
38105 struct drbd_connection *connection;
38106 struct list_head list;
38107 unsigned int barrier_nr;
38108- atomic_t epoch_size; /* increased on every request added. */
38109+ atomic_unchecked_t epoch_size; /* increased on every request added. */
38110 atomic_t active; /* increased on every req. added, and dec on every finished. */
38111 unsigned long flags;
38112 };
38113@@ -946,7 +946,7 @@ struct drbd_device {
38114 unsigned int al_tr_number;
38115 int al_tr_cycle;
38116 wait_queue_head_t seq_wait;
38117- atomic_t packet_seq;
38118+ atomic_unchecked_t packet_seq;
38119 unsigned int peer_seq;
38120 spinlock_t peer_seq_lock;
38121 unsigned long comm_bm_set; /* communicated number of set bits. */
38122@@ -955,8 +955,8 @@ struct drbd_device {
38123 struct mutex own_state_mutex;
38124 struct mutex *state_mutex; /* either own_state_mutex or first_peer_device(device)->connection->cstate_mutex */
38125 char congestion_reason; /* Why we where congested... */
38126- atomic_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
38127- atomic_t rs_sect_ev; /* for submitted resync data rate, both */
38128+ atomic_unchecked_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
38129+ atomic_unchecked_t rs_sect_ev; /* for submitted resync data rate, both */
38130 int rs_last_sect_ev; /* counter to compare with */
38131 int rs_last_events; /* counter of read or write "events" (unit sectors)
38132 * on the lower level device when we last looked. */
38133@@ -1567,7 +1567,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
38134 char __user *uoptval;
38135 int err;
38136
38137- uoptval = (char __user __force *)optval;
38138+ uoptval = (char __force_user *)optval;
38139
38140 set_fs(KERNEL_DS);
38141 if (level == SOL_SOCKET)
38142diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
38143index 973c185..05d8b1a 100644
38144--- a/drivers/block/drbd/drbd_main.c
38145+++ b/drivers/block/drbd/drbd_main.c
38146@@ -1328,7 +1328,7 @@ static int _drbd_send_ack(struct drbd_peer_device *peer_device, enum drbd_packet
38147 p->sector = sector;
38148 p->block_id = block_id;
38149 p->blksize = blksize;
38150- p->seq_num = cpu_to_be32(atomic_inc_return(&peer_device->device->packet_seq));
38151+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&peer_device->device->packet_seq));
38152 return drbd_send_command(peer_device, sock, cmd, sizeof(*p), NULL, 0);
38153 }
38154
38155@@ -1634,7 +1634,7 @@ int drbd_send_dblock(struct drbd_peer_device *peer_device, struct drbd_request *
38156 return -EIO;
38157 p->sector = cpu_to_be64(req->i.sector);
38158 p->block_id = (unsigned long)req;
38159- p->seq_num = cpu_to_be32(atomic_inc_return(&device->packet_seq));
38160+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&device->packet_seq));
38161 dp_flags = bio_flags_to_wire(peer_device->connection, req->master_bio->bi_rw);
38162 if (device->state.conn >= C_SYNC_SOURCE &&
38163 device->state.conn <= C_PAUSED_SYNC_T)
38164@@ -1915,8 +1915,8 @@ void drbd_init_set_defaults(struct drbd_device *device)
38165 atomic_set(&device->unacked_cnt, 0);
38166 atomic_set(&device->local_cnt, 0);
38167 atomic_set(&device->pp_in_use_by_net, 0);
38168- atomic_set(&device->rs_sect_in, 0);
38169- atomic_set(&device->rs_sect_ev, 0);
38170+ atomic_set_unchecked(&device->rs_sect_in, 0);
38171+ atomic_set_unchecked(&device->rs_sect_ev, 0);
38172 atomic_set(&device->ap_in_flight, 0);
38173 atomic_set(&device->md_io.in_use, 0);
38174
38175@@ -2688,8 +2688,8 @@ void drbd_destroy_connection(struct kref *kref)
38176 struct drbd_connection *connection = container_of(kref, struct drbd_connection, kref);
38177 struct drbd_resource *resource = connection->resource;
38178
38179- if (atomic_read(&connection->current_epoch->epoch_size) != 0)
38180- drbd_err(connection, "epoch_size:%d\n", atomic_read(&connection->current_epoch->epoch_size));
38181+ if (atomic_read_unchecked(&connection->current_epoch->epoch_size) != 0)
38182+ drbd_err(connection, "epoch_size:%d\n", atomic_read_unchecked(&connection->current_epoch->epoch_size));
38183 kfree(connection->current_epoch);
38184
38185 idr_destroy(&connection->peer_devices);
38186diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
38187index 1cd47df..57c53c0 100644
38188--- a/drivers/block/drbd/drbd_nl.c
38189+++ b/drivers/block/drbd/drbd_nl.c
38190@@ -3645,13 +3645,13 @@ finish:
38191
38192 void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
38193 {
38194- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38195+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38196 struct sk_buff *msg;
38197 struct drbd_genlmsghdr *d_out;
38198 unsigned seq;
38199 int err = -ENOMEM;
38200
38201- seq = atomic_inc_return(&drbd_genl_seq);
38202+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
38203 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
38204 if (!msg)
38205 goto failed;
38206diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
38207index 6960fb0..215d76b 100644
38208--- a/drivers/block/drbd/drbd_receiver.c
38209+++ b/drivers/block/drbd/drbd_receiver.c
38210@@ -870,7 +870,7 @@ int drbd_connected(struct drbd_peer_device *peer_device)
38211 struct drbd_device *device = peer_device->device;
38212 int err;
38213
38214- atomic_set(&device->packet_seq, 0);
38215+ atomic_set_unchecked(&device->packet_seq, 0);
38216 device->peer_seq = 0;
38217
38218 device->state_mutex = peer_device->connection->agreed_pro_version < 100 ?
38219@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
38220 do {
38221 next_epoch = NULL;
38222
38223- epoch_size = atomic_read(&epoch->epoch_size);
38224+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
38225
38226 switch (ev & ~EV_CLEANUP) {
38227 case EV_PUT:
38228@@ -1273,7 +1273,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
38229 rv = FE_DESTROYED;
38230 } else {
38231 epoch->flags = 0;
38232- atomic_set(&epoch->epoch_size, 0);
38233+ atomic_set_unchecked(&epoch->epoch_size, 0);
38234 /* atomic_set(&epoch->active, 0); is already zero */
38235 if (rv == FE_STILL_LIVE)
38236 rv = FE_RECYCLED;
38237@@ -1550,7 +1550,7 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
38238 conn_wait_active_ee_empty(connection);
38239 drbd_flush(connection);
38240
38241- if (atomic_read(&connection->current_epoch->epoch_size)) {
38242+ if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
38243 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
38244 if (epoch)
38245 break;
38246@@ -1564,11 +1564,11 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
38247 }
38248
38249 epoch->flags = 0;
38250- atomic_set(&epoch->epoch_size, 0);
38251+ atomic_set_unchecked(&epoch->epoch_size, 0);
38252 atomic_set(&epoch->active, 0);
38253
38254 spin_lock(&connection->epoch_lock);
38255- if (atomic_read(&connection->current_epoch->epoch_size)) {
38256+ if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
38257 list_add(&epoch->list, &connection->current_epoch->list);
38258 connection->current_epoch = epoch;
38259 connection->epochs++;
38260@@ -1802,7 +1802,7 @@ static int recv_resync_read(struct drbd_peer_device *peer_device, sector_t secto
38261 list_add_tail(&peer_req->w.list, &device->sync_ee);
38262 spin_unlock_irq(&device->resource->req_lock);
38263
38264- atomic_add(pi->size >> 9, &device->rs_sect_ev);
38265+ atomic_add_unchecked(pi->size >> 9, &device->rs_sect_ev);
38266 if (drbd_submit_peer_request(device, peer_req, WRITE, DRBD_FAULT_RS_WR) == 0)
38267 return 0;
38268
38269@@ -1900,7 +1900,7 @@ static int receive_RSDataReply(struct drbd_connection *connection, struct packet
38270 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
38271 }
38272
38273- atomic_add(pi->size >> 9, &device->rs_sect_in);
38274+ atomic_add_unchecked(pi->size >> 9, &device->rs_sect_in);
38275
38276 return err;
38277 }
38278@@ -2290,7 +2290,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
38279
38280 err = wait_for_and_update_peer_seq(peer_device, peer_seq);
38281 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
38282- atomic_inc(&connection->current_epoch->epoch_size);
38283+ atomic_inc_unchecked(&connection->current_epoch->epoch_size);
38284 err2 = drbd_drain_block(peer_device, pi->size);
38285 if (!err)
38286 err = err2;
38287@@ -2334,7 +2334,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
38288
38289 spin_lock(&connection->epoch_lock);
38290 peer_req->epoch = connection->current_epoch;
38291- atomic_inc(&peer_req->epoch->epoch_size);
38292+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
38293 atomic_inc(&peer_req->epoch->active);
38294 spin_unlock(&connection->epoch_lock);
38295
38296@@ -2479,7 +2479,7 @@ bool drbd_rs_c_min_rate_throttle(struct drbd_device *device)
38297
38298 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
38299 (int)part_stat_read(&disk->part0, sectors[1]) -
38300- atomic_read(&device->rs_sect_ev);
38301+ atomic_read_unchecked(&device->rs_sect_ev);
38302
38303 if (atomic_read(&device->ap_actlog_cnt)
38304 || !device->rs_last_events || curr_events - device->rs_last_events > 64) {
38305@@ -2618,7 +2618,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
38306 device->use_csums = true;
38307 } else if (pi->cmd == P_OV_REPLY) {
38308 /* track progress, we may need to throttle */
38309- atomic_add(size >> 9, &device->rs_sect_in);
38310+ atomic_add_unchecked(size >> 9, &device->rs_sect_in);
38311 peer_req->w.cb = w_e_end_ov_reply;
38312 dec_rs_pending(device);
38313 /* drbd_rs_begin_io done when we sent this request,
38314@@ -2691,7 +2691,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
38315 goto out_free_e;
38316
38317 submit_for_resync:
38318- atomic_add(size >> 9, &device->rs_sect_ev);
38319+ atomic_add_unchecked(size >> 9, &device->rs_sect_ev);
38320
38321 submit:
38322 update_receiver_timing_details(connection, drbd_submit_peer_request);
38323@@ -4564,7 +4564,7 @@ struct data_cmd {
38324 int expect_payload;
38325 size_t pkt_size;
38326 int (*fn)(struct drbd_connection *, struct packet_info *);
38327-};
38328+} __do_const;
38329
38330 static struct data_cmd drbd_cmd_handler[] = {
38331 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
38332@@ -4678,7 +4678,7 @@ static void conn_disconnect(struct drbd_connection *connection)
38333 if (!list_empty(&connection->current_epoch->list))
38334 drbd_err(connection, "ASSERTION FAILED: connection->current_epoch->list not empty\n");
38335 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
38336- atomic_set(&connection->current_epoch->epoch_size, 0);
38337+ atomic_set_unchecked(&connection->current_epoch->epoch_size, 0);
38338 connection->send.seen_any_write_yet = false;
38339
38340 drbd_info(connection, "Connection closed\n");
38341@@ -5182,7 +5182,7 @@ static int got_IsInSync(struct drbd_connection *connection, struct packet_info *
38342 put_ldev(device);
38343 }
38344 dec_rs_pending(device);
38345- atomic_add(blksize >> 9, &device->rs_sect_in);
38346+ atomic_add_unchecked(blksize >> 9, &device->rs_sect_in);
38347
38348 return 0;
38349 }
38350@@ -5470,7 +5470,7 @@ static int connection_finish_peer_reqs(struct drbd_connection *connection)
38351 struct asender_cmd {
38352 size_t pkt_size;
38353 int (*fn)(struct drbd_connection *connection, struct packet_info *);
38354-};
38355+} __do_const;
38356
38357 static struct asender_cmd asender_tbl[] = {
38358 [P_PING] = { 0, got_Ping },
38359diff --git a/drivers/block/drbd/drbd_worker.c b/drivers/block/drbd/drbd_worker.c
38360index d2d1f97..6a1188f 100644
38361--- a/drivers/block/drbd/drbd_worker.c
38362+++ b/drivers/block/drbd/drbd_worker.c
38363@@ -408,7 +408,7 @@ static int read_for_csum(struct drbd_peer_device *peer_device, sector_t sector,
38364 list_add_tail(&peer_req->w.list, &device->read_ee);
38365 spin_unlock_irq(&device->resource->req_lock);
38366
38367- atomic_add(size >> 9, &device->rs_sect_ev);
38368+ atomic_add_unchecked(size >> 9, &device->rs_sect_ev);
38369 if (drbd_submit_peer_request(device, peer_req, READ, DRBD_FAULT_RS_RD) == 0)
38370 return 0;
38371
38372@@ -553,7 +553,7 @@ static int drbd_rs_number_requests(struct drbd_device *device)
38373 unsigned int sect_in; /* Number of sectors that came in since the last turn */
38374 int number, mxb;
38375
38376- sect_in = atomic_xchg(&device->rs_sect_in, 0);
38377+ sect_in = atomic_xchg_unchecked(&device->rs_sect_in, 0);
38378 device->rs_in_flight -= sect_in;
38379
38380 rcu_read_lock();
38381@@ -1594,8 +1594,8 @@ void drbd_rs_controller_reset(struct drbd_device *device)
38382 {
38383 struct fifo_buffer *plan;
38384
38385- atomic_set(&device->rs_sect_in, 0);
38386- atomic_set(&device->rs_sect_ev, 0);
38387+ atomic_set_unchecked(&device->rs_sect_in, 0);
38388+ atomic_set_unchecked(&device->rs_sect_ev, 0);
38389 device->rs_in_flight = 0;
38390
38391 /* Updating the RCU protected object in place is necessary since
38392diff --git a/drivers/block/loop.c b/drivers/block/loop.c
38393index 6cb1beb..bf490f7 100644
38394--- a/drivers/block/loop.c
38395+++ b/drivers/block/loop.c
38396@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
38397
38398 file_start_write(file);
38399 set_fs(get_ds());
38400- bw = file->f_op->write(file, buf, len, &pos);
38401+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
38402 set_fs(old_fs);
38403 file_end_write(file);
38404 if (likely(bw == len))
38405diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
38406index e2bb8af..44b8aef 100644
38407--- a/drivers/block/nvme-core.c
38408+++ b/drivers/block/nvme-core.c
38409@@ -73,7 +73,6 @@ static LIST_HEAD(dev_list);
38410 static struct task_struct *nvme_thread;
38411 static struct workqueue_struct *nvme_workq;
38412 static wait_queue_head_t nvme_kthread_wait;
38413-static struct notifier_block nvme_nb;
38414
38415 static void nvme_reset_failed_dev(struct work_struct *ws);
38416
38417@@ -2926,6 +2925,10 @@ static struct pci_driver nvme_driver = {
38418 .err_handler = &nvme_err_handler,
38419 };
38420
38421+static struct notifier_block nvme_nb = {
38422+ .notifier_call = &nvme_cpu_notify,
38423+};
38424+
38425 static int __init nvme_init(void)
38426 {
38427 int result;
38428@@ -2942,7 +2945,6 @@ static int __init nvme_init(void)
38429 else if (result > 0)
38430 nvme_major = result;
38431
38432- nvme_nb.notifier_call = &nvme_cpu_notify;
38433 result = register_hotcpu_notifier(&nvme_nb);
38434 if (result)
38435 goto unregister_blkdev;
38436diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
38437index 09e628da..7607aaa 100644
38438--- a/drivers/block/pktcdvd.c
38439+++ b/drivers/block/pktcdvd.c
38440@@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
38441
38442 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
38443 {
38444- return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
38445+ return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
38446 }
38447
38448 /*
38449@@ -1890,7 +1890,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
38450 return -EROFS;
38451 }
38452 pd->settings.fp = ti.fp;
38453- pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
38454+ pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
38455
38456 if (ti.nwa_v) {
38457 pd->nwa = be32_to_cpu(ti.next_writable);
38458diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
38459index e5565fb..71be10b4 100644
38460--- a/drivers/block/smart1,2.h
38461+++ b/drivers/block/smart1,2.h
38462@@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
38463 }
38464
38465 static struct access_method smart4_access = {
38466- smart4_submit_command,
38467- smart4_intr_mask,
38468- smart4_fifo_full,
38469- smart4_intr_pending,
38470- smart4_completed,
38471+ .submit_command = smart4_submit_command,
38472+ .set_intr_mask = smart4_intr_mask,
38473+ .fifo_full = smart4_fifo_full,
38474+ .intr_pending = smart4_intr_pending,
38475+ .command_completed = smart4_completed,
38476 };
38477
38478 /*
38479@@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
38480 }
38481
38482 static struct access_method smart2_access = {
38483- smart2_submit_command,
38484- smart2_intr_mask,
38485- smart2_fifo_full,
38486- smart2_intr_pending,
38487- smart2_completed,
38488+ .submit_command = smart2_submit_command,
38489+ .set_intr_mask = smart2_intr_mask,
38490+ .fifo_full = smart2_fifo_full,
38491+ .intr_pending = smart2_intr_pending,
38492+ .command_completed = smart2_completed,
38493 };
38494
38495 /*
38496@@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
38497 }
38498
38499 static struct access_method smart2e_access = {
38500- smart2e_submit_command,
38501- smart2e_intr_mask,
38502- smart2e_fifo_full,
38503- smart2e_intr_pending,
38504- smart2e_completed,
38505+ .submit_command = smart2e_submit_command,
38506+ .set_intr_mask = smart2e_intr_mask,
38507+ .fifo_full = smart2e_fifo_full,
38508+ .intr_pending = smart2e_intr_pending,
38509+ .command_completed = smart2e_completed,
38510 };
38511
38512 /*
38513@@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
38514 }
38515
38516 static struct access_method smart1_access = {
38517- smart1_submit_command,
38518- smart1_intr_mask,
38519- smart1_fifo_full,
38520- smart1_intr_pending,
38521- smart1_completed,
38522+ .submit_command = smart1_submit_command,
38523+ .set_intr_mask = smart1_intr_mask,
38524+ .fifo_full = smart1_fifo_full,
38525+ .intr_pending = smart1_intr_pending,
38526+ .command_completed = smart1_completed,
38527 };
38528diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38529index f038dba..bb74c08 100644
38530--- a/drivers/bluetooth/btwilink.c
38531+++ b/drivers/bluetooth/btwilink.c
38532@@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38533
38534 static int bt_ti_probe(struct platform_device *pdev)
38535 {
38536- static struct ti_st *hst;
38537+ struct ti_st *hst;
38538 struct hci_dev *hdev;
38539 int err;
38540
38541diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38542index 5d28a45..a538f90 100644
38543--- a/drivers/cdrom/cdrom.c
38544+++ b/drivers/cdrom/cdrom.c
38545@@ -610,7 +610,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38546 ENSURE(reset, CDC_RESET);
38547 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38548 cdi->mc_flags = 0;
38549- cdo->n_minors = 0;
38550 cdi->options = CDO_USE_FFLAGS;
38551
38552 if (autoclose == 1 && CDROM_CAN(CDC_CLOSE_TRAY))
38553@@ -630,8 +629,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38554 else
38555 cdi->cdda_method = CDDA_OLD;
38556
38557- if (!cdo->generic_packet)
38558- cdo->generic_packet = cdrom_dummy_generic_packet;
38559+ if (!cdo->generic_packet) {
38560+ pax_open_kernel();
38561+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38562+ pax_close_kernel();
38563+ }
38564
38565 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38566 mutex_lock(&cdrom_mutex);
38567@@ -652,7 +654,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38568 if (cdi->exit)
38569 cdi->exit(cdi);
38570
38571- cdi->ops->n_minors--;
38572 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38573 }
38574
38575@@ -2126,7 +2127,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38576 */
38577 nr = nframes;
38578 do {
38579- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38580+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38581 if (cgc.buffer)
38582 break;
38583
38584@@ -3434,7 +3435,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38585 struct cdrom_device_info *cdi;
38586 int ret;
38587
38588- ret = scnprintf(info + *pos, max_size - *pos, header);
38589+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38590 if (!ret)
38591 return 1;
38592
38593diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38594index 584bc31..e64a12c 100644
38595--- a/drivers/cdrom/gdrom.c
38596+++ b/drivers/cdrom/gdrom.c
38597@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38598 .audio_ioctl = gdrom_audio_ioctl,
38599 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38600 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38601- .n_minors = 1,
38602 };
38603
38604 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38605diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38606index efefd12..4f1d494 100644
38607--- a/drivers/char/Kconfig
38608+++ b/drivers/char/Kconfig
38609@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38610
38611 config DEVKMEM
38612 bool "/dev/kmem virtual device support"
38613- default y
38614+ default n
38615+ depends on !GRKERNSEC_KMEM
38616 help
38617 Say Y here if you want to support the /dev/kmem device. The
38618 /dev/kmem device is rarely used, but can be used for certain
38619@@ -577,6 +578,7 @@ config DEVPORT
38620 bool
38621 depends on !M68K
38622 depends on ISA || PCI
38623+ depends on !GRKERNSEC_KMEM
38624 default y
38625
38626 source "drivers/s390/char/Kconfig"
38627diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38628index a48e05b..6bac831 100644
38629--- a/drivers/char/agp/compat_ioctl.c
38630+++ b/drivers/char/agp/compat_ioctl.c
38631@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38632 return -ENOMEM;
38633 }
38634
38635- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38636+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38637 sizeof(*usegment) * ureserve.seg_count)) {
38638 kfree(usegment);
38639 kfree(ksegment);
38640diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38641index 09f17eb..8531d2f 100644
38642--- a/drivers/char/agp/frontend.c
38643+++ b/drivers/char/agp/frontend.c
38644@@ -806,7 +806,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38645 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38646 return -EFAULT;
38647
38648- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38649+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38650 return -EFAULT;
38651
38652 client = agp_find_client_by_pid(reserve.pid);
38653@@ -836,7 +836,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38654 if (segment == NULL)
38655 return -ENOMEM;
38656
38657- if (copy_from_user(segment, (void __user *) reserve.seg_list,
38658+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38659 sizeof(struct agp_segment) * reserve.seg_count)) {
38660 kfree(segment);
38661 return -EFAULT;
38662diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38663index 4f94375..413694e 100644
38664--- a/drivers/char/genrtc.c
38665+++ b/drivers/char/genrtc.c
38666@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38667 switch (cmd) {
38668
38669 case RTC_PLL_GET:
38670+ memset(&pll, 0, sizeof(pll));
38671 if (get_rtc_pll(&pll))
38672 return -EINVAL;
38673 else
38674diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38675index d5d4cd8..22d561d 100644
38676--- a/drivers/char/hpet.c
38677+++ b/drivers/char/hpet.c
38678@@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38679 }
38680
38681 static int
38682-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38683+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38684 struct hpet_info *info)
38685 {
38686 struct hpet_timer __iomem *timer;
38687diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38688index f816211..89eadea 100644
38689--- a/drivers/char/ipmi/ipmi_msghandler.c
38690+++ b/drivers/char/ipmi/ipmi_msghandler.c
38691@@ -438,7 +438,7 @@ struct ipmi_smi {
38692 struct proc_dir_entry *proc_dir;
38693 char proc_dir_name[10];
38694
38695- atomic_t stats[IPMI_NUM_STATS];
38696+ atomic_unchecked_t stats[IPMI_NUM_STATS];
38697
38698 /*
38699 * run_to_completion duplicate of smb_info, smi_info
38700@@ -470,9 +470,9 @@ static LIST_HEAD(smi_watchers);
38701 static DEFINE_MUTEX(smi_watchers_mutex);
38702
38703 #define ipmi_inc_stat(intf, stat) \
38704- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38705+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38706 #define ipmi_get_stat(intf, stat) \
38707- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38708+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38709
38710 static int is_lan_addr(struct ipmi_addr *addr)
38711 {
38712@@ -2925,7 +2925,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38713 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38714 init_waitqueue_head(&intf->waitq);
38715 for (i = 0; i < IPMI_NUM_STATS; i++)
38716- atomic_set(&intf->stats[i], 0);
38717+ atomic_set_unchecked(&intf->stats[i], 0);
38718
38719 intf->proc_dir = NULL;
38720
38721diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38722index 5c4e1f6..0ea58f9 100644
38723--- a/drivers/char/ipmi/ipmi_si_intf.c
38724+++ b/drivers/char/ipmi/ipmi_si_intf.c
38725@@ -285,7 +285,7 @@ struct smi_info {
38726 unsigned char slave_addr;
38727
38728 /* Counters and things for the proc filesystem. */
38729- atomic_t stats[SI_NUM_STATS];
38730+ atomic_unchecked_t stats[SI_NUM_STATS];
38731
38732 struct task_struct *thread;
38733
38734@@ -294,9 +294,9 @@ struct smi_info {
38735 };
38736
38737 #define smi_inc_stat(smi, stat) \
38738- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38739+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38740 #define smi_get_stat(smi, stat) \
38741- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38742+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38743
38744 #define SI_MAX_PARMS 4
38745
38746@@ -3377,7 +3377,7 @@ static int try_smi_init(struct smi_info *new_smi)
38747 atomic_set(&new_smi->req_events, 0);
38748 new_smi->run_to_completion = false;
38749 for (i = 0; i < SI_NUM_STATS; i++)
38750- atomic_set(&new_smi->stats[i], 0);
38751+ atomic_set_unchecked(&new_smi->stats[i], 0);
38752
38753 new_smi->interrupt_disabled = true;
38754 atomic_set(&new_smi->stop_operation, 0);
38755diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38756index 524b707..29d07c1 100644
38757--- a/drivers/char/mem.c
38758+++ b/drivers/char/mem.c
38759@@ -18,6 +18,7 @@
38760 #include <linux/raw.h>
38761 #include <linux/tty.h>
38762 #include <linux/capability.h>
38763+#include <linux/security.h>
38764 #include <linux/ptrace.h>
38765 #include <linux/device.h>
38766 #include <linux/highmem.h>
38767@@ -36,6 +37,10 @@
38768
38769 #define DEVPORT_MINOR 4
38770
38771+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38772+extern const struct file_operations grsec_fops;
38773+#endif
38774+
38775 static inline unsigned long size_inside_page(unsigned long start,
38776 unsigned long size)
38777 {
38778@@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38779
38780 while (cursor < to) {
38781 if (!devmem_is_allowed(pfn)) {
38782+#ifdef CONFIG_GRKERNSEC_KMEM
38783+ gr_handle_mem_readwrite(from, to);
38784+#else
38785 printk(KERN_INFO
38786 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38787 current->comm, from, to);
38788+#endif
38789 return 0;
38790 }
38791 cursor += PAGE_SIZE;
38792@@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38793 }
38794 return 1;
38795 }
38796+#elif defined(CONFIG_GRKERNSEC_KMEM)
38797+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38798+{
38799+ return 0;
38800+}
38801 #else
38802 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38803 {
38804@@ -122,6 +136,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38805
38806 while (count > 0) {
38807 unsigned long remaining;
38808+ char *temp;
38809
38810 sz = size_inside_page(p, count);
38811
38812@@ -137,7 +152,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38813 if (!ptr)
38814 return -EFAULT;
38815
38816- remaining = copy_to_user(buf, ptr, sz);
38817+#ifdef CONFIG_PAX_USERCOPY
38818+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38819+ if (!temp) {
38820+ unxlate_dev_mem_ptr(p, ptr);
38821+ return -ENOMEM;
38822+ }
38823+ memcpy(temp, ptr, sz);
38824+#else
38825+ temp = ptr;
38826+#endif
38827+
38828+ remaining = copy_to_user(buf, temp, sz);
38829+
38830+#ifdef CONFIG_PAX_USERCOPY
38831+ kfree(temp);
38832+#endif
38833+
38834 unxlate_dev_mem_ptr(p, ptr);
38835 if (remaining)
38836 return -EFAULT;
38837@@ -369,9 +400,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38838 size_t count, loff_t *ppos)
38839 {
38840 unsigned long p = *ppos;
38841- ssize_t low_count, read, sz;
38842+ ssize_t low_count, read, sz, err = 0;
38843 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38844- int err = 0;
38845
38846 read = 0;
38847 if (p < (unsigned long) high_memory) {
38848@@ -393,6 +423,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38849 }
38850 #endif
38851 while (low_count > 0) {
38852+ char *temp;
38853+
38854 sz = size_inside_page(p, low_count);
38855
38856 /*
38857@@ -402,7 +434,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38858 */
38859 kbuf = xlate_dev_kmem_ptr((char *)p);
38860
38861- if (copy_to_user(buf, kbuf, sz))
38862+#ifdef CONFIG_PAX_USERCOPY
38863+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38864+ if (!temp)
38865+ return -ENOMEM;
38866+ memcpy(temp, kbuf, sz);
38867+#else
38868+ temp = kbuf;
38869+#endif
38870+
38871+ err = copy_to_user(buf, temp, sz);
38872+
38873+#ifdef CONFIG_PAX_USERCOPY
38874+ kfree(temp);
38875+#endif
38876+
38877+ if (err)
38878 return -EFAULT;
38879 buf += sz;
38880 p += sz;
38881@@ -797,6 +844,9 @@ static const struct memdev {
38882 #ifdef CONFIG_PRINTK
38883 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38884 #endif
38885+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38886+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38887+#endif
38888 };
38889
38890 static int memory_open(struct inode *inode, struct file *filp)
38891@@ -868,7 +918,7 @@ static int __init chr_dev_init(void)
38892 continue;
38893
38894 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38895- NULL, devlist[minor].name);
38896+ NULL, "%s", devlist[minor].name);
38897 }
38898
38899 return tty_init();
38900diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38901index 9df78e2..01ba9ae 100644
38902--- a/drivers/char/nvram.c
38903+++ b/drivers/char/nvram.c
38904@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38905
38906 spin_unlock_irq(&rtc_lock);
38907
38908- if (copy_to_user(buf, contents, tmp - contents))
38909+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38910 return -EFAULT;
38911
38912 *ppos = i;
38913diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38914index 0ea9986..e7b07e4 100644
38915--- a/drivers/char/pcmcia/synclink_cs.c
38916+++ b/drivers/char/pcmcia/synclink_cs.c
38917@@ -2345,7 +2345,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38918
38919 if (debug_level >= DEBUG_LEVEL_INFO)
38920 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38921- __FILE__, __LINE__, info->device_name, port->count);
38922+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38923
38924 if (tty_port_close_start(port, tty, filp) == 0)
38925 goto cleanup;
38926@@ -2363,7 +2363,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38927 cleanup:
38928 if (debug_level >= DEBUG_LEVEL_INFO)
38929 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38930- tty->driver->name, port->count);
38931+ tty->driver->name, atomic_read(&port->count));
38932 }
38933
38934 /* Wait until the transmitter is empty.
38935@@ -2505,7 +2505,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38936
38937 if (debug_level >= DEBUG_LEVEL_INFO)
38938 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38939- __FILE__, __LINE__, tty->driver->name, port->count);
38940+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38941
38942 /* If port is closing, signal caller to try again */
38943 if (port->flags & ASYNC_CLOSING){
38944@@ -2525,11 +2525,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38945 goto cleanup;
38946 }
38947 spin_lock(&port->lock);
38948- port->count++;
38949+ atomic_inc(&port->count);
38950 spin_unlock(&port->lock);
38951 spin_unlock_irqrestore(&info->netlock, flags);
38952
38953- if (port->count == 1) {
38954+ if (atomic_read(&port->count) == 1) {
38955 /* 1st open on this device, init hardware */
38956 retval = startup(info, tty);
38957 if (retval < 0)
38958@@ -3918,7 +3918,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38959 unsigned short new_crctype;
38960
38961 /* return error if TTY interface open */
38962- if (info->port.count)
38963+ if (atomic_read(&info->port.count))
38964 return -EBUSY;
38965
38966 switch (encoding)
38967@@ -4022,7 +4022,7 @@ static int hdlcdev_open(struct net_device *dev)
38968
38969 /* arbitrate between network and tty opens */
38970 spin_lock_irqsave(&info->netlock, flags);
38971- if (info->port.count != 0 || info->netcount != 0) {
38972+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38973 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38974 spin_unlock_irqrestore(&info->netlock, flags);
38975 return -EBUSY;
38976@@ -4112,7 +4112,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38977 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
38978
38979 /* return error if TTY interface open */
38980- if (info->port.count)
38981+ if (atomic_read(&info->port.count))
38982 return -EBUSY;
38983
38984 if (cmd != SIOCWANDEV)
38985diff --git a/drivers/char/random.c b/drivers/char/random.c
38986index 04645c0..560e350 100644
38987--- a/drivers/char/random.c
38988+++ b/drivers/char/random.c
38989@@ -289,9 +289,6 @@
38990 /*
38991 * To allow fractional bits to be tracked, the entropy_count field is
38992 * denominated in units of 1/8th bits.
38993- *
38994- * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
38995- * credit_entropy_bits() needs to be 64 bits wide.
38996 */
38997 #define ENTROPY_SHIFT 3
38998 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
38999@@ -439,9 +436,9 @@ struct entropy_store {
39000 };
39001
39002 static void push_to_pool(struct work_struct *work);
39003-static __u32 input_pool_data[INPUT_POOL_WORDS];
39004-static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
39005-static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
39006+static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
39007+static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
39008+static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
39009
39010 static struct entropy_store input_pool = {
39011 .poolinfo = &poolinfo_table[0],
39012@@ -635,7 +632,7 @@ retry:
39013 /* The +2 corresponds to the /4 in the denominator */
39014
39015 do {
39016- unsigned int anfrac = min(pnfrac, pool_size/2);
39017+ u64 anfrac = min(pnfrac, pool_size/2);
39018 unsigned int add =
39019 ((pool_size - entropy_count)*anfrac*3) >> s;
39020
39021@@ -1207,7 +1204,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
39022
39023 extract_buf(r, tmp);
39024 i = min_t(int, nbytes, EXTRACT_SIZE);
39025- if (copy_to_user(buf, tmp, i)) {
39026+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
39027 ret = -EFAULT;
39028 break;
39029 }
39030@@ -1590,7 +1587,7 @@ static char sysctl_bootid[16];
39031 static int proc_do_uuid(struct ctl_table *table, int write,
39032 void __user *buffer, size_t *lenp, loff_t *ppos)
39033 {
39034- struct ctl_table fake_table;
39035+ ctl_table_no_const fake_table;
39036 unsigned char buf[64], tmp_uuid[16], *uuid;
39037
39038 uuid = table->data;
39039@@ -1620,7 +1617,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
39040 static int proc_do_entropy(struct ctl_table *table, int write,
39041 void __user *buffer, size_t *lenp, loff_t *ppos)
39042 {
39043- struct ctl_table fake_table;
39044+ ctl_table_no_const fake_table;
39045 int entropy_count;
39046
39047 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
39048diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
39049index 7cc1fe22..b602d6b 100644
39050--- a/drivers/char/sonypi.c
39051+++ b/drivers/char/sonypi.c
39052@@ -54,6 +54,7 @@
39053
39054 #include <asm/uaccess.h>
39055 #include <asm/io.h>
39056+#include <asm/local.h>
39057
39058 #include <linux/sonypi.h>
39059
39060@@ -490,7 +491,7 @@ static struct sonypi_device {
39061 spinlock_t fifo_lock;
39062 wait_queue_head_t fifo_proc_list;
39063 struct fasync_struct *fifo_async;
39064- int open_count;
39065+ local_t open_count;
39066 int model;
39067 struct input_dev *input_jog_dev;
39068 struct input_dev *input_key_dev;
39069@@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
39070 static int sonypi_misc_release(struct inode *inode, struct file *file)
39071 {
39072 mutex_lock(&sonypi_device.lock);
39073- sonypi_device.open_count--;
39074+ local_dec(&sonypi_device.open_count);
39075 mutex_unlock(&sonypi_device.lock);
39076 return 0;
39077 }
39078@@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
39079 {
39080 mutex_lock(&sonypi_device.lock);
39081 /* Flush input queue on first open */
39082- if (!sonypi_device.open_count)
39083+ if (!local_read(&sonypi_device.open_count))
39084 kfifo_reset(&sonypi_device.fifo);
39085- sonypi_device.open_count++;
39086+ local_inc(&sonypi_device.open_count);
39087 mutex_unlock(&sonypi_device.lock);
39088
39089 return 0;
39090diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
39091index 565a947..dcdc06e 100644
39092--- a/drivers/char/tpm/tpm_acpi.c
39093+++ b/drivers/char/tpm/tpm_acpi.c
39094@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
39095 virt = acpi_os_map_iomem(start, len);
39096 if (!virt) {
39097 kfree(log->bios_event_log);
39098+ log->bios_event_log = NULL;
39099 printk("%s: ERROR - Unable to map memory\n", __func__);
39100 return -EIO;
39101 }
39102
39103- memcpy_fromio(log->bios_event_log, virt, len);
39104+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
39105
39106 acpi_os_unmap_iomem(virt, len);
39107 return 0;
39108diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
39109index 3a56a13..f8cbd25 100644
39110--- a/drivers/char/tpm/tpm_eventlog.c
39111+++ b/drivers/char/tpm/tpm_eventlog.c
39112@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
39113 event = addr;
39114
39115 if ((event->event_type == 0 && event->event_size == 0) ||
39116- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
39117+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
39118 return NULL;
39119
39120 return addr;
39121@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
39122 return NULL;
39123
39124 if ((event->event_type == 0 && event->event_size == 0) ||
39125- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
39126+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
39127 return NULL;
39128
39129 (*pos)++;
39130@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
39131 int i;
39132
39133 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
39134- seq_putc(m, data[i]);
39135+ if (!seq_putc(m, data[i]))
39136+ return -EFAULT;
39137
39138 return 0;
39139 }
39140diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
39141index cf7a561..c319ce0 100644
39142--- a/drivers/char/virtio_console.c
39143+++ b/drivers/char/virtio_console.c
39144@@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
39145 if (to_user) {
39146 ssize_t ret;
39147
39148- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
39149+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
39150 if (ret)
39151 return -EFAULT;
39152 } else {
39153@@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
39154 if (!port_has_data(port) && !port->host_connected)
39155 return 0;
39156
39157- return fill_readbuf(port, ubuf, count, true);
39158+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
39159 }
39160
39161 static int wait_port_writable(struct port *port, bool nonblock)
39162diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
39163index b9355da..9611f4e 100644
39164--- a/drivers/clk/clk-composite.c
39165+++ b/drivers/clk/clk-composite.c
39166@@ -191,7 +191,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
39167 struct clk *clk;
39168 struct clk_init_data init;
39169 struct clk_composite *composite;
39170- struct clk_ops *clk_composite_ops;
39171+ clk_ops_no_const *clk_composite_ops;
39172
39173 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
39174 if (!composite) {
39175diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c
39176index dd3a78c..386d49c 100644
39177--- a/drivers/clk/socfpga/clk-gate.c
39178+++ b/drivers/clk/socfpga/clk-gate.c
39179@@ -22,6 +22,7 @@
39180 #include <linux/mfd/syscon.h>
39181 #include <linux/of.h>
39182 #include <linux/regmap.h>
39183+#include <asm/pgtable.h>
39184
39185 #include "clk.h"
39186
39187@@ -174,7 +175,7 @@ static int socfpga_clk_prepare(struct clk_hw *hwclk)
39188 return 0;
39189 }
39190
39191-static struct clk_ops gateclk_ops = {
39192+static clk_ops_no_const gateclk_ops __read_only = {
39193 .prepare = socfpga_clk_prepare,
39194 .recalc_rate = socfpga_clk_recalc_rate,
39195 .get_parent = socfpga_clk_get_parent,
39196@@ -208,8 +209,10 @@ static void __init __socfpga_gate_init(struct device_node *node,
39197 socfpga_clk->hw.reg = clk_mgr_base_addr + clk_gate[0];
39198 socfpga_clk->hw.bit_idx = clk_gate[1];
39199
39200- gateclk_ops.enable = clk_gate_ops.enable;
39201- gateclk_ops.disable = clk_gate_ops.disable;
39202+ pax_open_kernel();
39203+ *(void **)&gateclk_ops.enable = clk_gate_ops.enable;
39204+ *(void **)&gateclk_ops.disable = clk_gate_ops.disable;
39205+ pax_close_kernel();
39206 }
39207
39208 rc = of_property_read_u32(node, "fixed-divider", &fixed_div);
39209diff --git a/drivers/clk/socfpga/clk-pll.c b/drivers/clk/socfpga/clk-pll.c
39210index de6da95..c98278b 100644
39211--- a/drivers/clk/socfpga/clk-pll.c
39212+++ b/drivers/clk/socfpga/clk-pll.c
39213@@ -21,6 +21,7 @@
39214 #include <linux/io.h>
39215 #include <linux/of.h>
39216 #include <linux/of_address.h>
39217+#include <asm/pgtable.h>
39218
39219 #include "clk.h"
39220
39221@@ -76,7 +77,7 @@ static u8 clk_pll_get_parent(struct clk_hw *hwclk)
39222 CLK_MGR_PLL_CLK_SRC_MASK;
39223 }
39224
39225-static struct clk_ops clk_pll_ops = {
39226+static clk_ops_no_const clk_pll_ops __read_only = {
39227 .recalc_rate = clk_pll_recalc_rate,
39228 .get_parent = clk_pll_get_parent,
39229 };
39230@@ -120,8 +121,10 @@ static __init struct clk *__socfpga_pll_init(struct device_node *node,
39231 pll_clk->hw.hw.init = &init;
39232
39233 pll_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
39234- clk_pll_ops.enable = clk_gate_ops.enable;
39235- clk_pll_ops.disable = clk_gate_ops.disable;
39236+ pax_open_kernel();
39237+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
39238+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
39239+ pax_close_kernel();
39240
39241 clk = clk_register(NULL, &pll_clk->hw.hw);
39242 if (WARN_ON(IS_ERR(clk))) {
39243diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
39244index b0c18ed..1713a80 100644
39245--- a/drivers/cpufreq/acpi-cpufreq.c
39246+++ b/drivers/cpufreq/acpi-cpufreq.c
39247@@ -675,8 +675,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39248 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
39249 per_cpu(acfreq_data, cpu) = data;
39250
39251- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
39252- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39253+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
39254+ pax_open_kernel();
39255+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39256+ pax_close_kernel();
39257+ }
39258
39259 result = acpi_processor_register_performance(data->acpi_data, cpu);
39260 if (result)
39261@@ -809,7 +812,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39262 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
39263 break;
39264 case ACPI_ADR_SPACE_FIXED_HARDWARE:
39265- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39266+ pax_open_kernel();
39267+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39268+ pax_close_kernel();
39269 break;
39270 default:
39271 break;
39272@@ -903,8 +908,10 @@ static void __init acpi_cpufreq_boost_init(void)
39273 if (!msrs)
39274 return;
39275
39276- acpi_cpufreq_driver.boost_supported = true;
39277- acpi_cpufreq_driver.boost_enabled = boost_state(0);
39278+ pax_open_kernel();
39279+ *(bool *)&acpi_cpufreq_driver.boost_supported = true;
39280+ *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
39281+ pax_close_kernel();
39282
39283 cpu_notifier_register_begin();
39284
39285diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c
39286index f657c57..31d97ae 100644
39287--- a/drivers/cpufreq/cpufreq-dt.c
39288+++ b/drivers/cpufreq/cpufreq-dt.c
39289@@ -362,7 +362,9 @@ static int dt_cpufreq_probe(struct platform_device *pdev)
39290 if (!IS_ERR(cpu_reg))
39291 regulator_put(cpu_reg);
39292
39293- dt_cpufreq_driver.driver_data = dev_get_platdata(&pdev->dev);
39294+ pax_open_kernel();
39295+ *(void **)&dt_cpufreq_driver.driver_data = dev_get_platdata(&pdev->dev);
39296+ pax_close_kernel();
39297
39298 ret = cpufreq_register_driver(&dt_cpufreq_driver);
39299 if (ret)
39300diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
39301index 4473eba..a4c9dc2 100644
39302--- a/drivers/cpufreq/cpufreq.c
39303+++ b/drivers/cpufreq/cpufreq.c
39304@@ -2122,7 +2122,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
39305 }
39306
39307 mutex_lock(&cpufreq_governor_mutex);
39308- list_del(&governor->governor_list);
39309+ pax_list_del(&governor->governor_list);
39310 mutex_unlock(&cpufreq_governor_mutex);
39311 return;
39312 }
39313@@ -2338,7 +2338,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
39314 return NOTIFY_OK;
39315 }
39316
39317-static struct notifier_block __refdata cpufreq_cpu_notifier = {
39318+static struct notifier_block cpufreq_cpu_notifier = {
39319 .notifier_call = cpufreq_cpu_callback,
39320 };
39321
39322@@ -2378,13 +2378,17 @@ int cpufreq_boost_trigger_state(int state)
39323 return 0;
39324
39325 write_lock_irqsave(&cpufreq_driver_lock, flags);
39326- cpufreq_driver->boost_enabled = state;
39327+ pax_open_kernel();
39328+ *(bool *)&cpufreq_driver->boost_enabled = state;
39329+ pax_close_kernel();
39330 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39331
39332 ret = cpufreq_driver->set_boost(state);
39333 if (ret) {
39334 write_lock_irqsave(&cpufreq_driver_lock, flags);
39335- cpufreq_driver->boost_enabled = !state;
39336+ pax_open_kernel();
39337+ *(bool *)&cpufreq_driver->boost_enabled = !state;
39338+ pax_close_kernel();
39339 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39340
39341 pr_err("%s: Cannot %s BOOST\n",
39342@@ -2441,8 +2445,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39343
39344 pr_debug("trying to register driver %s\n", driver_data->name);
39345
39346- if (driver_data->setpolicy)
39347- driver_data->flags |= CPUFREQ_CONST_LOOPS;
39348+ if (driver_data->setpolicy) {
39349+ pax_open_kernel();
39350+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
39351+ pax_close_kernel();
39352+ }
39353
39354 write_lock_irqsave(&cpufreq_driver_lock, flags);
39355 if (cpufreq_driver) {
39356@@ -2457,8 +2464,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39357 * Check if driver provides function to enable boost -
39358 * if not, use cpufreq_boost_set_sw as default
39359 */
39360- if (!cpufreq_driver->set_boost)
39361- cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39362+ if (!cpufreq_driver->set_boost) {
39363+ pax_open_kernel();
39364+ *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39365+ pax_close_kernel();
39366+ }
39367
39368 ret = cpufreq_sysfs_create_file(&boost.attr);
39369 if (ret) {
39370diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
39371index 1b44496..b80ff5e 100644
39372--- a/drivers/cpufreq/cpufreq_governor.c
39373+++ b/drivers/cpufreq/cpufreq_governor.c
39374@@ -245,7 +245,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39375 struct dbs_data *dbs_data;
39376 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
39377 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
39378- struct od_ops *od_ops = NULL;
39379+ const struct od_ops *od_ops = NULL;
39380 struct od_dbs_tuners *od_tuners = NULL;
39381 struct cs_dbs_tuners *cs_tuners = NULL;
39382 struct cpu_dbs_common_info *cpu_cdbs;
39383@@ -311,7 +311,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39384
39385 if ((cdata->governor == GOV_CONSERVATIVE) &&
39386 (!policy->governor->initialized)) {
39387- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39388+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39389
39390 cpufreq_register_notifier(cs_ops->notifier_block,
39391 CPUFREQ_TRANSITION_NOTIFIER);
39392@@ -331,7 +331,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39393
39394 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
39395 (policy->governor->initialized == 1)) {
39396- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39397+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39398
39399 cpufreq_unregister_notifier(cs_ops->notifier_block,
39400 CPUFREQ_TRANSITION_NOTIFIER);
39401diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
39402index cc401d1..8197340 100644
39403--- a/drivers/cpufreq/cpufreq_governor.h
39404+++ b/drivers/cpufreq/cpufreq_governor.h
39405@@ -212,7 +212,7 @@ struct common_dbs_data {
39406 void (*exit)(struct dbs_data *dbs_data);
39407
39408 /* Governor specific ops, see below */
39409- void *gov_ops;
39410+ const void *gov_ops;
39411 };
39412
39413 /* Governor Per policy data */
39414@@ -232,7 +232,7 @@ struct od_ops {
39415 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
39416 unsigned int freq_next, unsigned int relation);
39417 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
39418-};
39419+} __no_const;
39420
39421 struct cs_ops {
39422 struct notifier_block *notifier_block;
39423diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
39424index ad3f38f..8f086cd 100644
39425--- a/drivers/cpufreq/cpufreq_ondemand.c
39426+++ b/drivers/cpufreq/cpufreq_ondemand.c
39427@@ -524,7 +524,7 @@ static void od_exit(struct dbs_data *dbs_data)
39428
39429 define_get_cpu_dbs_routines(od_cpu_dbs_info);
39430
39431-static struct od_ops od_ops = {
39432+static struct od_ops od_ops __read_only = {
39433 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
39434 .powersave_bias_target = generic_powersave_bias_target,
39435 .freq_increase = dbs_freq_increase,
39436@@ -579,14 +579,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
39437 (struct cpufreq_policy *, unsigned int, unsigned int),
39438 unsigned int powersave_bias)
39439 {
39440- od_ops.powersave_bias_target = f;
39441+ pax_open_kernel();
39442+ *(void **)&od_ops.powersave_bias_target = f;
39443+ pax_close_kernel();
39444 od_set_powersave_bias(powersave_bias);
39445 }
39446 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
39447
39448 void od_unregister_powersave_bias_handler(void)
39449 {
39450- od_ops.powersave_bias_target = generic_powersave_bias_target;
39451+ pax_open_kernel();
39452+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
39453+ pax_close_kernel();
39454 od_set_powersave_bias(0);
39455 }
39456 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
39457diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
39458index 27bb6d3..4cf595c 100644
39459--- a/drivers/cpufreq/intel_pstate.c
39460+++ b/drivers/cpufreq/intel_pstate.c
39461@@ -133,10 +133,10 @@ struct pstate_funcs {
39462 struct cpu_defaults {
39463 struct pstate_adjust_policy pid_policy;
39464 struct pstate_funcs funcs;
39465-};
39466+} __do_const;
39467
39468 static struct pstate_adjust_policy pid_params;
39469-static struct pstate_funcs pstate_funcs;
39470+static struct pstate_funcs *pstate_funcs;
39471
39472 struct perf_limits {
39473 int no_turbo;
39474@@ -594,18 +594,18 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
39475
39476 cpu->pstate.current_pstate = pstate;
39477
39478- pstate_funcs.set(cpu, pstate);
39479+ pstate_funcs->set(cpu, pstate);
39480 }
39481
39482 static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
39483 {
39484- cpu->pstate.min_pstate = pstate_funcs.get_min();
39485- cpu->pstate.max_pstate = pstate_funcs.get_max();
39486- cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39487- cpu->pstate.scaling = pstate_funcs.get_scaling();
39488+ cpu->pstate.min_pstate = pstate_funcs->get_min();
39489+ cpu->pstate.max_pstate = pstate_funcs->get_max();
39490+ cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39491+ cpu->pstate.scaling = pstate_funcs->get_scaling();
39492
39493- if (pstate_funcs.get_vid)
39494- pstate_funcs.get_vid(cpu);
39495+ if (pstate_funcs->get_vid)
39496+ pstate_funcs->get_vid(cpu);
39497 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
39498 }
39499
39500@@ -875,9 +875,9 @@ static int intel_pstate_msrs_not_valid(void)
39501 rdmsrl(MSR_IA32_APERF, aperf);
39502 rdmsrl(MSR_IA32_MPERF, mperf);
39503
39504- if (!pstate_funcs.get_max() ||
39505- !pstate_funcs.get_min() ||
39506- !pstate_funcs.get_turbo())
39507+ if (!pstate_funcs->get_max() ||
39508+ !pstate_funcs->get_min() ||
39509+ !pstate_funcs->get_turbo())
39510 return -ENODEV;
39511
39512 rdmsrl(MSR_IA32_APERF, tmp);
39513@@ -891,7 +891,7 @@ static int intel_pstate_msrs_not_valid(void)
39514 return 0;
39515 }
39516
39517-static void copy_pid_params(struct pstate_adjust_policy *policy)
39518+static void copy_pid_params(const struct pstate_adjust_policy *policy)
39519 {
39520 pid_params.sample_rate_ms = policy->sample_rate_ms;
39521 pid_params.p_gain_pct = policy->p_gain_pct;
39522@@ -903,12 +903,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39523
39524 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39525 {
39526- pstate_funcs.get_max = funcs->get_max;
39527- pstate_funcs.get_min = funcs->get_min;
39528- pstate_funcs.get_turbo = funcs->get_turbo;
39529- pstate_funcs.get_scaling = funcs->get_scaling;
39530- pstate_funcs.set = funcs->set;
39531- pstate_funcs.get_vid = funcs->get_vid;
39532+ pstate_funcs = funcs;
39533 }
39534
39535 #if IS_ENABLED(CONFIG_ACPI)
39536diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39537index 529cfd9..0e28fff 100644
39538--- a/drivers/cpufreq/p4-clockmod.c
39539+++ b/drivers/cpufreq/p4-clockmod.c
39540@@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39541 case 0x0F: /* Core Duo */
39542 case 0x16: /* Celeron Core */
39543 case 0x1C: /* Atom */
39544- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39545+ pax_open_kernel();
39546+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39547+ pax_close_kernel();
39548 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39549 case 0x0D: /* Pentium M (Dothan) */
39550- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39551+ pax_open_kernel();
39552+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39553+ pax_close_kernel();
39554 /* fall through */
39555 case 0x09: /* Pentium M (Banias) */
39556 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39557@@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39558
39559 /* on P-4s, the TSC runs with constant frequency independent whether
39560 * throttling is active or not. */
39561- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39562+ pax_open_kernel();
39563+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39564+ pax_close_kernel();
39565
39566 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39567 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39568diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39569index 9bb42ba..b01b4a2 100644
39570--- a/drivers/cpufreq/sparc-us3-cpufreq.c
39571+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39572@@ -18,14 +18,12 @@
39573 #include <asm/head.h>
39574 #include <asm/timer.h>
39575
39576-static struct cpufreq_driver *cpufreq_us3_driver;
39577-
39578 struct us3_freq_percpu_info {
39579 struct cpufreq_frequency_table table[4];
39580 };
39581
39582 /* Indexed by cpu number. */
39583-static struct us3_freq_percpu_info *us3_freq_table;
39584+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39585
39586 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39587 * in the Safari config register.
39588@@ -156,16 +154,27 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39589
39590 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39591 {
39592- if (cpufreq_us3_driver)
39593- us3_freq_target(policy, 0);
39594+ us3_freq_target(policy, 0);
39595
39596 return 0;
39597 }
39598
39599+static int __init us3_freq_init(void);
39600+static void __exit us3_freq_exit(void);
39601+
39602+static struct cpufreq_driver cpufreq_us3_driver = {
39603+ .init = us3_freq_cpu_init,
39604+ .verify = cpufreq_generic_frequency_table_verify,
39605+ .target_index = us3_freq_target,
39606+ .get = us3_freq_get,
39607+ .exit = us3_freq_cpu_exit,
39608+ .name = "UltraSPARC-III",
39609+
39610+};
39611+
39612 static int __init us3_freq_init(void)
39613 {
39614 unsigned long manuf, impl, ver;
39615- int ret;
39616
39617 if (tlb_type != cheetah && tlb_type != cheetah_plus)
39618 return -ENODEV;
39619@@ -178,55 +187,15 @@ static int __init us3_freq_init(void)
39620 (impl == CHEETAH_IMPL ||
39621 impl == CHEETAH_PLUS_IMPL ||
39622 impl == JAGUAR_IMPL ||
39623- impl == PANTHER_IMPL)) {
39624- struct cpufreq_driver *driver;
39625-
39626- ret = -ENOMEM;
39627- driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39628- if (!driver)
39629- goto err_out;
39630-
39631- us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39632- GFP_KERNEL);
39633- if (!us3_freq_table)
39634- goto err_out;
39635-
39636- driver->init = us3_freq_cpu_init;
39637- driver->verify = cpufreq_generic_frequency_table_verify;
39638- driver->target_index = us3_freq_target;
39639- driver->get = us3_freq_get;
39640- driver->exit = us3_freq_cpu_exit;
39641- strcpy(driver->name, "UltraSPARC-III");
39642-
39643- cpufreq_us3_driver = driver;
39644- ret = cpufreq_register_driver(driver);
39645- if (ret)
39646- goto err_out;
39647-
39648- return 0;
39649-
39650-err_out:
39651- if (driver) {
39652- kfree(driver);
39653- cpufreq_us3_driver = NULL;
39654- }
39655- kfree(us3_freq_table);
39656- us3_freq_table = NULL;
39657- return ret;
39658- }
39659+ impl == PANTHER_IMPL))
39660+ return cpufreq_register_driver(&cpufreq_us3_driver);
39661
39662 return -ENODEV;
39663 }
39664
39665 static void __exit us3_freq_exit(void)
39666 {
39667- if (cpufreq_us3_driver) {
39668- cpufreq_unregister_driver(cpufreq_us3_driver);
39669- kfree(cpufreq_us3_driver);
39670- cpufreq_us3_driver = NULL;
39671- kfree(us3_freq_table);
39672- us3_freq_table = NULL;
39673- }
39674+ cpufreq_unregister_driver(&cpufreq_us3_driver);
39675 }
39676
39677 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39678diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39679index 7d4a315..21bb886 100644
39680--- a/drivers/cpufreq/speedstep-centrino.c
39681+++ b/drivers/cpufreq/speedstep-centrino.c
39682@@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39683 !cpu_has(cpu, X86_FEATURE_EST))
39684 return -ENODEV;
39685
39686- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39687- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39688+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39689+ pax_open_kernel();
39690+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39691+ pax_close_kernel();
39692+ }
39693
39694 if (policy->cpu != 0)
39695 return -ENODEV;
39696diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39697index e431d11..d0b997e 100644
39698--- a/drivers/cpuidle/driver.c
39699+++ b/drivers/cpuidle/driver.c
39700@@ -194,7 +194,7 @@ static int poll_idle(struct cpuidle_device *dev,
39701
39702 static void poll_idle_init(struct cpuidle_driver *drv)
39703 {
39704- struct cpuidle_state *state = &drv->states[0];
39705+ cpuidle_state_no_const *state = &drv->states[0];
39706
39707 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39708 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39709diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39710index fb9f511..213e6cc 100644
39711--- a/drivers/cpuidle/governor.c
39712+++ b/drivers/cpuidle/governor.c
39713@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39714 mutex_lock(&cpuidle_lock);
39715 if (__cpuidle_find_governor(gov->name) == NULL) {
39716 ret = 0;
39717- list_add_tail(&gov->governor_list, &cpuidle_governors);
39718+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39719 if (!cpuidle_curr_governor ||
39720 cpuidle_curr_governor->rating < gov->rating)
39721 cpuidle_switch_governor(gov);
39722diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39723index 97c5903..023ad23 100644
39724--- a/drivers/cpuidle/sysfs.c
39725+++ b/drivers/cpuidle/sysfs.c
39726@@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39727 NULL
39728 };
39729
39730-static struct attribute_group cpuidle_attr_group = {
39731+static attribute_group_no_const cpuidle_attr_group = {
39732 .attrs = cpuidle_default_attrs,
39733 .name = "cpuidle",
39734 };
39735diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39736index 8d2a772..33826c9 100644
39737--- a/drivers/crypto/hifn_795x.c
39738+++ b/drivers/crypto/hifn_795x.c
39739@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39740 MODULE_PARM_DESC(hifn_pll_ref,
39741 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39742
39743-static atomic_t hifn_dev_number;
39744+static atomic_unchecked_t hifn_dev_number;
39745
39746 #define ACRYPTO_OP_DECRYPT 0
39747 #define ACRYPTO_OP_ENCRYPT 1
39748@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39749 goto err_out_disable_pci_device;
39750
39751 snprintf(name, sizeof(name), "hifn%d",
39752- atomic_inc_return(&hifn_dev_number)-1);
39753+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
39754
39755 err = pci_request_regions(pdev, name);
39756 if (err)
39757diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39758index 30b538d8..1610d75 100644
39759--- a/drivers/devfreq/devfreq.c
39760+++ b/drivers/devfreq/devfreq.c
39761@@ -673,7 +673,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39762 goto err_out;
39763 }
39764
39765- list_add(&governor->node, &devfreq_governor_list);
39766+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39767
39768 list_for_each_entry(devfreq, &devfreq_list, node) {
39769 int ret = 0;
39770@@ -761,7 +761,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39771 }
39772 }
39773
39774- list_del(&governor->node);
39775+ pax_list_del((struct list_head *)&governor->node);
39776 err_out:
39777 mutex_unlock(&devfreq_list_lock);
39778
39779diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
39780index 42d4974..2714f36 100644
39781--- a/drivers/dma/sh/shdma-base.c
39782+++ b/drivers/dma/sh/shdma-base.c
39783@@ -228,8 +228,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
39784 schan->slave_id = -EINVAL;
39785 }
39786
39787- schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
39788- sdev->desc_size, GFP_KERNEL);
39789+ schan->desc = kcalloc(sdev->desc_size,
39790+ NR_DESCS_PER_CHANNEL, GFP_KERNEL);
39791 if (!schan->desc) {
39792 ret = -ENOMEM;
39793 goto edescalloc;
39794diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39795index 58eb857..d7e42c8 100644
39796--- a/drivers/dma/sh/shdmac.c
39797+++ b/drivers/dma/sh/shdmac.c
39798@@ -513,7 +513,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39799 return ret;
39800 }
39801
39802-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39803+static struct notifier_block sh_dmae_nmi_notifier = {
39804 .notifier_call = sh_dmae_nmi_handler,
39805
39806 /* Run before NMI debug handler and KGDB */
39807diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39808index 592af5f..bb1d583 100644
39809--- a/drivers/edac/edac_device.c
39810+++ b/drivers/edac/edac_device.c
39811@@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39812 */
39813 int edac_device_alloc_index(void)
39814 {
39815- static atomic_t device_indexes = ATOMIC_INIT(0);
39816+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39817
39818- return atomic_inc_return(&device_indexes) - 1;
39819+ return atomic_inc_return_unchecked(&device_indexes) - 1;
39820 }
39821 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39822
39823diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39824index a6cd361..7bdbf53 100644
39825--- a/drivers/edac/edac_mc_sysfs.c
39826+++ b/drivers/edac/edac_mc_sysfs.c
39827@@ -154,7 +154,7 @@ static const char * const edac_caps[] = {
39828 struct dev_ch_attribute {
39829 struct device_attribute attr;
39830 int channel;
39831-};
39832+} __do_const;
39833
39834 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39835 struct dev_ch_attribute dev_attr_legacy_##_name = \
39836@@ -1011,14 +1011,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39837 }
39838
39839 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39840+ pax_open_kernel();
39841 if (mci->get_sdram_scrub_rate) {
39842- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39843- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39844+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39845+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39846 }
39847 if (mci->set_sdram_scrub_rate) {
39848- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39849- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39850+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39851+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39852 }
39853+ pax_close_kernel();
39854 err = device_create_file(&mci->dev,
39855 &dev_attr_sdram_scrub_rate);
39856 if (err) {
39857diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39858index 2cf44b4d..6dd2dc7 100644
39859--- a/drivers/edac/edac_pci.c
39860+++ b/drivers/edac/edac_pci.c
39861@@ -29,7 +29,7 @@
39862
39863 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39864 static LIST_HEAD(edac_pci_list);
39865-static atomic_t pci_indexes = ATOMIC_INIT(0);
39866+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39867
39868 /*
39869 * edac_pci_alloc_ctl_info
39870@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39871 */
39872 int edac_pci_alloc_index(void)
39873 {
39874- return atomic_inc_return(&pci_indexes) - 1;
39875+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
39876 }
39877 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39878
39879diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39880index e8658e4..22746d6 100644
39881--- a/drivers/edac/edac_pci_sysfs.c
39882+++ b/drivers/edac/edac_pci_sysfs.c
39883@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39884 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39885 static int edac_pci_poll_msec = 1000; /* one second workq period */
39886
39887-static atomic_t pci_parity_count = ATOMIC_INIT(0);
39888-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39889+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39890+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39891
39892 static struct kobject *edac_pci_top_main_kobj;
39893 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39894@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39895 void *value;
39896 ssize_t(*show) (void *, char *);
39897 ssize_t(*store) (void *, const char *, size_t);
39898-};
39899+} __do_const;
39900
39901 /* Set of show/store abstract level functions for PCI Parity object */
39902 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39903@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39904 edac_printk(KERN_CRIT, EDAC_PCI,
39905 "Signaled System Error on %s\n",
39906 pci_name(dev));
39907- atomic_inc(&pci_nonparity_count);
39908+ atomic_inc_unchecked(&pci_nonparity_count);
39909 }
39910
39911 if (status & (PCI_STATUS_PARITY)) {
39912@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39913 "Master Data Parity Error on %s\n",
39914 pci_name(dev));
39915
39916- atomic_inc(&pci_parity_count);
39917+ atomic_inc_unchecked(&pci_parity_count);
39918 }
39919
39920 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39921@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39922 "Detected Parity Error on %s\n",
39923 pci_name(dev));
39924
39925- atomic_inc(&pci_parity_count);
39926+ atomic_inc_unchecked(&pci_parity_count);
39927 }
39928 }
39929
39930@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39931 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39932 "Signaled System Error on %s\n",
39933 pci_name(dev));
39934- atomic_inc(&pci_nonparity_count);
39935+ atomic_inc_unchecked(&pci_nonparity_count);
39936 }
39937
39938 if (status & (PCI_STATUS_PARITY)) {
39939@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39940 "Master Data Parity Error on "
39941 "%s\n", pci_name(dev));
39942
39943- atomic_inc(&pci_parity_count);
39944+ atomic_inc_unchecked(&pci_parity_count);
39945 }
39946
39947 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39948@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39949 "Detected Parity Error on %s\n",
39950 pci_name(dev));
39951
39952- atomic_inc(&pci_parity_count);
39953+ atomic_inc_unchecked(&pci_parity_count);
39954 }
39955 }
39956 }
39957@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39958 if (!check_pci_errors)
39959 return;
39960
39961- before_count = atomic_read(&pci_parity_count);
39962+ before_count = atomic_read_unchecked(&pci_parity_count);
39963
39964 /* scan all PCI devices looking for a Parity Error on devices and
39965 * bridges.
39966@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
39967 /* Only if operator has selected panic on PCI Error */
39968 if (edac_pci_get_panic_on_pe()) {
39969 /* If the count is different 'after' from 'before' */
39970- if (before_count != atomic_read(&pci_parity_count))
39971+ if (before_count != atomic_read_unchecked(&pci_parity_count))
39972 panic("EDAC: PCI Parity Error");
39973 }
39974 }
39975diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
39976index 51b7e3a..aa8a3e8 100644
39977--- a/drivers/edac/mce_amd.h
39978+++ b/drivers/edac/mce_amd.h
39979@@ -77,7 +77,7 @@ struct amd_decoder_ops {
39980 bool (*mc0_mce)(u16, u8);
39981 bool (*mc1_mce)(u16, u8);
39982 bool (*mc2_mce)(u16, u8);
39983-};
39984+} __no_const;
39985
39986 void amd_report_gart_errors(bool);
39987 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
39988diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
39989index 57ea7f4..af06b76 100644
39990--- a/drivers/firewire/core-card.c
39991+++ b/drivers/firewire/core-card.c
39992@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
39993 const struct fw_card_driver *driver,
39994 struct device *device)
39995 {
39996- static atomic_t index = ATOMIC_INIT(-1);
39997+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
39998
39999- card->index = atomic_inc_return(&index);
40000+ card->index = atomic_inc_return_unchecked(&index);
40001 card->driver = driver;
40002 card->device = device;
40003 card->current_tlabel = 0;
40004@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
40005
40006 void fw_core_remove_card(struct fw_card *card)
40007 {
40008- struct fw_card_driver dummy_driver = dummy_driver_template;
40009+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
40010
40011 card->driver->update_phy_reg(card, 4,
40012 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
40013diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
40014index 2c6d5e1..a2cca6b 100644
40015--- a/drivers/firewire/core-device.c
40016+++ b/drivers/firewire/core-device.c
40017@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
40018 struct config_rom_attribute {
40019 struct device_attribute attr;
40020 u32 key;
40021-};
40022+} __do_const;
40023
40024 static ssize_t show_immediate(struct device *dev,
40025 struct device_attribute *dattr, char *buf)
40026diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
40027index eb6935c..3cc2bfa 100644
40028--- a/drivers/firewire/core-transaction.c
40029+++ b/drivers/firewire/core-transaction.c
40030@@ -38,6 +38,7 @@
40031 #include <linux/timer.h>
40032 #include <linux/types.h>
40033 #include <linux/workqueue.h>
40034+#include <linux/sched.h>
40035
40036 #include <asm/byteorder.h>
40037
40038diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
40039index e1480ff6..1a429bd 100644
40040--- a/drivers/firewire/core.h
40041+++ b/drivers/firewire/core.h
40042@@ -111,6 +111,7 @@ struct fw_card_driver {
40043
40044 int (*stop_iso)(struct fw_iso_context *ctx);
40045 };
40046+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
40047
40048 void fw_card_initialize(struct fw_card *card,
40049 const struct fw_card_driver *driver, struct device *device);
40050diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
40051index a66a321..f6caf20 100644
40052--- a/drivers/firewire/ohci.c
40053+++ b/drivers/firewire/ohci.c
40054@@ -2056,10 +2056,12 @@ static void bus_reset_work(struct work_struct *work)
40055 be32_to_cpu(ohci->next_header));
40056 }
40057
40058+#ifndef CONFIG_GRKERNSEC
40059 if (param_remote_dma) {
40060 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
40061 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
40062 }
40063+#endif
40064
40065 spin_unlock_irq(&ohci->lock);
40066
40067@@ -2591,8 +2593,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
40068 unsigned long flags;
40069 int n, ret = 0;
40070
40071+#ifndef CONFIG_GRKERNSEC
40072 if (param_remote_dma)
40073 return 0;
40074+#endif
40075
40076 /*
40077 * FIXME: Make sure this bitmask is cleared when we clear the busReset
40078diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
40079index 94a58a0..f5eba42 100644
40080--- a/drivers/firmware/dmi-id.c
40081+++ b/drivers/firmware/dmi-id.c
40082@@ -16,7 +16,7 @@
40083 struct dmi_device_attribute{
40084 struct device_attribute dev_attr;
40085 int field;
40086-};
40087+} __do_const;
40088 #define to_dmi_dev_attr(_dev_attr) \
40089 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
40090
40091diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
40092index 17afc51..0ef90cd 100644
40093--- a/drivers/firmware/dmi_scan.c
40094+++ b/drivers/firmware/dmi_scan.c
40095@@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
40096 if (buf == NULL)
40097 return -1;
40098
40099- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
40100+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
40101
40102 dmi_unmap(buf);
40103 return 0;
40104diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
40105index 5b53d61..72cee96 100644
40106--- a/drivers/firmware/efi/cper.c
40107+++ b/drivers/firmware/efi/cper.c
40108@@ -44,12 +44,12 @@ static char rcd_decode_str[CPER_REC_LEN];
40109 */
40110 u64 cper_next_record_id(void)
40111 {
40112- static atomic64_t seq;
40113+ static atomic64_unchecked_t seq;
40114
40115- if (!atomic64_read(&seq))
40116- atomic64_set(&seq, ((u64)get_seconds()) << 32);
40117+ if (!atomic64_read_unchecked(&seq))
40118+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
40119
40120- return atomic64_inc_return(&seq);
40121+ return atomic64_inc_return_unchecked(&seq);
40122 }
40123 EXPORT_SYMBOL_GPL(cper_next_record_id);
40124
40125diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
40126index 8590099..d83627a 100644
40127--- a/drivers/firmware/efi/efi.c
40128+++ b/drivers/firmware/efi/efi.c
40129@@ -148,14 +148,16 @@ static struct attribute_group efi_subsys_attr_group = {
40130 };
40131
40132 static struct efivars generic_efivars;
40133-static struct efivar_operations generic_ops;
40134+static efivar_operations_no_const generic_ops __read_only;
40135
40136 static int generic_ops_register(void)
40137 {
40138- generic_ops.get_variable = efi.get_variable;
40139- generic_ops.set_variable = efi.set_variable;
40140- generic_ops.get_next_variable = efi.get_next_variable;
40141- generic_ops.query_variable_store = efi_query_variable_store;
40142+ pax_open_kernel();
40143+ *(void **)&generic_ops.get_variable = efi.get_variable;
40144+ *(void **)&generic_ops.set_variable = efi.set_variable;
40145+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
40146+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
40147+ pax_close_kernel();
40148
40149 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
40150 }
40151diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
40152index f256ecd..387dcb1 100644
40153--- a/drivers/firmware/efi/efivars.c
40154+++ b/drivers/firmware/efi/efivars.c
40155@@ -589,7 +589,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
40156 static int
40157 create_efivars_bin_attributes(void)
40158 {
40159- struct bin_attribute *attr;
40160+ bin_attribute_no_const *attr;
40161 int error;
40162
40163 /* new_var */
40164diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
40165index 2f569aa..c95f4fb 100644
40166--- a/drivers/firmware/google/memconsole.c
40167+++ b/drivers/firmware/google/memconsole.c
40168@@ -155,7 +155,10 @@ static int __init memconsole_init(void)
40169 if (!found_memconsole())
40170 return -ENODEV;
40171
40172- memconsole_bin_attr.size = memconsole_length;
40173+ pax_open_kernel();
40174+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
40175+ pax_close_kernel();
40176+
40177 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
40178 }
40179
40180diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
40181index fe49ec3..1ade794 100644
40182--- a/drivers/gpio/gpio-em.c
40183+++ b/drivers/gpio/gpio-em.c
40184@@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
40185 struct em_gio_priv *p;
40186 struct resource *io[2], *irq[2];
40187 struct gpio_chip *gpio_chip;
40188- struct irq_chip *irq_chip;
40189+ irq_chip_no_const *irq_chip;
40190 const char *name = dev_name(&pdev->dev);
40191 int ret;
40192
40193diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
40194index 3784e81..73637b5 100644
40195--- a/drivers/gpio/gpio-ich.c
40196+++ b/drivers/gpio/gpio-ich.c
40197@@ -94,7 +94,7 @@ struct ichx_desc {
40198 * this option allows driver caching written output values
40199 */
40200 bool use_outlvl_cache;
40201-};
40202+} __do_const;
40203
40204 static struct {
40205 spinlock_t lock;
40206diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
40207index bf6c094..6573caf 100644
40208--- a/drivers/gpio/gpio-rcar.c
40209+++ b/drivers/gpio/gpio-rcar.c
40210@@ -357,7 +357,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
40211 struct gpio_rcar_priv *p;
40212 struct resource *io, *irq;
40213 struct gpio_chip *gpio_chip;
40214- struct irq_chip *irq_chip;
40215+ irq_chip_no_const *irq_chip;
40216 struct device *dev = &pdev->dev;
40217 const char *name = dev_name(dev);
40218 int ret;
40219diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
40220index dbf28fa..04dad4e 100644
40221--- a/drivers/gpio/gpio-vr41xx.c
40222+++ b/drivers/gpio/gpio-vr41xx.c
40223@@ -224,7 +224,7 @@ static int giu_get_irq(unsigned int irq)
40224 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
40225 maskl, pendl, maskh, pendh);
40226
40227- atomic_inc(&irq_err_count);
40228+ atomic_inc_unchecked(&irq_err_count);
40229
40230 return -EINVAL;
40231 }
40232diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
40233index e8e98ca..10f416e 100644
40234--- a/drivers/gpio/gpiolib.c
40235+++ b/drivers/gpio/gpiolib.c
40236@@ -537,8 +537,10 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
40237 }
40238
40239 if (gpiochip->irqchip) {
40240- gpiochip->irqchip->irq_request_resources = NULL;
40241- gpiochip->irqchip->irq_release_resources = NULL;
40242+ pax_open_kernel();
40243+ *(void **)&gpiochip->irqchip->irq_request_resources = NULL;
40244+ *(void **)&gpiochip->irqchip->irq_release_resources = NULL;
40245+ pax_close_kernel();
40246 gpiochip->irqchip = NULL;
40247 }
40248 }
40249@@ -604,8 +606,11 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
40250 gpiochip->irqchip = NULL;
40251 return -EINVAL;
40252 }
40253- irqchip->irq_request_resources = gpiochip_irq_reqres;
40254- irqchip->irq_release_resources = gpiochip_irq_relres;
40255+
40256+ pax_open_kernel();
40257+ *(void **)&irqchip->irq_request_resources = gpiochip_irq_reqres;
40258+ *(void **)&irqchip->irq_release_resources = gpiochip_irq_relres;
40259+ pax_close_kernel();
40260
40261 /*
40262 * Prepare the mapping since the irqchip shall be orthogonal to
40263diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
40264index e79c8d3..a9370bc 100644
40265--- a/drivers/gpu/drm/drm_crtc.c
40266+++ b/drivers/gpu/drm/drm_crtc.c
40267@@ -3900,7 +3900,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
40268 goto done;
40269 }
40270
40271- if (copy_to_user(&enum_ptr[copied].name,
40272+ if (copy_to_user(enum_ptr[copied].name,
40273 &prop_enum->name, DRM_PROP_NAME_LEN)) {
40274 ret = -EFAULT;
40275 goto done;
40276diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
40277index bc3da32..7289357 100644
40278--- a/drivers/gpu/drm/drm_drv.c
40279+++ b/drivers/gpu/drm/drm_drv.c
40280@@ -443,7 +443,7 @@ void drm_unplug_dev(struct drm_device *dev)
40281
40282 drm_device_set_unplugged(dev);
40283
40284- if (dev->open_count == 0) {
40285+ if (local_read(&dev->open_count) == 0) {
40286 drm_put_dev(dev);
40287 }
40288 mutex_unlock(&drm_global_mutex);
40289diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
40290index ed7bc68..0d536af 100644
40291--- a/drivers/gpu/drm/drm_fops.c
40292+++ b/drivers/gpu/drm/drm_fops.c
40293@@ -89,7 +89,7 @@ int drm_open(struct inode *inode, struct file *filp)
40294 return PTR_ERR(minor);
40295
40296 dev = minor->dev;
40297- if (!dev->open_count++)
40298+ if (local_inc_return(&dev->open_count) == 1)
40299 need_setup = 1;
40300
40301 /* share address_space across all char-devs of a single device */
40302@@ -106,7 +106,7 @@ int drm_open(struct inode *inode, struct file *filp)
40303 return 0;
40304
40305 err_undo:
40306- dev->open_count--;
40307+ local_dec(&dev->open_count);
40308 drm_minor_release(minor);
40309 return retcode;
40310 }
40311@@ -376,7 +376,7 @@ int drm_release(struct inode *inode, struct file *filp)
40312
40313 mutex_lock(&drm_global_mutex);
40314
40315- DRM_DEBUG("open_count = %d\n", dev->open_count);
40316+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
40317
40318 mutex_lock(&dev->struct_mutex);
40319 list_del(&file_priv->lhead);
40320@@ -389,10 +389,10 @@ int drm_release(struct inode *inode, struct file *filp)
40321 * Begin inline drm_release
40322 */
40323
40324- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
40325+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
40326 task_pid_nr(current),
40327 (long)old_encode_dev(file_priv->minor->kdev->devt),
40328- dev->open_count);
40329+ local_read(&dev->open_count));
40330
40331 /* Release any auth tokens that might point to this file_priv,
40332 (do that under the drm_global_mutex) */
40333@@ -465,7 +465,7 @@ int drm_release(struct inode *inode, struct file *filp)
40334 * End inline drm_release
40335 */
40336
40337- if (!--dev->open_count) {
40338+ if (local_dec_and_test(&dev->open_count)) {
40339 retcode = drm_lastclose(dev);
40340 if (drm_device_is_unplugged(dev))
40341 drm_put_dev(dev);
40342diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
40343index 3d2e91c..d31c4c9 100644
40344--- a/drivers/gpu/drm/drm_global.c
40345+++ b/drivers/gpu/drm/drm_global.c
40346@@ -36,7 +36,7 @@
40347 struct drm_global_item {
40348 struct mutex mutex;
40349 void *object;
40350- int refcount;
40351+ atomic_t refcount;
40352 };
40353
40354 static struct drm_global_item glob[DRM_GLOBAL_NUM];
40355@@ -49,7 +49,7 @@ void drm_global_init(void)
40356 struct drm_global_item *item = &glob[i];
40357 mutex_init(&item->mutex);
40358 item->object = NULL;
40359- item->refcount = 0;
40360+ atomic_set(&item->refcount, 0);
40361 }
40362 }
40363
40364@@ -59,7 +59,7 @@ void drm_global_release(void)
40365 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
40366 struct drm_global_item *item = &glob[i];
40367 BUG_ON(item->object != NULL);
40368- BUG_ON(item->refcount != 0);
40369+ BUG_ON(atomic_read(&item->refcount) != 0);
40370 }
40371 }
40372
40373@@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40374 struct drm_global_item *item = &glob[ref->global_type];
40375
40376 mutex_lock(&item->mutex);
40377- if (item->refcount == 0) {
40378+ if (atomic_read(&item->refcount) == 0) {
40379 item->object = kzalloc(ref->size, GFP_KERNEL);
40380 if (unlikely(item->object == NULL)) {
40381 ret = -ENOMEM;
40382@@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40383 goto out_err;
40384
40385 }
40386- ++item->refcount;
40387+ atomic_inc(&item->refcount);
40388 ref->object = item->object;
40389 mutex_unlock(&item->mutex);
40390 return 0;
40391@@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
40392 struct drm_global_item *item = &glob[ref->global_type];
40393
40394 mutex_lock(&item->mutex);
40395- BUG_ON(item->refcount == 0);
40396+ BUG_ON(atomic_read(&item->refcount) == 0);
40397 BUG_ON(ref->object != item->object);
40398- if (--item->refcount == 0) {
40399+ if (atomic_dec_and_test(&item->refcount)) {
40400 ref->release(ref);
40401 item->object = NULL;
40402 }
40403diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
40404index 51efebd..2b70935 100644
40405--- a/drivers/gpu/drm/drm_info.c
40406+++ b/drivers/gpu/drm/drm_info.c
40407@@ -76,10 +76,13 @@ int drm_vm_info(struct seq_file *m, void *data)
40408 struct drm_local_map *map;
40409 struct drm_map_list *r_list;
40410
40411- /* Hardcoded from _DRM_FRAME_BUFFER,
40412- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
40413- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
40414- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
40415+ static const char * const types[] = {
40416+ [_DRM_FRAME_BUFFER] = "FB",
40417+ [_DRM_REGISTERS] = "REG",
40418+ [_DRM_SHM] = "SHM",
40419+ [_DRM_AGP] = "AGP",
40420+ [_DRM_SCATTER_GATHER] = "SG",
40421+ [_DRM_CONSISTENT] = "PCI"};
40422 const char *type;
40423 int i;
40424
40425@@ -90,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
40426 map = r_list->map;
40427 if (!map)
40428 continue;
40429- if (map->type < 0 || map->type > 5)
40430+ if (map->type >= ARRAY_SIZE(types))
40431 type = "??";
40432 else
40433 type = types[map->type];
40434diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
40435index 2f4c4343..dd12cd2 100644
40436--- a/drivers/gpu/drm/drm_ioc32.c
40437+++ b/drivers/gpu/drm/drm_ioc32.c
40438@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
40439 request = compat_alloc_user_space(nbytes);
40440 if (!access_ok(VERIFY_WRITE, request, nbytes))
40441 return -EFAULT;
40442- list = (struct drm_buf_desc *) (request + 1);
40443+ list = (struct drm_buf_desc __user *) (request + 1);
40444
40445 if (__put_user(count, &request->count)
40446 || __put_user(list, &request->list))
40447@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
40448 request = compat_alloc_user_space(nbytes);
40449 if (!access_ok(VERIFY_WRITE, request, nbytes))
40450 return -EFAULT;
40451- list = (struct drm_buf_pub *) (request + 1);
40452+ list = (struct drm_buf_pub __user *) (request + 1);
40453
40454 if (__put_user(count, &request->count)
40455 || __put_user(list, &request->list))
40456@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
40457 return 0;
40458 }
40459
40460-drm_ioctl_compat_t *drm_compat_ioctls[] = {
40461+drm_ioctl_compat_t drm_compat_ioctls[] = {
40462 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
40463 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
40464 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
40465@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
40466 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40467 {
40468 unsigned int nr = DRM_IOCTL_NR(cmd);
40469- drm_ioctl_compat_t *fn;
40470 int ret;
40471
40472 /* Assume that ioctls without an explicit compat routine will just
40473@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40474 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
40475 return drm_ioctl(filp, cmd, arg);
40476
40477- fn = drm_compat_ioctls[nr];
40478-
40479- if (fn != NULL)
40480- ret = (*fn) (filp, cmd, arg);
40481+ if (drm_compat_ioctls[nr] != NULL)
40482+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
40483 else
40484 ret = drm_ioctl(filp, cmd, arg);
40485
40486diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
40487index 00587a1..57a65ca 100644
40488--- a/drivers/gpu/drm/drm_ioctl.c
40489+++ b/drivers/gpu/drm/drm_ioctl.c
40490@@ -642,7 +642,7 @@ long drm_ioctl(struct file *filp,
40491 struct drm_file *file_priv = filp->private_data;
40492 struct drm_device *dev;
40493 const struct drm_ioctl_desc *ioctl = NULL;
40494- drm_ioctl_t *func;
40495+ drm_ioctl_no_const_t func;
40496 unsigned int nr = DRM_IOCTL_NR(cmd);
40497 int retcode = -EINVAL;
40498 char stack_kdata[128];
40499diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
40500index 93ec5dc..82acbaf 100644
40501--- a/drivers/gpu/drm/i810/i810_drv.h
40502+++ b/drivers/gpu/drm/i810/i810_drv.h
40503@@ -110,8 +110,8 @@ typedef struct drm_i810_private {
40504 int page_flipping;
40505
40506 wait_queue_head_t irq_queue;
40507- atomic_t irq_received;
40508- atomic_t irq_emitted;
40509+ atomic_unchecked_t irq_received;
40510+ atomic_unchecked_t irq_emitted;
40511
40512 int front_offset;
40513 } drm_i810_private_t;
40514diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40515index 318ade9..1f5de55 100644
40516--- a/drivers/gpu/drm/i915/i915_dma.c
40517+++ b/drivers/gpu/drm/i915/i915_dma.c
40518@@ -1294,7 +1294,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40519 * locking inversion with the driver load path. And the access here is
40520 * completely racy anyway. So don't bother with locking for now.
40521 */
40522- return dev->open_count == 0;
40523+ return local_read(&dev->open_count) == 0;
40524 }
40525
40526 static const struct vga_switcheroo_client_ops i915_switcheroo_ops = {
40527diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40528index 1a0611b..dd1fbfc 100644
40529--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40530+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40531@@ -866,12 +866,12 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40532 static int
40533 validate_exec_list(struct drm_device *dev,
40534 struct drm_i915_gem_exec_object2 *exec,
40535- int count)
40536+ unsigned int count)
40537 {
40538 unsigned relocs_total = 0;
40539 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40540 unsigned invalid_flags;
40541- int i;
40542+ unsigned int i;
40543
40544 invalid_flags = __EXEC_OBJECT_UNKNOWN_FLAGS;
40545 if (USES_FULL_PPGTT(dev))
40546diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40547index 2e0613e..a8b94d9 100644
40548--- a/drivers/gpu/drm/i915/i915_ioc32.c
40549+++ b/drivers/gpu/drm/i915/i915_ioc32.c
40550@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40551 (unsigned long)request);
40552 }
40553
40554-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40555+static drm_ioctl_compat_t i915_compat_ioctls[] = {
40556 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40557 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40558 [DRM_I915_GETPARAM] = compat_i915_getparam,
40559@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40560 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40561 {
40562 unsigned int nr = DRM_IOCTL_NR(cmd);
40563- drm_ioctl_compat_t *fn = NULL;
40564 int ret;
40565
40566 if (nr < DRM_COMMAND_BASE)
40567 return drm_compat_ioctl(filp, cmd, arg);
40568
40569- if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls))
40570- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40571-
40572- if (fn != NULL)
40573+ if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls)) {
40574+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40575 ret = (*fn) (filp, cmd, arg);
40576- else
40577+ } else
40578 ret = drm_ioctl(filp, cmd, arg);
40579
40580 return ret;
40581diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40582index 9cb5c95..9228666 100644
40583--- a/drivers/gpu/drm/i915/intel_display.c
40584+++ b/drivers/gpu/drm/i915/intel_display.c
40585@@ -12811,13 +12811,13 @@ struct intel_quirk {
40586 int subsystem_vendor;
40587 int subsystem_device;
40588 void (*hook)(struct drm_device *dev);
40589-};
40590+} __do_const;
40591
40592 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40593 struct intel_dmi_quirk {
40594 void (*hook)(struct drm_device *dev);
40595 const struct dmi_system_id (*dmi_id_list)[];
40596-};
40597+} __do_const;
40598
40599 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40600 {
40601@@ -12825,18 +12825,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40602 return 1;
40603 }
40604
40605-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40606+static const struct dmi_system_id intel_dmi_quirks_table[] = {
40607 {
40608- .dmi_id_list = &(const struct dmi_system_id[]) {
40609- {
40610- .callback = intel_dmi_reverse_brightness,
40611- .ident = "NCR Corporation",
40612- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40613- DMI_MATCH(DMI_PRODUCT_NAME, ""),
40614- },
40615- },
40616- { } /* terminating entry */
40617+ .callback = intel_dmi_reverse_brightness,
40618+ .ident = "NCR Corporation",
40619+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40620+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
40621 },
40622+ },
40623+ { } /* terminating entry */
40624+};
40625+
40626+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40627+ {
40628+ .dmi_id_list = &intel_dmi_quirks_table,
40629 .hook = quirk_invert_brightness,
40630 },
40631 };
40632diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40633index b4a2014..219ab78 100644
40634--- a/drivers/gpu/drm/mga/mga_drv.h
40635+++ b/drivers/gpu/drm/mga/mga_drv.h
40636@@ -122,9 +122,9 @@ typedef struct drm_mga_private {
40637 u32 clear_cmd;
40638 u32 maccess;
40639
40640- atomic_t vbl_received; /**< Number of vblanks received. */
40641+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40642 wait_queue_head_t fence_queue;
40643- atomic_t last_fence_retired;
40644+ atomic_unchecked_t last_fence_retired;
40645 u32 next_fence_to_post;
40646
40647 unsigned int fb_cpp;
40648diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40649index 729bfd5..ead8823 100644
40650--- a/drivers/gpu/drm/mga/mga_ioc32.c
40651+++ b/drivers/gpu/drm/mga/mga_ioc32.c
40652@@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40653 return 0;
40654 }
40655
40656-drm_ioctl_compat_t *mga_compat_ioctls[] = {
40657+drm_ioctl_compat_t mga_compat_ioctls[] = {
40658 [DRM_MGA_INIT] = compat_mga_init,
40659 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40660 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40661@@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40662 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40663 {
40664 unsigned int nr = DRM_IOCTL_NR(cmd);
40665- drm_ioctl_compat_t *fn = NULL;
40666 int ret;
40667
40668 if (nr < DRM_COMMAND_BASE)
40669 return drm_compat_ioctl(filp, cmd, arg);
40670
40671- if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls))
40672- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40673-
40674- if (fn != NULL)
40675+ if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls)) {
40676+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40677 ret = (*fn) (filp, cmd, arg);
40678- else
40679+ } else
40680 ret = drm_ioctl(filp, cmd, arg);
40681
40682 return ret;
40683diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40684index 1b071b8..de8601a 100644
40685--- a/drivers/gpu/drm/mga/mga_irq.c
40686+++ b/drivers/gpu/drm/mga/mga_irq.c
40687@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40688 if (crtc != 0)
40689 return 0;
40690
40691- return atomic_read(&dev_priv->vbl_received);
40692+ return atomic_read_unchecked(&dev_priv->vbl_received);
40693 }
40694
40695
40696@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40697 /* VBLANK interrupt */
40698 if (status & MGA_VLINEPEN) {
40699 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40700- atomic_inc(&dev_priv->vbl_received);
40701+ atomic_inc_unchecked(&dev_priv->vbl_received);
40702 drm_handle_vblank(dev, 0);
40703 handled = 1;
40704 }
40705@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40706 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40707 MGA_WRITE(MGA_PRIMEND, prim_end);
40708
40709- atomic_inc(&dev_priv->last_fence_retired);
40710+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
40711 wake_up(&dev_priv->fence_queue);
40712 handled = 1;
40713 }
40714@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40715 * using fences.
40716 */
40717 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
40718- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40719+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40720 - *sequence) <= (1 << 23)));
40721
40722 *sequence = cur_fence;
40723diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40724index dae2c96..324dbe4 100644
40725--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40726+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40727@@ -963,7 +963,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40728 struct bit_table {
40729 const char id;
40730 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40731-};
40732+} __no_const;
40733
40734 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40735
40736diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40737index 8ae36f2..1147a30 100644
40738--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40739+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40740@@ -121,7 +121,6 @@ struct nouveau_drm {
40741 struct drm_global_reference mem_global_ref;
40742 struct ttm_bo_global_ref bo_global_ref;
40743 struct ttm_bo_device bdev;
40744- atomic_t validate_sequence;
40745 int (*move)(struct nouveau_channel *,
40746 struct ttm_buffer_object *,
40747 struct ttm_mem_reg *, struct ttm_mem_reg *);
40748diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40749index 462679a..88e32a7 100644
40750--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40751+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40752@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40753 unsigned long arg)
40754 {
40755 unsigned int nr = DRM_IOCTL_NR(cmd);
40756- drm_ioctl_compat_t *fn = NULL;
40757+ drm_ioctl_compat_t fn = NULL;
40758 int ret;
40759
40760 if (nr < DRM_COMMAND_BASE)
40761diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40762index 753a6de..dd66b98 100644
40763--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40764+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40765@@ -126,11 +126,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40766 }
40767
40768 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40769- nouveau_vram_manager_init,
40770- nouveau_vram_manager_fini,
40771- nouveau_vram_manager_new,
40772- nouveau_vram_manager_del,
40773- nouveau_vram_manager_debug
40774+ .init = nouveau_vram_manager_init,
40775+ .takedown = nouveau_vram_manager_fini,
40776+ .get_node = nouveau_vram_manager_new,
40777+ .put_node = nouveau_vram_manager_del,
40778+ .debug = nouveau_vram_manager_debug
40779 };
40780
40781 static int
40782@@ -194,11 +194,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40783 }
40784
40785 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40786- nouveau_gart_manager_init,
40787- nouveau_gart_manager_fini,
40788- nouveau_gart_manager_new,
40789- nouveau_gart_manager_del,
40790- nouveau_gart_manager_debug
40791+ .init = nouveau_gart_manager_init,
40792+ .takedown = nouveau_gart_manager_fini,
40793+ .get_node = nouveau_gart_manager_new,
40794+ .put_node = nouveau_gart_manager_del,
40795+ .debug = nouveau_gart_manager_debug
40796 };
40797
40798 /*XXX*/
40799@@ -267,11 +267,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40800 }
40801
40802 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40803- nv04_gart_manager_init,
40804- nv04_gart_manager_fini,
40805- nv04_gart_manager_new,
40806- nv04_gart_manager_del,
40807- nv04_gart_manager_debug
40808+ .init = nv04_gart_manager_init,
40809+ .takedown = nv04_gart_manager_fini,
40810+ .get_node = nv04_gart_manager_new,
40811+ .put_node = nv04_gart_manager_del,
40812+ .debug = nv04_gart_manager_debug
40813 };
40814
40815 int
40816diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40817index c7592ec..dd45ebc 100644
40818--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40819+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40820@@ -72,7 +72,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40821 * locking inversion with the driver load path. And the access here is
40822 * completely racy anyway. So don't bother with locking for now.
40823 */
40824- return dev->open_count == 0;
40825+ return local_read(&dev->open_count) == 0;
40826 }
40827
40828 static const struct vga_switcheroo_client_ops
40829diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40830index 9782364..89bd954 100644
40831--- a/drivers/gpu/drm/qxl/qxl_cmd.c
40832+++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40833@@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40834 int ret;
40835
40836 mutex_lock(&qdev->async_io_mutex);
40837- irq_num = atomic_read(&qdev->irq_received_io_cmd);
40838+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40839 if (qdev->last_sent_io_cmd > irq_num) {
40840 if (intr)
40841 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40842- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40843+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40844 else
40845 ret = wait_event_timeout(qdev->io_cmd_event,
40846- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40847+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40848 /* 0 is timeout, just bail the "hw" has gone away */
40849 if (ret <= 0)
40850 goto out;
40851- irq_num = atomic_read(&qdev->irq_received_io_cmd);
40852+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40853 }
40854 outb(val, addr);
40855 qdev->last_sent_io_cmd = irq_num + 1;
40856 if (intr)
40857 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40858- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40859+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40860 else
40861 ret = wait_event_timeout(qdev->io_cmd_event,
40862- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40863+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40864 out:
40865 if (ret > 0)
40866 ret = 0;
40867diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
40868index 6911b8c..89d6867 100644
40869--- a/drivers/gpu/drm/qxl/qxl_debugfs.c
40870+++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
40871@@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
40872 struct drm_info_node *node = (struct drm_info_node *) m->private;
40873 struct qxl_device *qdev = node->minor->dev->dev_private;
40874
40875- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
40876- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
40877- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
40878- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
40879+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
40880+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
40881+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
40882+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
40883 seq_printf(m, "%d\n", qdev->irq_received_error);
40884 return 0;
40885 }
40886diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
40887index 7c6cafe..460f542 100644
40888--- a/drivers/gpu/drm/qxl/qxl_drv.h
40889+++ b/drivers/gpu/drm/qxl/qxl_drv.h
40890@@ -290,10 +290,10 @@ struct qxl_device {
40891 unsigned int last_sent_io_cmd;
40892
40893 /* interrupt handling */
40894- atomic_t irq_received;
40895- atomic_t irq_received_display;
40896- atomic_t irq_received_cursor;
40897- atomic_t irq_received_io_cmd;
40898+ atomic_unchecked_t irq_received;
40899+ atomic_unchecked_t irq_received_display;
40900+ atomic_unchecked_t irq_received_cursor;
40901+ atomic_unchecked_t irq_received_io_cmd;
40902 unsigned irq_received_error;
40903 wait_queue_head_t display_event;
40904 wait_queue_head_t cursor_event;
40905diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
40906index b110883..dd06418 100644
40907--- a/drivers/gpu/drm/qxl/qxl_ioctl.c
40908+++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
40909@@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40910
40911 /* TODO copy slow path code from i915 */
40912 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
40913- 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);
40914+ 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);
40915
40916 {
40917 struct qxl_drawable *draw = fb_cmd;
40918@@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40919 struct drm_qxl_reloc reloc;
40920
40921 if (copy_from_user(&reloc,
40922- &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
40923+ &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
40924 sizeof(reloc))) {
40925 ret = -EFAULT;
40926 goto out_free_bos;
40927@@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
40928
40929 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
40930
40931- struct drm_qxl_command *commands =
40932- (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
40933+ struct drm_qxl_command __user *commands =
40934+ (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
40935
40936- if (copy_from_user(&user_cmd, &commands[cmd_num],
40937+ if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
40938 sizeof(user_cmd)))
40939 return -EFAULT;
40940
40941diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
40942index 0bf1e20..42a7310 100644
40943--- a/drivers/gpu/drm/qxl/qxl_irq.c
40944+++ b/drivers/gpu/drm/qxl/qxl_irq.c
40945@@ -36,19 +36,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
40946 if (!pending)
40947 return IRQ_NONE;
40948
40949- atomic_inc(&qdev->irq_received);
40950+ atomic_inc_unchecked(&qdev->irq_received);
40951
40952 if (pending & QXL_INTERRUPT_DISPLAY) {
40953- atomic_inc(&qdev->irq_received_display);
40954+ atomic_inc_unchecked(&qdev->irq_received_display);
40955 wake_up_all(&qdev->display_event);
40956 qxl_queue_garbage_collect(qdev, false);
40957 }
40958 if (pending & QXL_INTERRUPT_CURSOR) {
40959- atomic_inc(&qdev->irq_received_cursor);
40960+ atomic_inc_unchecked(&qdev->irq_received_cursor);
40961 wake_up_all(&qdev->cursor_event);
40962 }
40963 if (pending & QXL_INTERRUPT_IO_CMD) {
40964- atomic_inc(&qdev->irq_received_io_cmd);
40965+ atomic_inc_unchecked(&qdev->irq_received_io_cmd);
40966 wake_up_all(&qdev->io_cmd_event);
40967 }
40968 if (pending & QXL_INTERRUPT_ERROR) {
40969@@ -85,10 +85,10 @@ int qxl_irq_init(struct qxl_device *qdev)
40970 init_waitqueue_head(&qdev->io_cmd_event);
40971 INIT_WORK(&qdev->client_monitors_config_work,
40972 qxl_client_monitors_config_work_func);
40973- atomic_set(&qdev->irq_received, 0);
40974- atomic_set(&qdev->irq_received_display, 0);
40975- atomic_set(&qdev->irq_received_cursor, 0);
40976- atomic_set(&qdev->irq_received_io_cmd, 0);
40977+ atomic_set_unchecked(&qdev->irq_received, 0);
40978+ atomic_set_unchecked(&qdev->irq_received_display, 0);
40979+ atomic_set_unchecked(&qdev->irq_received_cursor, 0);
40980+ atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
40981 qdev->irq_received_error = 0;
40982 ret = drm_irq_install(qdev->ddev, qdev->ddev->pdev->irq);
40983 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
40984diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
40985index 0cbc4c9..0e46686 100644
40986--- a/drivers/gpu/drm/qxl/qxl_ttm.c
40987+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
40988@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
40989 }
40990 }
40991
40992-static struct vm_operations_struct qxl_ttm_vm_ops;
40993+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
40994 static const struct vm_operations_struct *ttm_vm_ops;
40995
40996 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40997@@ -145,8 +145,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
40998 return r;
40999 if (unlikely(ttm_vm_ops == NULL)) {
41000 ttm_vm_ops = vma->vm_ops;
41001+ pax_open_kernel();
41002 qxl_ttm_vm_ops = *ttm_vm_ops;
41003 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
41004+ pax_close_kernel();
41005 }
41006 vma->vm_ops = &qxl_ttm_vm_ops;
41007 return 0;
41008@@ -464,25 +466,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
41009 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
41010 {
41011 #if defined(CONFIG_DEBUG_FS)
41012- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
41013- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
41014- unsigned i;
41015+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
41016+ {
41017+ .name = "qxl_mem_mm",
41018+ .show = &qxl_mm_dump_table,
41019+ },
41020+ {
41021+ .name = "qxl_surf_mm",
41022+ .show = &qxl_mm_dump_table,
41023+ }
41024+ };
41025
41026- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
41027- if (i == 0)
41028- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
41029- else
41030- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
41031- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
41032- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
41033- qxl_mem_types_list[i].driver_features = 0;
41034- if (i == 0)
41035- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41036- else
41037- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41038+ pax_open_kernel();
41039+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41040+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41041+ pax_close_kernel();
41042
41043- }
41044- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
41045+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
41046 #else
41047 return 0;
41048 #endif
41049diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
41050index 2c45ac9..5d740f8 100644
41051--- a/drivers/gpu/drm/r128/r128_cce.c
41052+++ b/drivers/gpu/drm/r128/r128_cce.c
41053@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
41054
41055 /* GH: Simple idle check.
41056 */
41057- atomic_set(&dev_priv->idle_count, 0);
41058+ atomic_set_unchecked(&dev_priv->idle_count, 0);
41059
41060 /* We don't support anything other than bus-mastering ring mode,
41061 * but the ring can be in either AGP or PCI space for the ring
41062diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
41063index 723e5d6..102dbaf 100644
41064--- a/drivers/gpu/drm/r128/r128_drv.h
41065+++ b/drivers/gpu/drm/r128/r128_drv.h
41066@@ -93,14 +93,14 @@ typedef struct drm_r128_private {
41067 int is_pci;
41068 unsigned long cce_buffers_offset;
41069
41070- atomic_t idle_count;
41071+ atomic_unchecked_t idle_count;
41072
41073 int page_flipping;
41074 int current_page;
41075 u32 crtc_offset;
41076 u32 crtc_offset_cntl;
41077
41078- atomic_t vbl_received;
41079+ atomic_unchecked_t vbl_received;
41080
41081 u32 color_fmt;
41082 unsigned int front_offset;
41083diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
41084index 663f38c..c689495 100644
41085--- a/drivers/gpu/drm/r128/r128_ioc32.c
41086+++ b/drivers/gpu/drm/r128/r128_ioc32.c
41087@@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
41088 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
41089 }
41090
41091-drm_ioctl_compat_t *r128_compat_ioctls[] = {
41092+drm_ioctl_compat_t r128_compat_ioctls[] = {
41093 [DRM_R128_INIT] = compat_r128_init,
41094 [DRM_R128_DEPTH] = compat_r128_depth,
41095 [DRM_R128_STIPPLE] = compat_r128_stipple,
41096@@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
41097 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41098 {
41099 unsigned int nr = DRM_IOCTL_NR(cmd);
41100- drm_ioctl_compat_t *fn = NULL;
41101 int ret;
41102
41103 if (nr < DRM_COMMAND_BASE)
41104 return drm_compat_ioctl(filp, cmd, arg);
41105
41106- if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls))
41107- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41108-
41109- if (fn != NULL)
41110+ if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls)) {
41111+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41112 ret = (*fn) (filp, cmd, arg);
41113- else
41114+ } else
41115 ret = drm_ioctl(filp, cmd, arg);
41116
41117 return ret;
41118diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
41119index c2ae496..30b5993 100644
41120--- a/drivers/gpu/drm/r128/r128_irq.c
41121+++ b/drivers/gpu/drm/r128/r128_irq.c
41122@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
41123 if (crtc != 0)
41124 return 0;
41125
41126- return atomic_read(&dev_priv->vbl_received);
41127+ return atomic_read_unchecked(&dev_priv->vbl_received);
41128 }
41129
41130 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41131@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41132 /* VBLANK interrupt */
41133 if (status & R128_CRTC_VBLANK_INT) {
41134 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
41135- atomic_inc(&dev_priv->vbl_received);
41136+ atomic_inc_unchecked(&dev_priv->vbl_received);
41137 drm_handle_vblank(dev, 0);
41138 return IRQ_HANDLED;
41139 }
41140diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
41141index 575e986..66e62ca 100644
41142--- a/drivers/gpu/drm/r128/r128_state.c
41143+++ b/drivers/gpu/drm/r128/r128_state.c
41144@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
41145
41146 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
41147 {
41148- if (atomic_read(&dev_priv->idle_count) == 0)
41149+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
41150 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
41151 else
41152- atomic_set(&dev_priv->idle_count, 0);
41153+ atomic_set_unchecked(&dev_priv->idle_count, 0);
41154 }
41155
41156 #endif
41157diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
41158index 4a85bb6..aaea819 100644
41159--- a/drivers/gpu/drm/radeon/mkregtable.c
41160+++ b/drivers/gpu/drm/radeon/mkregtable.c
41161@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
41162 regex_t mask_rex;
41163 regmatch_t match[4];
41164 char buf[1024];
41165- size_t end;
41166+ long end;
41167 int len;
41168 int done = 0;
41169 int r;
41170 unsigned o;
41171 struct offset *offset;
41172 char last_reg_s[10];
41173- int last_reg;
41174+ unsigned long last_reg;
41175
41176 if (regcomp
41177 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
41178diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
41179index 995a8b1..b7cb898 100644
41180--- a/drivers/gpu/drm/radeon/radeon_device.c
41181+++ b/drivers/gpu/drm/radeon/radeon_device.c
41182@@ -1214,7 +1214,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
41183 * locking inversion with the driver load path. And the access here is
41184 * completely racy anyway. So don't bother with locking for now.
41185 */
41186- return dev->open_count == 0;
41187+ return local_read(&dev->open_count) == 0;
41188 }
41189
41190 static const struct vga_switcheroo_client_ops radeon_switcheroo_ops = {
41191diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
41192index 46bd393..6ae4719 100644
41193--- a/drivers/gpu/drm/radeon/radeon_drv.h
41194+++ b/drivers/gpu/drm/radeon/radeon_drv.h
41195@@ -264,7 +264,7 @@ typedef struct drm_radeon_private {
41196
41197 /* SW interrupt */
41198 wait_queue_head_t swi_queue;
41199- atomic_t swi_emitted;
41200+ atomic_unchecked_t swi_emitted;
41201 int vblank_crtc;
41202 uint32_t irq_enable_reg;
41203 uint32_t r500_disp_irq_reg;
41204diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
41205index 0b98ea1..0881827 100644
41206--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
41207+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
41208@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41209 request = compat_alloc_user_space(sizeof(*request));
41210 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
41211 || __put_user(req32.param, &request->param)
41212- || __put_user((void __user *)(unsigned long)req32.value,
41213+ || __put_user((unsigned long)req32.value,
41214 &request->value))
41215 return -EFAULT;
41216
41217@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41218 #define compat_radeon_cp_setparam NULL
41219 #endif /* X86_64 || IA64 */
41220
41221-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41222+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
41223 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
41224 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
41225 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
41226@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41227 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41228 {
41229 unsigned int nr = DRM_IOCTL_NR(cmd);
41230- drm_ioctl_compat_t *fn = NULL;
41231 int ret;
41232
41233 if (nr < DRM_COMMAND_BASE)
41234 return drm_compat_ioctl(filp, cmd, arg);
41235
41236- if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls))
41237- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41238-
41239- if (fn != NULL)
41240+ if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls)) {
41241+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41242 ret = (*fn) (filp, cmd, arg);
41243- else
41244+ } else
41245 ret = drm_ioctl(filp, cmd, arg);
41246
41247 return ret;
41248diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
41249index 244b19b..c19226d 100644
41250--- a/drivers/gpu/drm/radeon/radeon_irq.c
41251+++ b/drivers/gpu/drm/radeon/radeon_irq.c
41252@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
41253 unsigned int ret;
41254 RING_LOCALS;
41255
41256- atomic_inc(&dev_priv->swi_emitted);
41257- ret = atomic_read(&dev_priv->swi_emitted);
41258+ atomic_inc_unchecked(&dev_priv->swi_emitted);
41259+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
41260
41261 BEGIN_RING(4);
41262 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
41263@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
41264 drm_radeon_private_t *dev_priv =
41265 (drm_radeon_private_t *) dev->dev_private;
41266
41267- atomic_set(&dev_priv->swi_emitted, 0);
41268+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
41269 init_waitqueue_head(&dev_priv->swi_queue);
41270
41271 dev->max_vblank_count = 0x001fffff;
41272diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
41273index 535403e..5dd655b 100644
41274--- a/drivers/gpu/drm/radeon/radeon_state.c
41275+++ b/drivers/gpu/drm/radeon/radeon_state.c
41276@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
41277 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
41278 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
41279
41280- if (copy_from_user(&depth_boxes, clear->depth_boxes,
41281+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
41282 sarea_priv->nbox * sizeof(depth_boxes[0])))
41283 return -EFAULT;
41284
41285@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
41286 {
41287 drm_radeon_private_t *dev_priv = dev->dev_private;
41288 drm_radeon_getparam_t *param = data;
41289- int value;
41290+ int value = 0;
41291
41292 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
41293
41294diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
41295index 8624979..65e5243 100644
41296--- a/drivers/gpu/drm/radeon/radeon_ttm.c
41297+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
41298@@ -936,7 +936,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
41299 man->size = size >> PAGE_SHIFT;
41300 }
41301
41302-static struct vm_operations_struct radeon_ttm_vm_ops;
41303+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
41304 static const struct vm_operations_struct *ttm_vm_ops = NULL;
41305
41306 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41307@@ -977,8 +977,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
41308 }
41309 if (unlikely(ttm_vm_ops == NULL)) {
41310 ttm_vm_ops = vma->vm_ops;
41311+ pax_open_kernel();
41312 radeon_ttm_vm_ops = *ttm_vm_ops;
41313 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
41314+ pax_close_kernel();
41315 }
41316 vma->vm_ops = &radeon_ttm_vm_ops;
41317 return 0;
41318diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41319index 054a79f..30d9ac4 100644
41320--- a/drivers/gpu/drm/tegra/dc.c
41321+++ b/drivers/gpu/drm/tegra/dc.c
41322@@ -1242,7 +1242,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41323 }
41324
41325 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41326- dc->debugfs_files[i].data = dc;
41327+ *(void **)&dc->debugfs_files[i].data = dc;
41328
41329 err = drm_debugfs_create_files(dc->debugfs_files,
41330 ARRAY_SIZE(debugfs_files),
41331diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
41332index f787445..2df2c65 100644
41333--- a/drivers/gpu/drm/tegra/dsi.c
41334+++ b/drivers/gpu/drm/tegra/dsi.c
41335@@ -41,7 +41,7 @@ struct tegra_dsi {
41336 struct clk *clk_lp;
41337 struct clk *clk;
41338
41339- struct drm_info_list *debugfs_files;
41340+ drm_info_list_no_const *debugfs_files;
41341 struct drm_minor *minor;
41342 struct dentry *debugfs;
41343
41344diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41345index ffe2654..03c7b1c 100644
41346--- a/drivers/gpu/drm/tegra/hdmi.c
41347+++ b/drivers/gpu/drm/tegra/hdmi.c
41348@@ -60,7 +60,7 @@ struct tegra_hdmi {
41349 bool stereo;
41350 bool dvi;
41351
41352- struct drm_info_list *debugfs_files;
41353+ drm_info_list_no_const *debugfs_files;
41354 struct drm_minor *minor;
41355 struct dentry *debugfs;
41356 };
41357diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41358index 964387f..4eafc00 100644
41359--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41360+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41361@@ -146,10 +146,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41362 }
41363
41364 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41365- ttm_bo_man_init,
41366- ttm_bo_man_takedown,
41367- ttm_bo_man_get_node,
41368- ttm_bo_man_put_node,
41369- ttm_bo_man_debug
41370+ .init = ttm_bo_man_init,
41371+ .takedown = ttm_bo_man_takedown,
41372+ .get_node = ttm_bo_man_get_node,
41373+ .put_node = ttm_bo_man_put_node,
41374+ .debug = ttm_bo_man_debug
41375 };
41376 EXPORT_SYMBOL(ttm_bo_manager_func);
41377diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41378index a1803fb..c53f6b0 100644
41379--- a/drivers/gpu/drm/ttm/ttm_memory.c
41380+++ b/drivers/gpu/drm/ttm/ttm_memory.c
41381@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41382 zone->glob = glob;
41383 glob->zone_kernel = zone;
41384 ret = kobject_init_and_add(
41385- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41386+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41387 if (unlikely(ret != 0)) {
41388 kobject_put(&zone->kobj);
41389 return ret;
41390@@ -348,7 +348,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41391 zone->glob = glob;
41392 glob->zone_dma32 = zone;
41393 ret = kobject_init_and_add(
41394- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41395+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41396 if (unlikely(ret != 0)) {
41397 kobject_put(&zone->kobj);
41398 return ret;
41399diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41400index 09874d6..d6da1de 100644
41401--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41402+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41403@@ -54,7 +54,7 @@
41404
41405 #define NUM_PAGES_TO_ALLOC (PAGE_SIZE/sizeof(struct page *))
41406 #define SMALL_ALLOCATION 16
41407-#define FREE_ALL_PAGES (~0U)
41408+#define FREE_ALL_PAGES (~0UL)
41409 /* times are in msecs */
41410 #define PAGE_FREE_INTERVAL 1000
41411
41412@@ -299,14 +299,13 @@ static void ttm_pool_update_free_locked(struct ttm_page_pool *pool,
41413 * @free_all: If set to true will free all pages in pool
41414 * @gfp: GFP flags.
41415 **/
41416-static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free,
41417+static unsigned long ttm_page_pool_free(struct ttm_page_pool *pool, unsigned long nr_free,
41418 gfp_t gfp)
41419 {
41420 unsigned long irq_flags;
41421 struct page *p;
41422 struct page **pages_to_free;
41423- unsigned freed_pages = 0,
41424- npages_to_free = nr_free;
41425+ unsigned long freed_pages = 0, npages_to_free = nr_free;
41426
41427 if (NUM_PAGES_TO_ALLOC < nr_free)
41428 npages_to_free = NUM_PAGES_TO_ALLOC;
41429@@ -366,7 +365,8 @@ restart:
41430 __list_del(&p->lru, &pool->list);
41431
41432 ttm_pool_update_free_locked(pool, freed_pages);
41433- nr_free -= freed_pages;
41434+ if (likely(nr_free != FREE_ALL_PAGES))
41435+ nr_free -= freed_pages;
41436 }
41437
41438 spin_unlock_irqrestore(&pool->lock, irq_flags);
41439@@ -395,7 +395,7 @@ ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41440 unsigned i;
41441 unsigned pool_offset;
41442 struct ttm_page_pool *pool;
41443- int shrink_pages = sc->nr_to_scan;
41444+ unsigned long shrink_pages = sc->nr_to_scan;
41445 unsigned long freed = 0;
41446
41447 if (!mutex_trylock(&lock))
41448@@ -403,7 +403,7 @@ ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41449 pool_offset = ++start_pool % NUM_POOLS;
41450 /* select start pool in round robin fashion */
41451 for (i = 0; i < NUM_POOLS; ++i) {
41452- unsigned nr_free = shrink_pages;
41453+ unsigned long nr_free = shrink_pages;
41454 if (shrink_pages == 0)
41455 break;
41456 pool = &_manager->pools[(i + pool_offset)%NUM_POOLS];
41457@@ -669,7 +669,7 @@ out:
41458 }
41459
41460 /* Put all pages in pages list to correct pool to wait for reuse */
41461-static void ttm_put_pages(struct page **pages, unsigned npages, int flags,
41462+static void ttm_put_pages(struct page **pages, unsigned long npages, int flags,
41463 enum ttm_caching_state cstate)
41464 {
41465 unsigned long irq_flags;
41466@@ -724,7 +724,7 @@ static int ttm_get_pages(struct page **pages, unsigned npages, int flags,
41467 struct list_head plist;
41468 struct page *p = NULL;
41469 gfp_t gfp_flags = GFP_USER;
41470- unsigned count;
41471+ unsigned long count;
41472 int r;
41473
41474 /* set zero flag for page allocation if required */
41475diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
41476index c96db43..c367557 100644
41477--- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
41478+++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
41479@@ -56,7 +56,7 @@
41480
41481 #define NUM_PAGES_TO_ALLOC (PAGE_SIZE/sizeof(struct page *))
41482 #define SMALL_ALLOCATION 4
41483-#define FREE_ALL_PAGES (~0U)
41484+#define FREE_ALL_PAGES (~0UL)
41485 /* times are in msecs */
41486 #define IS_UNDEFINED (0)
41487 #define IS_WC (1<<1)
41488@@ -413,15 +413,14 @@ static void ttm_dma_page_put(struct dma_pool *pool, struct dma_page *d_page)
41489 * @nr_free: If set to true will free all pages in pool
41490 * @gfp: GFP flags.
41491 **/
41492-static unsigned ttm_dma_page_pool_free(struct dma_pool *pool, unsigned nr_free,
41493+static unsigned long ttm_dma_page_pool_free(struct dma_pool *pool, unsigned long nr_free,
41494 gfp_t gfp)
41495 {
41496 unsigned long irq_flags;
41497 struct dma_page *dma_p, *tmp;
41498 struct page **pages_to_free;
41499 struct list_head d_pages;
41500- unsigned freed_pages = 0,
41501- npages_to_free = nr_free;
41502+ unsigned long freed_pages = 0, npages_to_free = nr_free;
41503
41504 if (NUM_PAGES_TO_ALLOC < nr_free)
41505 npages_to_free = NUM_PAGES_TO_ALLOC;
41506@@ -494,7 +493,8 @@ restart:
41507 /* remove range of pages from the pool */
41508 if (freed_pages) {
41509 ttm_pool_update_free_locked(pool, freed_pages);
41510- nr_free -= freed_pages;
41511+ if (likely(nr_free != FREE_ALL_PAGES))
41512+ nr_free -= freed_pages;
41513 }
41514
41515 spin_unlock_irqrestore(&pool->lock, irq_flags);
41516@@ -929,7 +929,7 @@ void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev)
41517 struct dma_page *d_page, *next;
41518 enum pool_type type;
41519 bool is_cached = false;
41520- unsigned count = 0, i, npages = 0;
41521+ unsigned long count = 0, i, npages = 0;
41522 unsigned long irq_flags;
41523
41524 type = ttm_to_type(ttm->page_flags, ttm->caching_state);
41525@@ -1007,7 +1007,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41526 static unsigned start_pool;
41527 unsigned idx = 0;
41528 unsigned pool_offset;
41529- unsigned shrink_pages = sc->nr_to_scan;
41530+ unsigned long shrink_pages = sc->nr_to_scan;
41531 struct device_pools *p;
41532 unsigned long freed = 0;
41533
41534@@ -1020,7 +1020,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41535 goto out;
41536 pool_offset = ++start_pool % _manager->npools;
41537 list_for_each_entry(p, &_manager->pools, pools) {
41538- unsigned nr_free;
41539+ unsigned long nr_free;
41540
41541 if (!p->dev)
41542 continue;
41543@@ -1034,7 +1034,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41544 sc->gfp_mask);
41545 freed += nr_free - shrink_pages;
41546
41547- pr_debug("%s: (%s:%d) Asked to shrink %d, have %d more to go\n",
41548+ pr_debug("%s: (%s:%d) Asked to shrink %lu, have %lu more to go\n",
41549 p->pool->dev_name, p->pool->name, current->pid,
41550 nr_free, shrink_pages);
41551 }
41552diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41553index 8cbcb45..a4d9cf7 100644
41554--- a/drivers/gpu/drm/udl/udl_fb.c
41555+++ b/drivers/gpu/drm/udl/udl_fb.c
41556@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41557 fb_deferred_io_cleanup(info);
41558 kfree(info->fbdefio);
41559 info->fbdefio = NULL;
41560- info->fbops->fb_mmap = udl_fb_mmap;
41561 }
41562
41563 pr_warn("released /dev/fb%d user=%d count=%d\n",
41564diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41565index ef8c500..01030c8 100644
41566--- a/drivers/gpu/drm/via/via_drv.h
41567+++ b/drivers/gpu/drm/via/via_drv.h
41568@@ -53,7 +53,7 @@ typedef struct drm_via_ring_buffer {
41569 typedef uint32_t maskarray_t[5];
41570
41571 typedef struct drm_via_irq {
41572- atomic_t irq_received;
41573+ atomic_unchecked_t irq_received;
41574 uint32_t pending_mask;
41575 uint32_t enable_mask;
41576 wait_queue_head_t irq_queue;
41577@@ -77,7 +77,7 @@ typedef struct drm_via_private {
41578 struct timeval last_vblank;
41579 int last_vblank_valid;
41580 unsigned usec_per_vblank;
41581- atomic_t vbl_received;
41582+ atomic_unchecked_t vbl_received;
41583 drm_via_state_t hc_state;
41584 char pci_buf[VIA_PCI_BUF_SIZE];
41585 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41586diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41587index 1319433..a993b0c 100644
41588--- a/drivers/gpu/drm/via/via_irq.c
41589+++ b/drivers/gpu/drm/via/via_irq.c
41590@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41591 if (crtc != 0)
41592 return 0;
41593
41594- return atomic_read(&dev_priv->vbl_received);
41595+ return atomic_read_unchecked(&dev_priv->vbl_received);
41596 }
41597
41598 irqreturn_t via_driver_irq_handler(int irq, void *arg)
41599@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41600
41601 status = VIA_READ(VIA_REG_INTERRUPT);
41602 if (status & VIA_IRQ_VBLANK_PENDING) {
41603- atomic_inc(&dev_priv->vbl_received);
41604- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41605+ atomic_inc_unchecked(&dev_priv->vbl_received);
41606+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41607 do_gettimeofday(&cur_vblank);
41608 if (dev_priv->last_vblank_valid) {
41609 dev_priv->usec_per_vblank =
41610@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41611 dev_priv->last_vblank = cur_vblank;
41612 dev_priv->last_vblank_valid = 1;
41613 }
41614- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41615+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41616 DRM_DEBUG("US per vblank is: %u\n",
41617 dev_priv->usec_per_vblank);
41618 }
41619@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41620
41621 for (i = 0; i < dev_priv->num_irqs; ++i) {
41622 if (status & cur_irq->pending_mask) {
41623- atomic_inc(&cur_irq->irq_received);
41624+ atomic_inc_unchecked(&cur_irq->irq_received);
41625 wake_up(&cur_irq->irq_queue);
41626 handled = 1;
41627 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41628@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41629 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41630 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41631 masks[irq][4]));
41632- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41633+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41634 } else {
41635 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41636 (((cur_irq_sequence =
41637- atomic_read(&cur_irq->irq_received)) -
41638+ atomic_read_unchecked(&cur_irq->irq_received)) -
41639 *sequence) <= (1 << 23)));
41640 }
41641 *sequence = cur_irq_sequence;
41642@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41643 }
41644
41645 for (i = 0; i < dev_priv->num_irqs; ++i) {
41646- atomic_set(&cur_irq->irq_received, 0);
41647+ atomic_set_unchecked(&cur_irq->irq_received, 0);
41648 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41649 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41650 init_waitqueue_head(&cur_irq->irq_queue);
41651@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41652 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41653 case VIA_IRQ_RELATIVE:
41654 irqwait->request.sequence +=
41655- atomic_read(&cur_irq->irq_received);
41656+ atomic_read_unchecked(&cur_irq->irq_received);
41657 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41658 case VIA_IRQ_ABSOLUTE:
41659 break;
41660diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41661index 4ee799b..69fc0d1 100644
41662--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41663+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41664@@ -446,7 +446,7 @@ struct vmw_private {
41665 * Fencing and IRQs.
41666 */
41667
41668- atomic_t marker_seq;
41669+ atomic_unchecked_t marker_seq;
41670 wait_queue_head_t fence_queue;
41671 wait_queue_head_t fifo_queue;
41672 int fence_queue_waiters; /* Protected by hw_mutex */
41673diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41674index 09e10ae..cb76c60 100644
41675--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41676+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41677@@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41678 (unsigned int) min,
41679 (unsigned int) fifo->capabilities);
41680
41681- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41682+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41683 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41684 vmw_marker_queue_init(&fifo->marker_queue);
41685 return vmw_fifo_send_fence(dev_priv, &dummy);
41686@@ -378,7 +378,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41687 if (reserveable)
41688 iowrite32(bytes, fifo_mem +
41689 SVGA_FIFO_RESERVED);
41690- return fifo_mem + (next_cmd >> 2);
41691+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41692 } else {
41693 need_bounce = true;
41694 }
41695@@ -498,7 +498,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41696
41697 fm = vmw_fifo_reserve(dev_priv, bytes);
41698 if (unlikely(fm == NULL)) {
41699- *seqno = atomic_read(&dev_priv->marker_seq);
41700+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41701 ret = -ENOMEM;
41702 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41703 false, 3*HZ);
41704@@ -506,7 +506,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41705 }
41706
41707 do {
41708- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41709+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41710 } while (*seqno == 0);
41711
41712 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41713diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41714index 170b61b..fec7348 100644
41715--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41716+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41717@@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41718 }
41719
41720 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41721- vmw_gmrid_man_init,
41722- vmw_gmrid_man_takedown,
41723- vmw_gmrid_man_get_node,
41724- vmw_gmrid_man_put_node,
41725- vmw_gmrid_man_debug
41726+ .init = vmw_gmrid_man_init,
41727+ .takedown = vmw_gmrid_man_takedown,
41728+ .get_node = vmw_gmrid_man_get_node,
41729+ .put_node = vmw_gmrid_man_put_node,
41730+ .debug = vmw_gmrid_man_debug
41731 };
41732diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41733index 37881ec..319065d 100644
41734--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41735+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41736@@ -235,7 +235,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41737 int ret;
41738
41739 num_clips = arg->num_clips;
41740- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41741+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41742
41743 if (unlikely(num_clips == 0))
41744 return 0;
41745@@ -318,7 +318,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41746 int ret;
41747
41748 num_clips = arg->num_clips;
41749- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41750+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41751
41752 if (unlikely(num_clips == 0))
41753 return 0;
41754diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41755index 0c42376..6febe77 100644
41756--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41757+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41758@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41759 * emitted. Then the fence is stale and signaled.
41760 */
41761
41762- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41763+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41764 > VMW_FENCE_WRAP);
41765
41766 return ret;
41767@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41768
41769 if (fifo_idle)
41770 down_read(&fifo_state->rwsem);
41771- signal_seq = atomic_read(&dev_priv->marker_seq);
41772+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41773 ret = 0;
41774
41775 for (;;) {
41776diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41777index efd1ffd..0ae13ca 100644
41778--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41779+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41780@@ -135,7 +135,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41781 while (!vmw_lag_lt(queue, us)) {
41782 spin_lock(&queue->lock);
41783 if (list_empty(&queue->head))
41784- seqno = atomic_read(&dev_priv->marker_seq);
41785+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41786 else {
41787 marker = list_first_entry(&queue->head,
41788 struct vmw_marker, head);
41789diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41790index 37ac7b5..d52a5c9 100644
41791--- a/drivers/gpu/vga/vga_switcheroo.c
41792+++ b/drivers/gpu/vga/vga_switcheroo.c
41793@@ -644,7 +644,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41794
41795 /* this version is for the case where the power switch is separate
41796 to the device being powered down. */
41797-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41798+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41799 {
41800 /* copy over all the bus versions */
41801 if (dev->bus && dev->bus->pm) {
41802@@ -695,7 +695,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41803 return ret;
41804 }
41805
41806-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41807+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41808 {
41809 /* copy over all the bus versions */
41810 if (dev->bus && dev->bus->pm) {
41811diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41812index 3402033..50b562c 100644
41813--- a/drivers/hid/hid-core.c
41814+++ b/drivers/hid/hid-core.c
41815@@ -2506,7 +2506,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41816
41817 int hid_add_device(struct hid_device *hdev)
41818 {
41819- static atomic_t id = ATOMIC_INIT(0);
41820+ static atomic_unchecked_t id = ATOMIC_INIT(0);
41821 int ret;
41822
41823 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41824@@ -2548,7 +2548,7 @@ int hid_add_device(struct hid_device *hdev)
41825 /* XXX hack, any other cleaner solution after the driver core
41826 * is converted to allow more than 20 bytes as the device name? */
41827 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41828- hdev->vendor, hdev->product, atomic_inc_return(&id));
41829+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41830
41831 hid_debug_register(hdev, dev_name(&hdev->dev));
41832 ret = device_add(&hdev->dev);
41833diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c
41834index 71f5692..147d3da 100644
41835--- a/drivers/hid/hid-logitech-dj.c
41836+++ b/drivers/hid/hid-logitech-dj.c
41837@@ -658,6 +658,12 @@ static int logi_dj_raw_event(struct hid_device *hdev,
41838 * device (via hid_input_report() ) and return 1 so hid-core does not do
41839 * anything else with it.
41840 */
41841+ if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) ||
41842+ (dj_report->device_index > DJ_DEVICE_INDEX_MAX)) {
41843+ dev_err(&hdev->dev, "%s: invalid device index:%d\n",
41844+ __func__, dj_report->device_index);
41845+ return false;
41846+ }
41847
41848 /* case 1) */
41849 if (data[0] != REPORT_ID_DJ_SHORT)
41850diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
41851index bc4269e..b6e6102 100644
41852--- a/drivers/hid/hid-sony.c
41853+++ b/drivers/hid/hid-sony.c
41854@@ -798,6 +798,12 @@ union sixaxis_output_report_01 {
41855 __u8 buf[36];
41856 };
41857
41858+#define DS4_REPORT_0x02_SIZE 37
41859+#define DS4_REPORT_0x05_SIZE 32
41860+#define DS4_REPORT_0x11_SIZE 78
41861+#define DS4_REPORT_0x81_SIZE 7
41862+#define SIXAXIS_REPORT_0xF2_SIZE 18
41863+
41864 static spinlock_t sony_dev_list_lock;
41865 static LIST_HEAD(sony_device_list);
41866 static DEFINE_IDA(sony_device_id_allocator);
41867@@ -811,6 +817,7 @@ struct sony_sc {
41868 struct work_struct state_worker;
41869 struct power_supply battery;
41870 int device_id;
41871+ __u8 *output_report_dmabuf;
41872
41873 #ifdef CONFIG_SONY_FF
41874 __u8 left;
41875@@ -1142,9 +1149,20 @@ static int sixaxis_set_operational_usb(struct hid_device *hdev)
41876
41877 static int sixaxis_set_operational_bt(struct hid_device *hdev)
41878 {
41879- unsigned char buf[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 };
41880- return hid_hw_raw_request(hdev, buf[0], buf, sizeof(buf),
41881+ static const __u8 report[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 };
41882+ __u8 *buf;
41883+ int ret;
41884+
41885+ buf = kmemdup(report, sizeof(report), GFP_KERNEL);
41886+ if (!buf)
41887+ return -ENOMEM;
41888+
41889+ ret = hid_hw_raw_request(hdev, buf[0], buf, sizeof(report),
41890 HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
41891+
41892+ kfree(buf);
41893+
41894+ return ret;
41895 }
41896
41897 /*
41898@@ -1153,10 +1171,19 @@ static int sixaxis_set_operational_bt(struct hid_device *hdev)
41899 */
41900 static int dualshock4_set_operational_bt(struct hid_device *hdev)
41901 {
41902- __u8 buf[37] = { 0 };
41903+ __u8 *buf;
41904+ int ret;
41905
41906- return hid_hw_raw_request(hdev, 0x02, buf, sizeof(buf),
41907+ buf = kmalloc(DS4_REPORT_0x02_SIZE, GFP_KERNEL);
41908+ if (!buf)
41909+ return -ENOMEM;
41910+
41911+ ret = hid_hw_raw_request(hdev, 0x02, buf, DS4_REPORT_0x02_SIZE,
41912 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
41913+
41914+ kfree(buf);
41915+
41916+ return ret;
41917 }
41918
41919 static void sixaxis_set_leds_from_id(int id, __u8 values[MAX_LEDS])
41920@@ -1471,9 +1498,7 @@ error_leds:
41921
41922 static void sixaxis_state_worker(struct work_struct *work)
41923 {
41924- struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
41925- int n;
41926- union sixaxis_output_report_01 report = {
41927+ static const union sixaxis_output_report_01 default_report = {
41928 .buf = {
41929 0x01,
41930 0x00, 0xff, 0x00, 0xff, 0x00,
41931@@ -1485,20 +1510,27 @@ static void sixaxis_state_worker(struct work_struct *work)
41932 0x00, 0x00, 0x00, 0x00, 0x00
41933 }
41934 };
41935+ struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
41936+ struct sixaxis_output_report *report =
41937+ (struct sixaxis_output_report *)sc->output_report_dmabuf;
41938+ int n;
41939+
41940+ /* Initialize the report with default values */
41941+ memcpy(report, &default_report, sizeof(struct sixaxis_output_report));
41942
41943 #ifdef CONFIG_SONY_FF
41944- report.data.rumble.right_motor_on = sc->right ? 1 : 0;
41945- report.data.rumble.left_motor_force = sc->left;
41946+ report->rumble.right_motor_on = sc->right ? 1 : 0;
41947+ report->rumble.left_motor_force = sc->left;
41948 #endif
41949
41950- report.data.leds_bitmap |= sc->led_state[0] << 1;
41951- report.data.leds_bitmap |= sc->led_state[1] << 2;
41952- report.data.leds_bitmap |= sc->led_state[2] << 3;
41953- report.data.leds_bitmap |= sc->led_state[3] << 4;
41954+ report->leds_bitmap |= sc->led_state[0] << 1;
41955+ report->leds_bitmap |= sc->led_state[1] << 2;
41956+ report->leds_bitmap |= sc->led_state[2] << 3;
41957+ report->leds_bitmap |= sc->led_state[3] << 4;
41958
41959 /* Set flag for all leds off, required for 3rd party INTEC controller */
41960- if ((report.data.leds_bitmap & 0x1E) == 0)
41961- report.data.leds_bitmap |= 0x20;
41962+ if ((report->leds_bitmap & 0x1E) == 0)
41963+ report->leds_bitmap |= 0x20;
41964
41965 /*
41966 * The LEDs in the report are indexed in reverse order to their
41967@@ -1511,28 +1543,30 @@ static void sixaxis_state_worker(struct work_struct *work)
41968 */
41969 for (n = 0; n < 4; n++) {
41970 if (sc->led_delay_on[n] || sc->led_delay_off[n]) {
41971- report.data.led[3 - n].duty_off = sc->led_delay_off[n];
41972- report.data.led[3 - n].duty_on = sc->led_delay_on[n];
41973+ report->led[3 - n].duty_off = sc->led_delay_off[n];
41974+ report->led[3 - n].duty_on = sc->led_delay_on[n];
41975 }
41976 }
41977
41978- hid_hw_raw_request(sc->hdev, report.data.report_id, report.buf,
41979- sizeof(report), HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
41980+ hid_hw_raw_request(sc->hdev, report->report_id, (__u8 *)report,
41981+ sizeof(struct sixaxis_output_report),
41982+ HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
41983 }
41984
41985 static void dualshock4_state_worker(struct work_struct *work)
41986 {
41987 struct sony_sc *sc = container_of(work, struct sony_sc, state_worker);
41988 struct hid_device *hdev = sc->hdev;
41989+ __u8 *buf = sc->output_report_dmabuf;
41990 int offset;
41991
41992- __u8 buf[78] = { 0 };
41993-
41994 if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) {
41995+ memset(buf, 0, DS4_REPORT_0x05_SIZE);
41996 buf[0] = 0x05;
41997 buf[1] = 0xFF;
41998 offset = 4;
41999 } else {
42000+ memset(buf, 0, DS4_REPORT_0x11_SIZE);
42001 buf[0] = 0x11;
42002 buf[1] = 0xB0;
42003 buf[3] = 0x0F;
42004@@ -1560,12 +1594,33 @@ static void dualshock4_state_worker(struct work_struct *work)
42005 buf[offset++] = sc->led_delay_off[3];
42006
42007 if (sc->quirks & DUALSHOCK4_CONTROLLER_USB)
42008- hid_hw_output_report(hdev, buf, 32);
42009+ hid_hw_output_report(hdev, buf, DS4_REPORT_0x05_SIZE);
42010 else
42011- hid_hw_raw_request(hdev, 0x11, buf, 78,
42012+ hid_hw_raw_request(hdev, 0x11, buf, DS4_REPORT_0x11_SIZE,
42013 HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
42014 }
42015
42016+static int sony_allocate_output_report(struct sony_sc *sc)
42017+{
42018+ if (sc->quirks & SIXAXIS_CONTROLLER)
42019+ sc->output_report_dmabuf =
42020+ kmalloc(sizeof(union sixaxis_output_report_01),
42021+ GFP_KERNEL);
42022+ else if (sc->quirks & DUALSHOCK4_CONTROLLER_BT)
42023+ sc->output_report_dmabuf = kmalloc(DS4_REPORT_0x11_SIZE,
42024+ GFP_KERNEL);
42025+ else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB)
42026+ sc->output_report_dmabuf = kmalloc(DS4_REPORT_0x05_SIZE,
42027+ GFP_KERNEL);
42028+ else
42029+ return 0;
42030+
42031+ if (!sc->output_report_dmabuf)
42032+ return -ENOMEM;
42033+
42034+ return 0;
42035+}
42036+
42037 #ifdef CONFIG_SONY_FF
42038 static int sony_play_effect(struct input_dev *dev, void *data,
42039 struct ff_effect *effect)
42040@@ -1754,6 +1809,7 @@ static int sony_get_bt_devaddr(struct sony_sc *sc)
42041
42042 static int sony_check_add(struct sony_sc *sc)
42043 {
42044+ __u8 *buf = NULL;
42045 int n, ret;
42046
42047 if ((sc->quirks & DUALSHOCK4_CONTROLLER_BT) ||
42048@@ -1769,36 +1825,44 @@ static int sony_check_add(struct sony_sc *sc)
42049 return 0;
42050 }
42051 } else if (sc->quirks & DUALSHOCK4_CONTROLLER_USB) {
42052- __u8 buf[7];
42053+ buf = kmalloc(DS4_REPORT_0x81_SIZE, GFP_KERNEL);
42054+ if (!buf)
42055+ return -ENOMEM;
42056
42057 /*
42058 * The MAC address of a DS4 controller connected via USB can be
42059 * retrieved with feature report 0x81. The address begins at
42060 * offset 1.
42061 */
42062- ret = hid_hw_raw_request(sc->hdev, 0x81, buf, sizeof(buf),
42063- HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
42064+ ret = hid_hw_raw_request(sc->hdev, 0x81, buf,
42065+ DS4_REPORT_0x81_SIZE, HID_FEATURE_REPORT,
42066+ HID_REQ_GET_REPORT);
42067
42068- if (ret != 7) {
42069+ if (ret != DS4_REPORT_0x81_SIZE) {
42070 hid_err(sc->hdev, "failed to retrieve feature report 0x81 with the DualShock 4 MAC address\n");
42071- return ret < 0 ? ret : -EINVAL;
42072+ ret = ret < 0 ? ret : -EINVAL;
42073+ goto out_free;
42074 }
42075
42076 memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address));
42077 } else if (sc->quirks & SIXAXIS_CONTROLLER_USB) {
42078- __u8 buf[18];
42079+ buf = kmalloc(SIXAXIS_REPORT_0xF2_SIZE, GFP_KERNEL);
42080+ if (!buf)
42081+ return -ENOMEM;
42082
42083 /*
42084 * The MAC address of a Sixaxis controller connected via USB can
42085 * be retrieved with feature report 0xf2. The address begins at
42086 * offset 4.
42087 */
42088- ret = hid_hw_raw_request(sc->hdev, 0xf2, buf, sizeof(buf),
42089- HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
42090+ ret = hid_hw_raw_request(sc->hdev, 0xf2, buf,
42091+ SIXAXIS_REPORT_0xF2_SIZE, HID_FEATURE_REPORT,
42092+ HID_REQ_GET_REPORT);
42093
42094- if (ret != 18) {
42095+ if (ret != SIXAXIS_REPORT_0xF2_SIZE) {
42096 hid_err(sc->hdev, "failed to retrieve feature report 0xf2 with the Sixaxis MAC address\n");
42097- return ret < 0 ? ret : -EINVAL;
42098+ ret = ret < 0 ? ret : -EINVAL;
42099+ goto out_free;
42100 }
42101
42102 /*
42103@@ -1811,7 +1875,13 @@ static int sony_check_add(struct sony_sc *sc)
42104 return 0;
42105 }
42106
42107- return sony_check_add_dev_list(sc);
42108+ ret = sony_check_add_dev_list(sc);
42109+
42110+out_free:
42111+
42112+ kfree(buf);
42113+
42114+ return ret;
42115 }
42116
42117 static int sony_set_device_id(struct sony_sc *sc)
42118@@ -1895,6 +1965,12 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
42119 return ret;
42120 }
42121
42122+ ret = sony_allocate_output_report(sc);
42123+ if (ret < 0) {
42124+ hid_err(hdev, "failed to allocate the output report buffer\n");
42125+ goto err_stop;
42126+ }
42127+
42128 ret = sony_set_device_id(sc);
42129 if (ret < 0) {
42130 hid_err(hdev, "failed to allocate the device id\n");
42131@@ -1984,6 +2060,7 @@ err_stop:
42132 if (sc->quirks & SONY_BATTERY_SUPPORT)
42133 sony_battery_remove(sc);
42134 sony_cancel_work_sync(sc);
42135+ kfree(sc->output_report_dmabuf);
42136 sony_remove_dev_list(sc);
42137 sony_release_device_id(sc);
42138 hid_hw_stop(hdev);
42139@@ -2004,6 +2081,8 @@ static void sony_remove(struct hid_device *hdev)
42140
42141 sony_cancel_work_sync(sc);
42142
42143+ kfree(sc->output_report_dmabuf);
42144+
42145 sony_remove_dev_list(sc);
42146
42147 sony_release_device_id(sc);
42148diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
42149index c13fb5b..55a3802 100644
42150--- a/drivers/hid/hid-wiimote-debug.c
42151+++ b/drivers/hid/hid-wiimote-debug.c
42152@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
42153 else if (size == 0)
42154 return -EIO;
42155
42156- if (copy_to_user(u, buf, size))
42157+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
42158 return -EFAULT;
42159
42160 *off += size;
42161diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
42162index 433f72a..2926005 100644
42163--- a/drivers/hv/channel.c
42164+++ b/drivers/hv/channel.c
42165@@ -366,8 +366,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
42166 unsigned long flags;
42167 int ret = 0;
42168
42169- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
42170- atomic_inc(&vmbus_connection.next_gpadl_handle);
42171+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
42172+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
42173
42174 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
42175 if (ret)
42176diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
42177index 3e4235c..877d0e5 100644
42178--- a/drivers/hv/hv.c
42179+++ b/drivers/hv/hv.c
42180@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
42181 u64 output_address = (output) ? virt_to_phys(output) : 0;
42182 u32 output_address_hi = output_address >> 32;
42183 u32 output_address_lo = output_address & 0xFFFFFFFF;
42184- void *hypercall_page = hv_context.hypercall_page;
42185+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
42186
42187 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
42188 "=a"(hv_status_lo) : "d" (control_hi),
42189@@ -156,7 +156,7 @@ int hv_init(void)
42190 /* See if the hypercall page is already set */
42191 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
42192
42193- virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
42194+ virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
42195
42196 if (!virtaddr)
42197 goto cleanup;
42198diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
42199index 5e90c5d..d8fcefb 100644
42200--- a/drivers/hv/hv_balloon.c
42201+++ b/drivers/hv/hv_balloon.c
42202@@ -470,7 +470,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
42203
42204 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
42205 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
42206-static atomic_t trans_id = ATOMIC_INIT(0);
42207+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
42208
42209 static int dm_ring_size = (5 * PAGE_SIZE);
42210
42211@@ -893,7 +893,7 @@ static void hot_add_req(struct work_struct *dummy)
42212 pr_info("Memory hot add failed\n");
42213
42214 dm->state = DM_INITIALIZED;
42215- resp.hdr.trans_id = atomic_inc_return(&trans_id);
42216+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42217 vmbus_sendpacket(dm->dev->channel, &resp,
42218 sizeof(struct dm_hot_add_response),
42219 (unsigned long)NULL,
42220@@ -973,7 +973,7 @@ static void post_status(struct hv_dynmem_device *dm)
42221 memset(&status, 0, sizeof(struct dm_status));
42222 status.hdr.type = DM_STATUS_REPORT;
42223 status.hdr.size = sizeof(struct dm_status);
42224- status.hdr.trans_id = atomic_inc_return(&trans_id);
42225+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42226
42227 /*
42228 * The host expects the guest to report free memory.
42229@@ -993,7 +993,7 @@ static void post_status(struct hv_dynmem_device *dm)
42230 * send the status. This can happen if we were interrupted
42231 * after we picked our transaction ID.
42232 */
42233- if (status.hdr.trans_id != atomic_read(&trans_id))
42234+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
42235 return;
42236
42237 /*
42238@@ -1129,7 +1129,7 @@ static void balloon_up(struct work_struct *dummy)
42239 */
42240
42241 do {
42242- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
42243+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42244 ret = vmbus_sendpacket(dm_device.dev->channel,
42245 bl_resp,
42246 bl_resp->hdr.size,
42247@@ -1175,7 +1175,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
42248
42249 memset(&resp, 0, sizeof(struct dm_unballoon_response));
42250 resp.hdr.type = DM_UNBALLOON_RESPONSE;
42251- resp.hdr.trans_id = atomic_inc_return(&trans_id);
42252+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42253 resp.hdr.size = sizeof(struct dm_unballoon_response);
42254
42255 vmbus_sendpacket(dm_device.dev->channel, &resp,
42256@@ -1239,7 +1239,7 @@ static void version_resp(struct hv_dynmem_device *dm,
42257 memset(&version_req, 0, sizeof(struct dm_version_request));
42258 version_req.hdr.type = DM_VERSION_REQUEST;
42259 version_req.hdr.size = sizeof(struct dm_version_request);
42260- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42261+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42262 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
42263 version_req.is_last_attempt = 1;
42264
42265@@ -1409,7 +1409,7 @@ static int balloon_probe(struct hv_device *dev,
42266 memset(&version_req, 0, sizeof(struct dm_version_request));
42267 version_req.hdr.type = DM_VERSION_REQUEST;
42268 version_req.hdr.size = sizeof(struct dm_version_request);
42269- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42270+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42271 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
42272 version_req.is_last_attempt = 0;
42273
42274@@ -1440,7 +1440,7 @@ static int balloon_probe(struct hv_device *dev,
42275 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
42276 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
42277 cap_msg.hdr.size = sizeof(struct dm_capabilities);
42278- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
42279+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42280
42281 cap_msg.caps.cap_bits.balloon = 1;
42282 cap_msg.caps.cap_bits.hot_add = 1;
42283diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
42284index c386d8d..d6004c4 100644
42285--- a/drivers/hv/hyperv_vmbus.h
42286+++ b/drivers/hv/hyperv_vmbus.h
42287@@ -611,7 +611,7 @@ enum vmbus_connect_state {
42288 struct vmbus_connection {
42289 enum vmbus_connect_state conn_state;
42290
42291- atomic_t next_gpadl_handle;
42292+ atomic_unchecked_t next_gpadl_handle;
42293
42294 /*
42295 * Represents channel interrupts. Each bit position represents a
42296diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
42297index 4d6b269..2e23b86 100644
42298--- a/drivers/hv/vmbus_drv.c
42299+++ b/drivers/hv/vmbus_drv.c
42300@@ -807,10 +807,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
42301 {
42302 int ret = 0;
42303
42304- static atomic_t device_num = ATOMIC_INIT(0);
42305+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
42306
42307 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
42308- atomic_inc_return(&device_num));
42309+ atomic_inc_return_unchecked(&device_num));
42310
42311 child_device_obj->device.bus = &hv_bus;
42312 child_device_obj->device.parent = &hv_acpi_dev->dev;
42313diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
42314index 579bdf9..75118b5 100644
42315--- a/drivers/hwmon/acpi_power_meter.c
42316+++ b/drivers/hwmon/acpi_power_meter.c
42317@@ -116,7 +116,7 @@ struct sensor_template {
42318 struct device_attribute *devattr,
42319 const char *buf, size_t count);
42320 int index;
42321-};
42322+} __do_const;
42323
42324 /* Averaging interval */
42325 static int update_avg_interval(struct acpi_power_meter_resource *resource)
42326@@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
42327 struct sensor_template *attrs)
42328 {
42329 struct device *dev = &resource->acpi_dev->dev;
42330- struct sensor_device_attribute *sensors =
42331+ sensor_device_attribute_no_const *sensors =
42332 &resource->sensors[resource->num_sensors];
42333 int res = 0;
42334
42335diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
42336index 3288f13..71cfb4e 100644
42337--- a/drivers/hwmon/applesmc.c
42338+++ b/drivers/hwmon/applesmc.c
42339@@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
42340 {
42341 struct applesmc_node_group *grp;
42342 struct applesmc_dev_attr *node;
42343- struct attribute *attr;
42344+ attribute_no_const *attr;
42345 int ret, i;
42346
42347 for (grp = groups; grp->format; grp++) {
42348diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
42349index cccef87..06ce8ec 100644
42350--- a/drivers/hwmon/asus_atk0110.c
42351+++ b/drivers/hwmon/asus_atk0110.c
42352@@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
42353 struct atk_sensor_data {
42354 struct list_head list;
42355 struct atk_data *data;
42356- struct device_attribute label_attr;
42357- struct device_attribute input_attr;
42358- struct device_attribute limit1_attr;
42359- struct device_attribute limit2_attr;
42360+ device_attribute_no_const label_attr;
42361+ device_attribute_no_const input_attr;
42362+ device_attribute_no_const limit1_attr;
42363+ device_attribute_no_const limit2_attr;
42364 char label_attr_name[ATTR_NAME_SIZE];
42365 char input_attr_name[ATTR_NAME_SIZE];
42366 char limit1_attr_name[ATTR_NAME_SIZE];
42367@@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
42368 static struct device_attribute atk_name_attr =
42369 __ATTR(name, 0444, atk_name_show, NULL);
42370
42371-static void atk_init_attribute(struct device_attribute *attr, char *name,
42372+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
42373 sysfs_show_func show)
42374 {
42375 sysfs_attr_init(&attr->attr);
42376diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
42377index d76f0b7..55ae976 100644
42378--- a/drivers/hwmon/coretemp.c
42379+++ b/drivers/hwmon/coretemp.c
42380@@ -784,7 +784,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
42381 return NOTIFY_OK;
42382 }
42383
42384-static struct notifier_block coretemp_cpu_notifier __refdata = {
42385+static struct notifier_block coretemp_cpu_notifier = {
42386 .notifier_call = coretemp_cpu_callback,
42387 };
42388
42389diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
42390index 7a8a6fb..015c1fd 100644
42391--- a/drivers/hwmon/ibmaem.c
42392+++ b/drivers/hwmon/ibmaem.c
42393@@ -924,7 +924,7 @@ static int aem_register_sensors(struct aem_data *data,
42394 struct aem_rw_sensor_template *rw)
42395 {
42396 struct device *dev = &data->pdev->dev;
42397- struct sensor_device_attribute *sensors = data->sensors;
42398+ sensor_device_attribute_no_const *sensors = data->sensors;
42399 int err;
42400
42401 /* Set up read-only sensors */
42402diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
42403index 14c82da..09b25d7 100644
42404--- a/drivers/hwmon/iio_hwmon.c
42405+++ b/drivers/hwmon/iio_hwmon.c
42406@@ -61,7 +61,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
42407 {
42408 struct device *dev = &pdev->dev;
42409 struct iio_hwmon_state *st;
42410- struct sensor_device_attribute *a;
42411+ sensor_device_attribute_no_const *a;
42412 int ret, i;
42413 int in_i = 1, temp_i = 1, curr_i = 1;
42414 enum iio_chan_type type;
42415diff --git a/drivers/hwmon/nct6683.c b/drivers/hwmon/nct6683.c
42416index 7710f46..427a28d 100644
42417--- a/drivers/hwmon/nct6683.c
42418+++ b/drivers/hwmon/nct6683.c
42419@@ -397,11 +397,11 @@ static struct attribute_group *
42420 nct6683_create_attr_group(struct device *dev, struct sensor_template_group *tg,
42421 int repeat)
42422 {
42423- struct sensor_device_attribute_2 *a2;
42424- struct sensor_device_attribute *a;
42425+ sensor_device_attribute_2_no_const *a2;
42426+ sensor_device_attribute_no_const *a;
42427 struct sensor_device_template **t;
42428 struct sensor_device_attr_u *su;
42429- struct attribute_group *group;
42430+ attribute_group_no_const *group;
42431 struct attribute **attrs;
42432 int i, j, count;
42433
42434diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
42435index 504cbdd..35d6f25 100644
42436--- a/drivers/hwmon/nct6775.c
42437+++ b/drivers/hwmon/nct6775.c
42438@@ -943,10 +943,10 @@ static struct attribute_group *
42439 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
42440 int repeat)
42441 {
42442- struct attribute_group *group;
42443+ attribute_group_no_const *group;
42444 struct sensor_device_attr_u *su;
42445- struct sensor_device_attribute *a;
42446- struct sensor_device_attribute_2 *a2;
42447+ sensor_device_attribute_no_const *a;
42448+ sensor_device_attribute_2_no_const *a2;
42449 struct attribute **attrs;
42450 struct sensor_device_template **t;
42451 int i, count;
42452diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
42453index 291d11f..3f0dbbd 100644
42454--- a/drivers/hwmon/pmbus/pmbus_core.c
42455+++ b/drivers/hwmon/pmbus/pmbus_core.c
42456@@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
42457 return 0;
42458 }
42459
42460-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42461+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
42462 const char *name,
42463 umode_t mode,
42464 ssize_t (*show)(struct device *dev,
42465@@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42466 dev_attr->store = store;
42467 }
42468
42469-static void pmbus_attr_init(struct sensor_device_attribute *a,
42470+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
42471 const char *name,
42472 umode_t mode,
42473 ssize_t (*show)(struct device *dev,
42474@@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
42475 u16 reg, u8 mask)
42476 {
42477 struct pmbus_boolean *boolean;
42478- struct sensor_device_attribute *a;
42479+ sensor_device_attribute_no_const *a;
42480
42481 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
42482 if (!boolean)
42483@@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
42484 bool update, bool readonly)
42485 {
42486 struct pmbus_sensor *sensor;
42487- struct device_attribute *a;
42488+ device_attribute_no_const *a;
42489
42490 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
42491 if (!sensor)
42492@@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
42493 const char *lstring, int index)
42494 {
42495 struct pmbus_label *label;
42496- struct device_attribute *a;
42497+ device_attribute_no_const *a;
42498
42499 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
42500 if (!label)
42501diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
42502index 97cd45a..ac54d8b 100644
42503--- a/drivers/hwmon/sht15.c
42504+++ b/drivers/hwmon/sht15.c
42505@@ -169,7 +169,7 @@ struct sht15_data {
42506 int supply_uv;
42507 bool supply_uv_valid;
42508 struct work_struct update_supply_work;
42509- atomic_t interrupt_handled;
42510+ atomic_unchecked_t interrupt_handled;
42511 };
42512
42513 /**
42514@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
42515 ret = gpio_direction_input(data->pdata->gpio_data);
42516 if (ret)
42517 return ret;
42518- atomic_set(&data->interrupt_handled, 0);
42519+ atomic_set_unchecked(&data->interrupt_handled, 0);
42520
42521 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42522 if (gpio_get_value(data->pdata->gpio_data) == 0) {
42523 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
42524 /* Only relevant if the interrupt hasn't occurred. */
42525- if (!atomic_read(&data->interrupt_handled))
42526+ if (!atomic_read_unchecked(&data->interrupt_handled))
42527 schedule_work(&data->read_work);
42528 }
42529 ret = wait_event_timeout(data->wait_queue,
42530@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
42531
42532 /* First disable the interrupt */
42533 disable_irq_nosync(irq);
42534- atomic_inc(&data->interrupt_handled);
42535+ atomic_inc_unchecked(&data->interrupt_handled);
42536 /* Then schedule a reading work struct */
42537 if (data->state != SHT15_READING_NOTHING)
42538 schedule_work(&data->read_work);
42539@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
42540 * If not, then start the interrupt again - care here as could
42541 * have gone low in meantime so verify it hasn't!
42542 */
42543- atomic_set(&data->interrupt_handled, 0);
42544+ atomic_set_unchecked(&data->interrupt_handled, 0);
42545 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42546 /* If still not occurred or another handler was scheduled */
42547 if (gpio_get_value(data->pdata->gpio_data)
42548- || atomic_read(&data->interrupt_handled))
42549+ || atomic_read_unchecked(&data->interrupt_handled))
42550 return;
42551 }
42552
42553diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
42554index 8df43c5..b07b91d 100644
42555--- a/drivers/hwmon/via-cputemp.c
42556+++ b/drivers/hwmon/via-cputemp.c
42557@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
42558 return NOTIFY_OK;
42559 }
42560
42561-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
42562+static struct notifier_block via_cputemp_cpu_notifier = {
42563 .notifier_call = via_cputemp_cpu_callback,
42564 };
42565
42566diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
42567index 65e3240..e6c511d 100644
42568--- a/drivers/i2c/busses/i2c-amd756-s4882.c
42569+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
42570@@ -39,7 +39,7 @@
42571 extern struct i2c_adapter amd756_smbus;
42572
42573 static struct i2c_adapter *s4882_adapter;
42574-static struct i2c_algorithm *s4882_algo;
42575+static i2c_algorithm_no_const *s4882_algo;
42576
42577 /* Wrapper access functions for multiplexed SMBus */
42578 static DEFINE_MUTEX(amd756_lock);
42579diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
42580index b19a310..d6eece0 100644
42581--- a/drivers/i2c/busses/i2c-diolan-u2c.c
42582+++ b/drivers/i2c/busses/i2c-diolan-u2c.c
42583@@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
42584 /* usb layer */
42585
42586 /* Send command to device, and get response. */
42587-static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42588+static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42589 {
42590 int ret = 0;
42591 int actual;
42592diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
42593index 88eda09..cf40434 100644
42594--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
42595+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
42596@@ -37,7 +37,7 @@
42597 extern struct i2c_adapter *nforce2_smbus;
42598
42599 static struct i2c_adapter *s4985_adapter;
42600-static struct i2c_algorithm *s4985_algo;
42601+static i2c_algorithm_no_const *s4985_algo;
42602
42603 /* Wrapper access functions for multiplexed SMBus */
42604 static DEFINE_MUTEX(nforce2_lock);
42605diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
42606index 71c7a39..71dd3e0 100644
42607--- a/drivers/i2c/i2c-dev.c
42608+++ b/drivers/i2c/i2c-dev.c
42609@@ -272,7 +272,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
42610 break;
42611 }
42612
42613- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
42614+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
42615 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
42616 if (IS_ERR(rdwr_pa[i].buf)) {
42617 res = PTR_ERR(rdwr_pa[i].buf);
42618diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
42619index 0b510ba..4fbb5085 100644
42620--- a/drivers/ide/ide-cd.c
42621+++ b/drivers/ide/ide-cd.c
42622@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
42623 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
42624 if ((unsigned long)buf & alignment
42625 || blk_rq_bytes(rq) & q->dma_pad_mask
42626- || object_is_on_stack(buf))
42627+ || object_starts_on_stack(buf))
42628 drive->dma = 0;
42629 }
42630 }
42631diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
42632index af3e76d..96dfe5e 100644
42633--- a/drivers/iio/industrialio-core.c
42634+++ b/drivers/iio/industrialio-core.c
42635@@ -555,7 +555,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
42636 }
42637
42638 static
42639-int __iio_device_attr_init(struct device_attribute *dev_attr,
42640+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
42641 const char *postfix,
42642 struct iio_chan_spec const *chan,
42643 ssize_t (*readfunc)(struct device *dev,
42644diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
42645index e28a494..f7c2671 100644
42646--- a/drivers/infiniband/core/cm.c
42647+++ b/drivers/infiniband/core/cm.c
42648@@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
42649
42650 struct cm_counter_group {
42651 struct kobject obj;
42652- atomic_long_t counter[CM_ATTR_COUNT];
42653+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
42654 };
42655
42656 struct cm_counter_attribute {
42657@@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
42658 struct ib_mad_send_buf *msg = NULL;
42659 int ret;
42660
42661- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42662+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42663 counter[CM_REQ_COUNTER]);
42664
42665 /* Quick state check to discard duplicate REQs. */
42666@@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
42667 if (!cm_id_priv)
42668 return;
42669
42670- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42671+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42672 counter[CM_REP_COUNTER]);
42673 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
42674 if (ret)
42675@@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
42676 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
42677 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
42678 spin_unlock_irq(&cm_id_priv->lock);
42679- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42680+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42681 counter[CM_RTU_COUNTER]);
42682 goto out;
42683 }
42684@@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
42685 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
42686 dreq_msg->local_comm_id);
42687 if (!cm_id_priv) {
42688- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42689+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42690 counter[CM_DREQ_COUNTER]);
42691 cm_issue_drep(work->port, work->mad_recv_wc);
42692 return -EINVAL;
42693@@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
42694 case IB_CM_MRA_REP_RCVD:
42695 break;
42696 case IB_CM_TIMEWAIT:
42697- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42698+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42699 counter[CM_DREQ_COUNTER]);
42700 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42701 goto unlock;
42702@@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
42703 cm_free_msg(msg);
42704 goto deref;
42705 case IB_CM_DREQ_RCVD:
42706- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42707+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42708 counter[CM_DREQ_COUNTER]);
42709 goto unlock;
42710 default:
42711@@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
42712 ib_modify_mad(cm_id_priv->av.port->mad_agent,
42713 cm_id_priv->msg, timeout)) {
42714 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
42715- atomic_long_inc(&work->port->
42716+ atomic_long_inc_unchecked(&work->port->
42717 counter_group[CM_RECV_DUPLICATES].
42718 counter[CM_MRA_COUNTER]);
42719 goto out;
42720@@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
42721 break;
42722 case IB_CM_MRA_REQ_RCVD:
42723 case IB_CM_MRA_REP_RCVD:
42724- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42725+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42726 counter[CM_MRA_COUNTER]);
42727 /* fall through */
42728 default:
42729@@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
42730 case IB_CM_LAP_IDLE:
42731 break;
42732 case IB_CM_MRA_LAP_SENT:
42733- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42734+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42735 counter[CM_LAP_COUNTER]);
42736 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42737 goto unlock;
42738@@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
42739 cm_free_msg(msg);
42740 goto deref;
42741 case IB_CM_LAP_RCVD:
42742- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42743+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42744 counter[CM_LAP_COUNTER]);
42745 goto unlock;
42746 default:
42747@@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
42748 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
42749 if (cur_cm_id_priv) {
42750 spin_unlock_irq(&cm.lock);
42751- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42752+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42753 counter[CM_SIDR_REQ_COUNTER]);
42754 goto out; /* Duplicate message. */
42755 }
42756@@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
42757 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
42758 msg->retries = 1;
42759
42760- atomic_long_add(1 + msg->retries,
42761+ atomic_long_add_unchecked(1 + msg->retries,
42762 &port->counter_group[CM_XMIT].counter[attr_index]);
42763 if (msg->retries)
42764- atomic_long_add(msg->retries,
42765+ atomic_long_add_unchecked(msg->retries,
42766 &port->counter_group[CM_XMIT_RETRIES].
42767 counter[attr_index]);
42768
42769@@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42770 }
42771
42772 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42773- atomic_long_inc(&port->counter_group[CM_RECV].
42774+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42775 counter[attr_id - CM_ATTR_ID_OFFSET]);
42776
42777 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42778@@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42779 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42780
42781 return sprintf(buf, "%ld\n",
42782- atomic_long_read(&group->counter[cm_attr->index]));
42783+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42784 }
42785
42786 static const struct sysfs_ops cm_counter_ops = {
42787diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42788index 9f5ad7c..588cd84 100644
42789--- a/drivers/infiniband/core/fmr_pool.c
42790+++ b/drivers/infiniband/core/fmr_pool.c
42791@@ -98,8 +98,8 @@ struct ib_fmr_pool {
42792
42793 struct task_struct *thread;
42794
42795- atomic_t req_ser;
42796- atomic_t flush_ser;
42797+ atomic_unchecked_t req_ser;
42798+ atomic_unchecked_t flush_ser;
42799
42800 wait_queue_head_t force_wait;
42801 };
42802@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42803 struct ib_fmr_pool *pool = pool_ptr;
42804
42805 do {
42806- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42807+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42808 ib_fmr_batch_release(pool);
42809
42810- atomic_inc(&pool->flush_ser);
42811+ atomic_inc_unchecked(&pool->flush_ser);
42812 wake_up_interruptible(&pool->force_wait);
42813
42814 if (pool->flush_function)
42815@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42816 }
42817
42818 set_current_state(TASK_INTERRUPTIBLE);
42819- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42820+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42821 !kthread_should_stop())
42822 schedule();
42823 __set_current_state(TASK_RUNNING);
42824@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42825 pool->dirty_watermark = params->dirty_watermark;
42826 pool->dirty_len = 0;
42827 spin_lock_init(&pool->pool_lock);
42828- atomic_set(&pool->req_ser, 0);
42829- atomic_set(&pool->flush_ser, 0);
42830+ atomic_set_unchecked(&pool->req_ser, 0);
42831+ atomic_set_unchecked(&pool->flush_ser, 0);
42832 init_waitqueue_head(&pool->force_wait);
42833
42834 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42835@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42836 }
42837 spin_unlock_irq(&pool->pool_lock);
42838
42839- serial = atomic_inc_return(&pool->req_ser);
42840+ serial = atomic_inc_return_unchecked(&pool->req_ser);
42841 wake_up_process(pool->thread);
42842
42843 if (wait_event_interruptible(pool->force_wait,
42844- atomic_read(&pool->flush_ser) - serial >= 0))
42845+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42846 return -EINTR;
42847
42848 return 0;
42849@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42850 } else {
42851 list_add_tail(&fmr->list, &pool->dirty_list);
42852 if (++pool->dirty_len >= pool->dirty_watermark) {
42853- atomic_inc(&pool->req_ser);
42854+ atomic_inc_unchecked(&pool->req_ser);
42855 wake_up_process(pool->thread);
42856 }
42857 }
42858diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42859index ec7a298..8742e59 100644
42860--- a/drivers/infiniband/hw/cxgb4/mem.c
42861+++ b/drivers/infiniband/hw/cxgb4/mem.c
42862@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42863 int err;
42864 struct fw_ri_tpte tpt;
42865 u32 stag_idx;
42866- static atomic_t key;
42867+ static atomic_unchecked_t key;
42868
42869 if (c4iw_fatal_error(rdev))
42870 return -EIO;
42871@@ -270,7 +270,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42872 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42873 rdev->stats.stag.max = rdev->stats.stag.cur;
42874 mutex_unlock(&rdev->stats.lock);
42875- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42876+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42877 }
42878 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42879 __func__, stag_state, type, pdid, stag_idx);
42880diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42881index 79b3dbc..96e5fcc 100644
42882--- a/drivers/infiniband/hw/ipath/ipath_rc.c
42883+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42884@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42885 struct ib_atomic_eth *ateth;
42886 struct ipath_ack_entry *e;
42887 u64 vaddr;
42888- atomic64_t *maddr;
42889+ atomic64_unchecked_t *maddr;
42890 u64 sdata;
42891 u32 rkey;
42892 u8 next;
42893@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42894 IB_ACCESS_REMOTE_ATOMIC)))
42895 goto nack_acc_unlck;
42896 /* Perform atomic OP and save result. */
42897- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42898+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42899 sdata = be64_to_cpu(ateth->swap_data);
42900 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42901 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42902- (u64) atomic64_add_return(sdata, maddr) - sdata :
42903+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42904 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42905 be64_to_cpu(ateth->compare_data),
42906 sdata);
42907diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42908index 1f95bba..9530f87 100644
42909--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42910+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42911@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42912 unsigned long flags;
42913 struct ib_wc wc;
42914 u64 sdata;
42915- atomic64_t *maddr;
42916+ atomic64_unchecked_t *maddr;
42917 enum ib_wc_status send_status;
42918
42919 /*
42920@@ -382,11 +382,11 @@ again:
42921 IB_ACCESS_REMOTE_ATOMIC)))
42922 goto acc_err;
42923 /* Perform atomic OP and save result. */
42924- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42925+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42926 sdata = wqe->wr.wr.atomic.compare_add;
42927 *(u64 *) sqp->s_sge.sge.vaddr =
42928 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42929- (u64) atomic64_add_return(sdata, maddr) - sdata :
42930+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42931 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42932 sdata, wqe->wr.wr.atomic.swap);
42933 goto send_comp;
42934diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42935index 82a7dd8..8fb6ba6 100644
42936--- a/drivers/infiniband/hw/mlx4/mad.c
42937+++ b/drivers/infiniband/hw/mlx4/mad.c
42938@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42939
42940 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42941 {
42942- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42943+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42944 cpu_to_be64(0xff00000000000000LL);
42945 }
42946
42947diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42948index ed327e6..ca1739e0 100644
42949--- a/drivers/infiniband/hw/mlx4/mcg.c
42950+++ b/drivers/infiniband/hw/mlx4/mcg.c
42951@@ -1041,7 +1041,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42952 {
42953 char name[20];
42954
42955- atomic_set(&ctx->tid, 0);
42956+ atomic_set_unchecked(&ctx->tid, 0);
42957 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42958 ctx->mcg_wq = create_singlethread_workqueue(name);
42959 if (!ctx->mcg_wq)
42960diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42961index 6eb743f..a7b0f6d 100644
42962--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42963+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42964@@ -426,7 +426,7 @@ struct mlx4_ib_demux_ctx {
42965 struct list_head mcg_mgid0_list;
42966 struct workqueue_struct *mcg_wq;
42967 struct mlx4_ib_demux_pv_ctx **tun;
42968- atomic_t tid;
42969+ atomic_unchecked_t tid;
42970 int flushing; /* flushing the work queue */
42971 };
42972
42973diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42974index 9d3e5c1..6f166df 100644
42975--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42976+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42977@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42978 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42979 }
42980
42981-int mthca_QUERY_FW(struct mthca_dev *dev)
42982+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42983 {
42984 struct mthca_mailbox *mailbox;
42985 u32 *outbox;
42986@@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42987 CMD_TIME_CLASS_B);
42988 }
42989
42990-int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42991+int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42992 int num_mtt)
42993 {
42994 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42995@@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42996 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42997 }
42998
42999-int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43000+int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43001 int eq_num)
43002 {
43003 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
43004@@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
43005 CMD_TIME_CLASS_B);
43006 }
43007
43008-int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
43009+int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
43010 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
43011 void *in_mad, void *response_mad)
43012 {
43013diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
43014index ded76c1..0cf0a08 100644
43015--- a/drivers/infiniband/hw/mthca/mthca_main.c
43016+++ b/drivers/infiniband/hw/mthca/mthca_main.c
43017@@ -692,7 +692,7 @@ err_close:
43018 return err;
43019 }
43020
43021-static int mthca_setup_hca(struct mthca_dev *dev)
43022+static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
43023 {
43024 int err;
43025
43026diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
43027index ed9a989..6aa5dc2 100644
43028--- a/drivers/infiniband/hw/mthca/mthca_mr.c
43029+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
43030@@ -81,7 +81,7 @@ struct mthca_mpt_entry {
43031 * through the bitmaps)
43032 */
43033
43034-static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
43035+static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
43036 {
43037 int o;
43038 int m;
43039@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
43040 return key;
43041 }
43042
43043-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
43044+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
43045 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
43046 {
43047 struct mthca_mailbox *mailbox;
43048@@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
43049 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
43050 }
43051
43052-int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
43053+int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
43054 u64 *buffer_list, int buffer_size_shift,
43055 int list_len, u64 iova, u64 total_size,
43056 u32 access, struct mthca_mr *mr)
43057diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
43058index 415f8e1..e34214e 100644
43059--- a/drivers/infiniband/hw/mthca/mthca_provider.c
43060+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
43061@@ -764,7 +764,7 @@ unlock:
43062 return 0;
43063 }
43064
43065-static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
43066+static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
43067 {
43068 struct mthca_dev *dev = to_mdev(ibcq->device);
43069 struct mthca_cq *cq = to_mcq(ibcq);
43070diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
43071index 3b2a6dc..bce26ff 100644
43072--- a/drivers/infiniband/hw/nes/nes.c
43073+++ b/drivers/infiniband/hw/nes/nes.c
43074@@ -97,7 +97,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
43075 LIST_HEAD(nes_adapter_list);
43076 static LIST_HEAD(nes_dev_list);
43077
43078-atomic_t qps_destroyed;
43079+atomic_unchecked_t qps_destroyed;
43080
43081 static unsigned int ee_flsh_adapter;
43082 static unsigned int sysfs_nonidx_addr;
43083@@ -278,7 +278,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
43084 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
43085 struct nes_adapter *nesadapter = nesdev->nesadapter;
43086
43087- atomic_inc(&qps_destroyed);
43088+ atomic_inc_unchecked(&qps_destroyed);
43089
43090 /* Free the control structures */
43091
43092diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
43093index bd9d132..70d84f4 100644
43094--- a/drivers/infiniband/hw/nes/nes.h
43095+++ b/drivers/infiniband/hw/nes/nes.h
43096@@ -180,17 +180,17 @@ extern unsigned int nes_debug_level;
43097 extern unsigned int wqm_quanta;
43098 extern struct list_head nes_adapter_list;
43099
43100-extern atomic_t cm_connects;
43101-extern atomic_t cm_accepts;
43102-extern atomic_t cm_disconnects;
43103-extern atomic_t cm_closes;
43104-extern atomic_t cm_connecteds;
43105-extern atomic_t cm_connect_reqs;
43106-extern atomic_t cm_rejects;
43107-extern atomic_t mod_qp_timouts;
43108-extern atomic_t qps_created;
43109-extern atomic_t qps_destroyed;
43110-extern atomic_t sw_qps_destroyed;
43111+extern atomic_unchecked_t cm_connects;
43112+extern atomic_unchecked_t cm_accepts;
43113+extern atomic_unchecked_t cm_disconnects;
43114+extern atomic_unchecked_t cm_closes;
43115+extern atomic_unchecked_t cm_connecteds;
43116+extern atomic_unchecked_t cm_connect_reqs;
43117+extern atomic_unchecked_t cm_rejects;
43118+extern atomic_unchecked_t mod_qp_timouts;
43119+extern atomic_unchecked_t qps_created;
43120+extern atomic_unchecked_t qps_destroyed;
43121+extern atomic_unchecked_t sw_qps_destroyed;
43122 extern u32 mh_detected;
43123 extern u32 mh_pauses_sent;
43124 extern u32 cm_packets_sent;
43125@@ -199,16 +199,16 @@ extern u32 cm_packets_created;
43126 extern u32 cm_packets_received;
43127 extern u32 cm_packets_dropped;
43128 extern u32 cm_packets_retrans;
43129-extern atomic_t cm_listens_created;
43130-extern atomic_t cm_listens_destroyed;
43131+extern atomic_unchecked_t cm_listens_created;
43132+extern atomic_unchecked_t cm_listens_destroyed;
43133 extern u32 cm_backlog_drops;
43134-extern atomic_t cm_loopbacks;
43135-extern atomic_t cm_nodes_created;
43136-extern atomic_t cm_nodes_destroyed;
43137-extern atomic_t cm_accel_dropped_pkts;
43138-extern atomic_t cm_resets_recvd;
43139-extern atomic_t pau_qps_created;
43140-extern atomic_t pau_qps_destroyed;
43141+extern atomic_unchecked_t cm_loopbacks;
43142+extern atomic_unchecked_t cm_nodes_created;
43143+extern atomic_unchecked_t cm_nodes_destroyed;
43144+extern atomic_unchecked_t cm_accel_dropped_pkts;
43145+extern atomic_unchecked_t cm_resets_recvd;
43146+extern atomic_unchecked_t pau_qps_created;
43147+extern atomic_unchecked_t pau_qps_destroyed;
43148
43149 extern u32 int_mod_timer_init;
43150 extern u32 int_mod_cq_depth_256;
43151diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
43152index 6f09a72..cf4399d 100644
43153--- a/drivers/infiniband/hw/nes/nes_cm.c
43154+++ b/drivers/infiniband/hw/nes/nes_cm.c
43155@@ -69,14 +69,14 @@ u32 cm_packets_dropped;
43156 u32 cm_packets_retrans;
43157 u32 cm_packets_created;
43158 u32 cm_packets_received;
43159-atomic_t cm_listens_created;
43160-atomic_t cm_listens_destroyed;
43161+atomic_unchecked_t cm_listens_created;
43162+atomic_unchecked_t cm_listens_destroyed;
43163 u32 cm_backlog_drops;
43164-atomic_t cm_loopbacks;
43165-atomic_t cm_nodes_created;
43166-atomic_t cm_nodes_destroyed;
43167-atomic_t cm_accel_dropped_pkts;
43168-atomic_t cm_resets_recvd;
43169+atomic_unchecked_t cm_loopbacks;
43170+atomic_unchecked_t cm_nodes_created;
43171+atomic_unchecked_t cm_nodes_destroyed;
43172+atomic_unchecked_t cm_accel_dropped_pkts;
43173+atomic_unchecked_t cm_resets_recvd;
43174
43175 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
43176 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
43177@@ -135,28 +135,28 @@ static void record_ird_ord(struct nes_cm_node *, u16, u16);
43178 /* instance of function pointers for client API */
43179 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
43180 static struct nes_cm_ops nes_cm_api = {
43181- mini_cm_accelerated,
43182- mini_cm_listen,
43183- mini_cm_del_listen,
43184- mini_cm_connect,
43185- mini_cm_close,
43186- mini_cm_accept,
43187- mini_cm_reject,
43188- mini_cm_recv_pkt,
43189- mini_cm_dealloc_core,
43190- mini_cm_get,
43191- mini_cm_set
43192+ .accelerated = mini_cm_accelerated,
43193+ .listen = mini_cm_listen,
43194+ .stop_listener = mini_cm_del_listen,
43195+ .connect = mini_cm_connect,
43196+ .close = mini_cm_close,
43197+ .accept = mini_cm_accept,
43198+ .reject = mini_cm_reject,
43199+ .recv_pkt = mini_cm_recv_pkt,
43200+ .destroy_cm_core = mini_cm_dealloc_core,
43201+ .get = mini_cm_get,
43202+ .set = mini_cm_set
43203 };
43204
43205 static struct nes_cm_core *g_cm_core;
43206
43207-atomic_t cm_connects;
43208-atomic_t cm_accepts;
43209-atomic_t cm_disconnects;
43210-atomic_t cm_closes;
43211-atomic_t cm_connecteds;
43212-atomic_t cm_connect_reqs;
43213-atomic_t cm_rejects;
43214+atomic_unchecked_t cm_connects;
43215+atomic_unchecked_t cm_accepts;
43216+atomic_unchecked_t cm_disconnects;
43217+atomic_unchecked_t cm_closes;
43218+atomic_unchecked_t cm_connecteds;
43219+atomic_unchecked_t cm_connect_reqs;
43220+atomic_unchecked_t cm_rejects;
43221
43222 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
43223 {
43224@@ -1436,7 +1436,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
43225 kfree(listener);
43226 listener = NULL;
43227 ret = 0;
43228- atomic_inc(&cm_listens_destroyed);
43229+ atomic_inc_unchecked(&cm_listens_destroyed);
43230 } else {
43231 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
43232 }
43233@@ -1637,7 +1637,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
43234 cm_node->rem_mac);
43235
43236 add_hte_node(cm_core, cm_node);
43237- atomic_inc(&cm_nodes_created);
43238+ atomic_inc_unchecked(&cm_nodes_created);
43239
43240 return cm_node;
43241 }
43242@@ -1698,7 +1698,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
43243 }
43244
43245 atomic_dec(&cm_core->node_cnt);
43246- atomic_inc(&cm_nodes_destroyed);
43247+ atomic_inc_unchecked(&cm_nodes_destroyed);
43248 nesqp = cm_node->nesqp;
43249 if (nesqp) {
43250 nesqp->cm_node = NULL;
43251@@ -1762,7 +1762,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
43252
43253 static void drop_packet(struct sk_buff *skb)
43254 {
43255- atomic_inc(&cm_accel_dropped_pkts);
43256+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
43257 dev_kfree_skb_any(skb);
43258 }
43259
43260@@ -1825,7 +1825,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
43261 {
43262
43263 int reset = 0; /* whether to send reset in case of err.. */
43264- atomic_inc(&cm_resets_recvd);
43265+ atomic_inc_unchecked(&cm_resets_recvd);
43266 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
43267 " refcnt=%d\n", cm_node, cm_node->state,
43268 atomic_read(&cm_node->ref_count));
43269@@ -2492,7 +2492,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
43270 rem_ref_cm_node(cm_node->cm_core, cm_node);
43271 return NULL;
43272 }
43273- atomic_inc(&cm_loopbacks);
43274+ atomic_inc_unchecked(&cm_loopbacks);
43275 loopbackremotenode->loopbackpartner = cm_node;
43276 loopbackremotenode->tcp_cntxt.rcv_wscale =
43277 NES_CM_DEFAULT_RCV_WND_SCALE;
43278@@ -2773,7 +2773,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
43279 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
43280 else {
43281 rem_ref_cm_node(cm_core, cm_node);
43282- atomic_inc(&cm_accel_dropped_pkts);
43283+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
43284 dev_kfree_skb_any(skb);
43285 }
43286 break;
43287@@ -3081,7 +3081,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43288
43289 if ((cm_id) && (cm_id->event_handler)) {
43290 if (issue_disconn) {
43291- atomic_inc(&cm_disconnects);
43292+ atomic_inc_unchecked(&cm_disconnects);
43293 cm_event.event = IW_CM_EVENT_DISCONNECT;
43294 cm_event.status = disconn_status;
43295 cm_event.local_addr = cm_id->local_addr;
43296@@ -3103,7 +3103,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43297 }
43298
43299 if (issue_close) {
43300- atomic_inc(&cm_closes);
43301+ atomic_inc_unchecked(&cm_closes);
43302 nes_disconnect(nesqp, 1);
43303
43304 cm_id->provider_data = nesqp;
43305@@ -3241,7 +3241,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43306
43307 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
43308 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
43309- atomic_inc(&cm_accepts);
43310+ atomic_inc_unchecked(&cm_accepts);
43311
43312 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
43313 netdev_refcnt_read(nesvnic->netdev));
43314@@ -3439,7 +3439,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
43315 struct nes_cm_core *cm_core;
43316 u8 *start_buff;
43317
43318- atomic_inc(&cm_rejects);
43319+ atomic_inc_unchecked(&cm_rejects);
43320 cm_node = (struct nes_cm_node *)cm_id->provider_data;
43321 loopback = cm_node->loopbackpartner;
43322 cm_core = cm_node->cm_core;
43323@@ -3504,7 +3504,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43324 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
43325 ntohs(laddr->sin_port));
43326
43327- atomic_inc(&cm_connects);
43328+ atomic_inc_unchecked(&cm_connects);
43329 nesqp->active_conn = 1;
43330
43331 /* cache the cm_id in the qp */
43332@@ -3649,7 +3649,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
43333 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
43334 return err;
43335 }
43336- atomic_inc(&cm_listens_created);
43337+ atomic_inc_unchecked(&cm_listens_created);
43338 }
43339
43340 cm_id->add_ref(cm_id);
43341@@ -3756,7 +3756,7 @@ static void cm_event_connected(struct nes_cm_event *event)
43342
43343 if (nesqp->destroyed)
43344 return;
43345- atomic_inc(&cm_connecteds);
43346+ atomic_inc_unchecked(&cm_connecteds);
43347 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
43348 " local port 0x%04X. jiffies = %lu.\n",
43349 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
43350@@ -3941,7 +3941,7 @@ static void cm_event_reset(struct nes_cm_event *event)
43351
43352 cm_id->add_ref(cm_id);
43353 ret = cm_id->event_handler(cm_id, &cm_event);
43354- atomic_inc(&cm_closes);
43355+ atomic_inc_unchecked(&cm_closes);
43356 cm_event.event = IW_CM_EVENT_CLOSE;
43357 cm_event.status = 0;
43358 cm_event.provider_data = cm_id->provider_data;
43359@@ -3981,7 +3981,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
43360 return;
43361 cm_id = cm_node->cm_id;
43362
43363- atomic_inc(&cm_connect_reqs);
43364+ atomic_inc_unchecked(&cm_connect_reqs);
43365 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43366 cm_node, cm_id, jiffies);
43367
43368@@ -4030,7 +4030,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
43369 return;
43370 cm_id = cm_node->cm_id;
43371
43372- atomic_inc(&cm_connect_reqs);
43373+ atomic_inc_unchecked(&cm_connect_reqs);
43374 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43375 cm_node, cm_id, jiffies);
43376
43377diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
43378index 4166452..fc952c3 100644
43379--- a/drivers/infiniband/hw/nes/nes_mgt.c
43380+++ b/drivers/infiniband/hw/nes/nes_mgt.c
43381@@ -40,8 +40,8 @@
43382 #include "nes.h"
43383 #include "nes_mgt.h"
43384
43385-atomic_t pau_qps_created;
43386-atomic_t pau_qps_destroyed;
43387+atomic_unchecked_t pau_qps_created;
43388+atomic_unchecked_t pau_qps_destroyed;
43389
43390 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
43391 {
43392@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
43393 {
43394 struct sk_buff *skb;
43395 unsigned long flags;
43396- atomic_inc(&pau_qps_destroyed);
43397+ atomic_inc_unchecked(&pau_qps_destroyed);
43398
43399 /* Free packets that have not yet been forwarded */
43400 /* Lock is acquired by skb_dequeue when removing the skb */
43401@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
43402 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
43403 skb_queue_head_init(&nesqp->pau_list);
43404 spin_lock_init(&nesqp->pau_lock);
43405- atomic_inc(&pau_qps_created);
43406+ atomic_inc_unchecked(&pau_qps_created);
43407 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
43408 }
43409
43410diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
43411index 49eb511..a774366 100644
43412--- a/drivers/infiniband/hw/nes/nes_nic.c
43413+++ b/drivers/infiniband/hw/nes/nes_nic.c
43414@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
43415 target_stat_values[++index] = mh_detected;
43416 target_stat_values[++index] = mh_pauses_sent;
43417 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
43418- target_stat_values[++index] = atomic_read(&cm_connects);
43419- target_stat_values[++index] = atomic_read(&cm_accepts);
43420- target_stat_values[++index] = atomic_read(&cm_disconnects);
43421- target_stat_values[++index] = atomic_read(&cm_connecteds);
43422- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
43423- target_stat_values[++index] = atomic_read(&cm_rejects);
43424- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
43425- target_stat_values[++index] = atomic_read(&qps_created);
43426- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
43427- target_stat_values[++index] = atomic_read(&qps_destroyed);
43428- target_stat_values[++index] = atomic_read(&cm_closes);
43429+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
43430+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
43431+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
43432+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
43433+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
43434+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
43435+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
43436+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
43437+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
43438+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
43439+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
43440 target_stat_values[++index] = cm_packets_sent;
43441 target_stat_values[++index] = cm_packets_bounced;
43442 target_stat_values[++index] = cm_packets_created;
43443 target_stat_values[++index] = cm_packets_received;
43444 target_stat_values[++index] = cm_packets_dropped;
43445 target_stat_values[++index] = cm_packets_retrans;
43446- target_stat_values[++index] = atomic_read(&cm_listens_created);
43447- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
43448+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
43449+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
43450 target_stat_values[++index] = cm_backlog_drops;
43451- target_stat_values[++index] = atomic_read(&cm_loopbacks);
43452- target_stat_values[++index] = atomic_read(&cm_nodes_created);
43453- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
43454- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
43455- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
43456+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
43457+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
43458+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
43459+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
43460+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
43461 target_stat_values[++index] = nesadapter->free_4kpbl;
43462 target_stat_values[++index] = nesadapter->free_256pbl;
43463 target_stat_values[++index] = int_mod_timer_init;
43464 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
43465 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
43466 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
43467- target_stat_values[++index] = atomic_read(&pau_qps_created);
43468- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
43469+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
43470+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
43471 }
43472
43473 /**
43474diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
43475index fef067c..6a25ccd 100644
43476--- a/drivers/infiniband/hw/nes/nes_verbs.c
43477+++ b/drivers/infiniband/hw/nes/nes_verbs.c
43478@@ -46,9 +46,9 @@
43479
43480 #include <rdma/ib_umem.h>
43481
43482-atomic_t mod_qp_timouts;
43483-atomic_t qps_created;
43484-atomic_t sw_qps_destroyed;
43485+atomic_unchecked_t mod_qp_timouts;
43486+atomic_unchecked_t qps_created;
43487+atomic_unchecked_t sw_qps_destroyed;
43488
43489 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
43490
43491@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
43492 if (init_attr->create_flags)
43493 return ERR_PTR(-EINVAL);
43494
43495- atomic_inc(&qps_created);
43496+ atomic_inc_unchecked(&qps_created);
43497 switch (init_attr->qp_type) {
43498 case IB_QPT_RC:
43499 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
43500@@ -1468,7 +1468,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
43501 struct iw_cm_event cm_event;
43502 int ret = 0;
43503
43504- atomic_inc(&sw_qps_destroyed);
43505+ atomic_inc_unchecked(&sw_qps_destroyed);
43506 nesqp->destroyed = 1;
43507
43508 /* Blow away the connection if it exists. */
43509diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
43510index c00ae09..04e91be 100644
43511--- a/drivers/infiniband/hw/qib/qib.h
43512+++ b/drivers/infiniband/hw/qib/qib.h
43513@@ -52,6 +52,7 @@
43514 #include <linux/kref.h>
43515 #include <linux/sched.h>
43516 #include <linux/kthread.h>
43517+#include <linux/slab.h>
43518
43519 #include "qib_common.h"
43520 #include "qib_verbs.h"
43521diff --git a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
43522index cdc7df4..a2fdfdb 100644
43523--- a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
43524+++ b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
43525@@ -156,7 +156,7 @@ static size_t ipoib_get_size(const struct net_device *dev)
43526 nla_total_size(2); /* IFLA_IPOIB_UMCAST */
43527 }
43528
43529-static struct rtnl_link_ops ipoib_link_ops __read_mostly = {
43530+static struct rtnl_link_ops ipoib_link_ops = {
43531 .kind = "ipoib",
43532 .maxtype = IFLA_IPOIB_MAX,
43533 .policy = ipoib_policy,
43534diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
43535index e29c04e..adbf68c 100644
43536--- a/drivers/input/gameport/gameport.c
43537+++ b/drivers/input/gameport/gameport.c
43538@@ -527,14 +527,14 @@ EXPORT_SYMBOL(gameport_set_phys);
43539 */
43540 static void gameport_init_port(struct gameport *gameport)
43541 {
43542- static atomic_t gameport_no = ATOMIC_INIT(0);
43543+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
43544
43545 __module_get(THIS_MODULE);
43546
43547 mutex_init(&gameport->drv_mutex);
43548 device_initialize(&gameport->dev);
43549 dev_set_name(&gameport->dev, "gameport%lu",
43550- (unsigned long)atomic_inc_return(&gameport_no) - 1);
43551+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
43552 gameport->dev.bus = &gameport_bus;
43553 gameport->dev.release = gameport_release_port;
43554 if (gameport->parent)
43555diff --git a/drivers/input/input.c b/drivers/input/input.c
43556index 0f175f5..4c481c0 100644
43557--- a/drivers/input/input.c
43558+++ b/drivers/input/input.c
43559@@ -1775,7 +1775,7 @@ EXPORT_SYMBOL_GPL(input_class);
43560 */
43561 struct input_dev *input_allocate_device(void)
43562 {
43563- static atomic_t input_no = ATOMIC_INIT(0);
43564+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
43565 struct input_dev *dev;
43566
43567 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
43568@@ -1790,7 +1790,7 @@ struct input_dev *input_allocate_device(void)
43569 INIT_LIST_HEAD(&dev->node);
43570
43571 dev_set_name(&dev->dev, "input%lu",
43572- (unsigned long) atomic_inc_return(&input_no) - 1);
43573+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
43574
43575 __module_get(THIS_MODULE);
43576 }
43577diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
43578index 4a95b22..874c182 100644
43579--- a/drivers/input/joystick/sidewinder.c
43580+++ b/drivers/input/joystick/sidewinder.c
43581@@ -30,6 +30,7 @@
43582 #include <linux/kernel.h>
43583 #include <linux/module.h>
43584 #include <linux/slab.h>
43585+#include <linux/sched.h>
43586 #include <linux/input.h>
43587 #include <linux/gameport.h>
43588 #include <linux/jiffies.h>
43589diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
43590index fc55f0d..11e2aa6 100644
43591--- a/drivers/input/joystick/xpad.c
43592+++ b/drivers/input/joystick/xpad.c
43593@@ -886,7 +886,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
43594
43595 static int xpad_led_probe(struct usb_xpad *xpad)
43596 {
43597- static atomic_t led_seq = ATOMIC_INIT(0);
43598+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
43599 long led_no;
43600 struct xpad_led *led;
43601 struct led_classdev *led_cdev;
43602@@ -899,7 +899,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
43603 if (!led)
43604 return -ENOMEM;
43605
43606- led_no = (long)atomic_inc_return(&led_seq) - 1;
43607+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
43608
43609 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
43610 led->xpad = xpad;
43611diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
43612index afed8e2..3aa8a18 100644
43613--- a/drivers/input/misc/ims-pcu.c
43614+++ b/drivers/input/misc/ims-pcu.c
43615@@ -1851,7 +1851,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
43616
43617 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43618 {
43619- static atomic_t device_no = ATOMIC_INIT(0);
43620+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
43621
43622 const struct ims_pcu_device_info *info;
43623 int error;
43624@@ -1882,7 +1882,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43625 }
43626
43627 /* Device appears to be operable, complete initialization */
43628- pcu->device_no = atomic_inc_return(&device_no) - 1;
43629+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
43630
43631 /*
43632 * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor
43633diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
43634index f4cf664..3204fda 100644
43635--- a/drivers/input/mouse/psmouse.h
43636+++ b/drivers/input/mouse/psmouse.h
43637@@ -117,7 +117,7 @@ struct psmouse_attribute {
43638 ssize_t (*set)(struct psmouse *psmouse, void *data,
43639 const char *buf, size_t count);
43640 bool protect;
43641-};
43642+} __do_const;
43643 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
43644
43645 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
43646diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
43647index b604564..3f14ae4 100644
43648--- a/drivers/input/mousedev.c
43649+++ b/drivers/input/mousedev.c
43650@@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
43651
43652 spin_unlock_irq(&client->packet_lock);
43653
43654- if (copy_to_user(buffer, data, count))
43655+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
43656 return -EFAULT;
43657
43658 return count;
43659diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
43660index d399b8b..4913ede 100644
43661--- a/drivers/input/serio/serio.c
43662+++ b/drivers/input/serio/serio.c
43663@@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev)
43664 */
43665 static void serio_init_port(struct serio *serio)
43666 {
43667- static atomic_t serio_no = ATOMIC_INIT(0);
43668+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
43669
43670 __module_get(THIS_MODULE);
43671
43672@@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio)
43673 mutex_init(&serio->drv_mutex);
43674 device_initialize(&serio->dev);
43675 dev_set_name(&serio->dev, "serio%lu",
43676- (unsigned long)atomic_inc_return(&serio_no) - 1);
43677+ (unsigned long)atomic_inc_return_unchecked(&serio_no) - 1);
43678 serio->dev.bus = &serio_bus;
43679 serio->dev.release = serio_release_port;
43680 serio->dev.groups = serio_device_attr_groups;
43681diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
43682index c9a02fe..0debc75 100644
43683--- a/drivers/input/serio/serio_raw.c
43684+++ b/drivers/input/serio/serio_raw.c
43685@@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
43686
43687 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43688 {
43689- static atomic_t serio_raw_no = ATOMIC_INIT(0);
43690+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
43691 struct serio_raw *serio_raw;
43692 int err;
43693
43694@@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43695 }
43696
43697 snprintf(serio_raw->name, sizeof(serio_raw->name),
43698- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
43699+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
43700 kref_init(&serio_raw->kref);
43701 INIT_LIST_HEAD(&serio_raw->client_list);
43702 init_waitqueue_head(&serio_raw->wait);
43703diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
43704index 505a9ad..f0b1b6e 100644
43705--- a/drivers/iommu/amd_iommu.c
43706+++ b/drivers/iommu/amd_iommu.c
43707@@ -823,11 +823,21 @@ static void copy_cmd_to_buffer(struct amd_iommu *iommu,
43708
43709 static void build_completion_wait(struct iommu_cmd *cmd, u64 address)
43710 {
43711+ phys_addr_t physaddr;
43712 WARN_ON(address & 0x7ULL);
43713
43714 memset(cmd, 0, sizeof(*cmd));
43715- cmd->data[0] = lower_32_bits(__pa(address)) | CMD_COMPL_WAIT_STORE_MASK;
43716- cmd->data[1] = upper_32_bits(__pa(address));
43717+
43718+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
43719+ if (object_starts_on_stack(address)) {
43720+ void *adjbuf = (void *)address - current->stack + current->lowmem_stack;
43721+ physaddr = __pa((u64)adjbuf);
43722+ } else
43723+#endif
43724+ physaddr = __pa(address);
43725+
43726+ cmd->data[0] = lower_32_bits(physaddr) | CMD_COMPL_WAIT_STORE_MASK;
43727+ cmd->data[1] = upper_32_bits(physaddr);
43728 cmd->data[2] = 1;
43729 CMD_SET_TYPE(cmd, CMD_COMPL_WAIT);
43730 }
43731diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
43732index 60558f7..5a02369 100644
43733--- a/drivers/iommu/arm-smmu.c
43734+++ b/drivers/iommu/arm-smmu.c
43735@@ -934,7 +934,7 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain,
43736 cfg->irptndx = cfg->cbndx;
43737 }
43738
43739- ACCESS_ONCE(smmu_domain->smmu) = smmu;
43740+ ACCESS_ONCE_RW(smmu_domain->smmu) = smmu;
43741 arm_smmu_init_context_bank(smmu_domain);
43742 spin_unlock_irqrestore(&smmu_domain->lock, flags);
43743
43744diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
43745index ed8b048..7fbcc01 100644
43746--- a/drivers/iommu/iommu.c
43747+++ b/drivers/iommu/iommu.c
43748@@ -802,7 +802,7 @@ static int iommu_bus_notifier(struct notifier_block *nb,
43749 static int iommu_bus_init(struct bus_type *bus, const struct iommu_ops *ops)
43750 {
43751 int err;
43752- struct notifier_block *nb;
43753+ notifier_block_no_const *nb;
43754 struct iommu_callback_data cb = {
43755 .ops = ops,
43756 };
43757diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
43758index 74a1767..5a359e8 100644
43759--- a/drivers/iommu/irq_remapping.c
43760+++ b/drivers/iommu/irq_remapping.c
43761@@ -361,7 +361,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
43762 void panic_if_irq_remap(const char *msg)
43763 {
43764 if (irq_remapping_enabled)
43765- panic(msg);
43766+ panic("%s", msg);
43767 }
43768
43769 static void ir_ack_apic_edge(struct irq_data *data)
43770@@ -382,10 +382,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
43771
43772 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
43773 {
43774- chip->irq_print_chip = ir_print_prefix;
43775- chip->irq_ack = ir_ack_apic_edge;
43776- chip->irq_eoi = ir_ack_apic_level;
43777- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43778+ pax_open_kernel();
43779+ *(void **)&chip->irq_print_chip = ir_print_prefix;
43780+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
43781+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
43782+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43783+ pax_close_kernel();
43784 }
43785
43786 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
43787diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
43788index 38493ff..001538b 100644
43789--- a/drivers/irqchip/irq-gic.c
43790+++ b/drivers/irqchip/irq-gic.c
43791@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
43792 * Supported arch specific GIC irq extension.
43793 * Default make them NULL.
43794 */
43795-struct irq_chip gic_arch_extn = {
43796+irq_chip_no_const gic_arch_extn = {
43797 .irq_eoi = NULL,
43798 .irq_mask = NULL,
43799 .irq_unmask = NULL,
43800@@ -311,7 +311,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43801 chained_irq_exit(chip, desc);
43802 }
43803
43804-static struct irq_chip gic_chip = {
43805+static irq_chip_no_const gic_chip __read_only = {
43806 .name = "GIC",
43807 .irq_mask = gic_mask_irq,
43808 .irq_unmask = gic_unmask_irq,
43809diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
43810index 8777065..a4a9967 100644
43811--- a/drivers/irqchip/irq-renesas-irqc.c
43812+++ b/drivers/irqchip/irq-renesas-irqc.c
43813@@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
43814 struct irqc_priv *p;
43815 struct resource *io;
43816 struct resource *irq;
43817- struct irq_chip *irq_chip;
43818+ irq_chip_no_const *irq_chip;
43819 const char *name = dev_name(&pdev->dev);
43820 int ret;
43821 int k;
43822diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43823index 6a2df32..dc962f1 100644
43824--- a/drivers/isdn/capi/capi.c
43825+++ b/drivers/isdn/capi/capi.c
43826@@ -81,8 +81,8 @@ struct capiminor {
43827
43828 struct capi20_appl *ap;
43829 u32 ncci;
43830- atomic_t datahandle;
43831- atomic_t msgid;
43832+ atomic_unchecked_t datahandle;
43833+ atomic_unchecked_t msgid;
43834
43835 struct tty_port port;
43836 int ttyinstop;
43837@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43838 capimsg_setu16(s, 2, mp->ap->applid);
43839 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43840 capimsg_setu8 (s, 5, CAPI_RESP);
43841- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43842+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43843 capimsg_setu32(s, 8, mp->ncci);
43844 capimsg_setu16(s, 12, datahandle);
43845 }
43846@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43847 mp->outbytes -= len;
43848 spin_unlock_bh(&mp->outlock);
43849
43850- datahandle = atomic_inc_return(&mp->datahandle);
43851+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43852 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43853 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43854 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43855 capimsg_setu16(skb->data, 2, mp->ap->applid);
43856 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43857 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43858- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43859+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43860 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43861 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43862 capimsg_setu16(skb->data, 16, len); /* Data length */
43863diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43864index aecec6d..11e13c5 100644
43865--- a/drivers/isdn/gigaset/bas-gigaset.c
43866+++ b/drivers/isdn/gigaset/bas-gigaset.c
43867@@ -2565,22 +2565,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43868
43869
43870 static const struct gigaset_ops gigops = {
43871- gigaset_write_cmd,
43872- gigaset_write_room,
43873- gigaset_chars_in_buffer,
43874- gigaset_brkchars,
43875- gigaset_init_bchannel,
43876- gigaset_close_bchannel,
43877- gigaset_initbcshw,
43878- gigaset_freebcshw,
43879- gigaset_reinitbcshw,
43880- gigaset_initcshw,
43881- gigaset_freecshw,
43882- gigaset_set_modem_ctrl,
43883- gigaset_baud_rate,
43884- gigaset_set_line_ctrl,
43885- gigaset_isoc_send_skb,
43886- gigaset_isoc_input,
43887+ .write_cmd = gigaset_write_cmd,
43888+ .write_room = gigaset_write_room,
43889+ .chars_in_buffer = gigaset_chars_in_buffer,
43890+ .brkchars = gigaset_brkchars,
43891+ .init_bchannel = gigaset_init_bchannel,
43892+ .close_bchannel = gigaset_close_bchannel,
43893+ .initbcshw = gigaset_initbcshw,
43894+ .freebcshw = gigaset_freebcshw,
43895+ .reinitbcshw = gigaset_reinitbcshw,
43896+ .initcshw = gigaset_initcshw,
43897+ .freecshw = gigaset_freecshw,
43898+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43899+ .baud_rate = gigaset_baud_rate,
43900+ .set_line_ctrl = gigaset_set_line_ctrl,
43901+ .send_skb = gigaset_isoc_send_skb,
43902+ .handle_input = gigaset_isoc_input,
43903 };
43904
43905 /* bas_gigaset_init
43906diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43907index 600c79b..3752bab 100644
43908--- a/drivers/isdn/gigaset/interface.c
43909+++ b/drivers/isdn/gigaset/interface.c
43910@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43911 }
43912 tty->driver_data = cs;
43913
43914- ++cs->port.count;
43915+ atomic_inc(&cs->port.count);
43916
43917- if (cs->port.count == 1) {
43918+ if (atomic_read(&cs->port.count) == 1) {
43919 tty_port_tty_set(&cs->port, tty);
43920 cs->port.low_latency = 1;
43921 }
43922@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43923
43924 if (!cs->connected)
43925 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43926- else if (!cs->port.count)
43927+ else if (!atomic_read(&cs->port.count))
43928 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43929- else if (!--cs->port.count)
43930+ else if (!atomic_dec_return(&cs->port.count))
43931 tty_port_tty_set(&cs->port, NULL);
43932
43933 mutex_unlock(&cs->mutex);
43934diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43935index 8c91fd5..14f13ce 100644
43936--- a/drivers/isdn/gigaset/ser-gigaset.c
43937+++ b/drivers/isdn/gigaset/ser-gigaset.c
43938@@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43939 }
43940
43941 static const struct gigaset_ops ops = {
43942- gigaset_write_cmd,
43943- gigaset_write_room,
43944- gigaset_chars_in_buffer,
43945- gigaset_brkchars,
43946- gigaset_init_bchannel,
43947- gigaset_close_bchannel,
43948- gigaset_initbcshw,
43949- gigaset_freebcshw,
43950- gigaset_reinitbcshw,
43951- gigaset_initcshw,
43952- gigaset_freecshw,
43953- gigaset_set_modem_ctrl,
43954- gigaset_baud_rate,
43955- gigaset_set_line_ctrl,
43956- gigaset_m10x_send_skb, /* asyncdata.c */
43957- gigaset_m10x_input, /* asyncdata.c */
43958+ .write_cmd = gigaset_write_cmd,
43959+ .write_room = gigaset_write_room,
43960+ .chars_in_buffer = gigaset_chars_in_buffer,
43961+ .brkchars = gigaset_brkchars,
43962+ .init_bchannel = gigaset_init_bchannel,
43963+ .close_bchannel = gigaset_close_bchannel,
43964+ .initbcshw = gigaset_initbcshw,
43965+ .freebcshw = gigaset_freebcshw,
43966+ .reinitbcshw = gigaset_reinitbcshw,
43967+ .initcshw = gigaset_initcshw,
43968+ .freecshw = gigaset_freecshw,
43969+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43970+ .baud_rate = gigaset_baud_rate,
43971+ .set_line_ctrl = gigaset_set_line_ctrl,
43972+ .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43973+ .handle_input = gigaset_m10x_input, /* asyncdata.c */
43974 };
43975
43976
43977diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43978index a8e652d..edadaa4 100644
43979--- a/drivers/isdn/gigaset/usb-gigaset.c
43980+++ b/drivers/isdn/gigaset/usb-gigaset.c
43981@@ -548,7 +548,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43982 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43983 memcpy(cs->hw.usb->bchars, buf, 6);
43984 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43985- 0, 0, &buf, 6, 2000);
43986+ 0, 0, buf, 6, 2000);
43987 }
43988
43989 static void gigaset_freebcshw(struct bc_state *bcs)
43990@@ -867,22 +867,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43991 }
43992
43993 static const struct gigaset_ops ops = {
43994- gigaset_write_cmd,
43995- gigaset_write_room,
43996- gigaset_chars_in_buffer,
43997- gigaset_brkchars,
43998- gigaset_init_bchannel,
43999- gigaset_close_bchannel,
44000- gigaset_initbcshw,
44001- gigaset_freebcshw,
44002- gigaset_reinitbcshw,
44003- gigaset_initcshw,
44004- gigaset_freecshw,
44005- gigaset_set_modem_ctrl,
44006- gigaset_baud_rate,
44007- gigaset_set_line_ctrl,
44008- gigaset_m10x_send_skb,
44009- gigaset_m10x_input,
44010+ .write_cmd = gigaset_write_cmd,
44011+ .write_room = gigaset_write_room,
44012+ .chars_in_buffer = gigaset_chars_in_buffer,
44013+ .brkchars = gigaset_brkchars,
44014+ .init_bchannel = gigaset_init_bchannel,
44015+ .close_bchannel = gigaset_close_bchannel,
44016+ .initbcshw = gigaset_initbcshw,
44017+ .freebcshw = gigaset_freebcshw,
44018+ .reinitbcshw = gigaset_reinitbcshw,
44019+ .initcshw = gigaset_initcshw,
44020+ .freecshw = gigaset_freecshw,
44021+ .set_modem_ctrl = gigaset_set_modem_ctrl,
44022+ .baud_rate = gigaset_baud_rate,
44023+ .set_line_ctrl = gigaset_set_line_ctrl,
44024+ .send_skb = gigaset_m10x_send_skb,
44025+ .handle_input = gigaset_m10x_input,
44026 };
44027
44028 /*
44029diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
44030index 4d9b195..455075c 100644
44031--- a/drivers/isdn/hardware/avm/b1.c
44032+++ b/drivers/isdn/hardware/avm/b1.c
44033@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
44034 }
44035 if (left) {
44036 if (t4file->user) {
44037- if (copy_from_user(buf, dp, left))
44038+ if (left > sizeof buf || copy_from_user(buf, dp, left))
44039 return -EFAULT;
44040 } else {
44041 memcpy(buf, dp, left);
44042@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
44043 }
44044 if (left) {
44045 if (config->user) {
44046- if (copy_from_user(buf, dp, left))
44047+ if (left > sizeof buf || copy_from_user(buf, dp, left))
44048 return -EFAULT;
44049 } else {
44050 memcpy(buf, dp, left);
44051diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
44052index 9b856e1..fa03c92 100644
44053--- a/drivers/isdn/i4l/isdn_common.c
44054+++ b/drivers/isdn/i4l/isdn_common.c
44055@@ -1654,6 +1654,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
44056 } else
44057 return -EINVAL;
44058 case IIOCDBGVAR:
44059+ if (!capable(CAP_SYS_RAWIO))
44060+ return -EPERM;
44061 if (arg) {
44062 if (copy_to_user(argp, &dev, sizeof(ulong)))
44063 return -EFAULT;
44064diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
44065index 91d5730..336523e 100644
44066--- a/drivers/isdn/i4l/isdn_concap.c
44067+++ b/drivers/isdn/i4l/isdn_concap.c
44068@@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
44069 }
44070
44071 struct concap_device_ops isdn_concap_reliable_dl_dops = {
44072- &isdn_concap_dl_data_req,
44073- &isdn_concap_dl_connect_req,
44074- &isdn_concap_dl_disconn_req
44075+ .data_req = &isdn_concap_dl_data_req,
44076+ .connect_req = &isdn_concap_dl_connect_req,
44077+ .disconn_req = &isdn_concap_dl_disconn_req
44078 };
44079
44080 /* The following should better go into a dedicated source file such that
44081diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
44082index bc91261..2ef7e36 100644
44083--- a/drivers/isdn/i4l/isdn_tty.c
44084+++ b/drivers/isdn/i4l/isdn_tty.c
44085@@ -1503,9 +1503,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
44086
44087 #ifdef ISDN_DEBUG_MODEM_OPEN
44088 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
44089- port->count);
44090+ atomic_read(&port->count));
44091 #endif
44092- port->count++;
44093+ atomic_inc(&port->count);
44094 port->tty = tty;
44095 /*
44096 * Start up serial port
44097@@ -1549,7 +1549,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
44098 #endif
44099 return;
44100 }
44101- if ((tty->count == 1) && (port->count != 1)) {
44102+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
44103 /*
44104 * Uh, oh. tty->count is 1, which means that the tty
44105 * structure will be freed. Info->count should always
44106@@ -1558,15 +1558,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
44107 * serial port won't be shutdown.
44108 */
44109 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
44110- "info->count is %d\n", port->count);
44111- port->count = 1;
44112+ "info->count is %d\n", atomic_read(&port->count));
44113+ atomic_set(&port->count, 1);
44114 }
44115- if (--port->count < 0) {
44116+ if (atomic_dec_return(&port->count) < 0) {
44117 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
44118- info->line, port->count);
44119- port->count = 0;
44120+ info->line, atomic_read(&port->count));
44121+ atomic_set(&port->count, 0);
44122 }
44123- if (port->count) {
44124+ if (atomic_read(&port->count)) {
44125 #ifdef ISDN_DEBUG_MODEM_OPEN
44126 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
44127 #endif
44128@@ -1620,7 +1620,7 @@ isdn_tty_hangup(struct tty_struct *tty)
44129 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
44130 return;
44131 isdn_tty_shutdown(info);
44132- port->count = 0;
44133+ atomic_set(&port->count, 0);
44134 port->flags &= ~ASYNC_NORMAL_ACTIVE;
44135 port->tty = NULL;
44136 wake_up_interruptible(&port->open_wait);
44137@@ -1965,7 +1965,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
44138 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
44139 modem_info *info = &dev->mdm.info[i];
44140
44141- if (info->port.count == 0)
44142+ if (atomic_read(&info->port.count) == 0)
44143 continue;
44144 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
44145 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
44146diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
44147index e2d4e58..40cd045 100644
44148--- a/drivers/isdn/i4l/isdn_x25iface.c
44149+++ b/drivers/isdn/i4l/isdn_x25iface.c
44150@@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
44151
44152
44153 static struct concap_proto_ops ix25_pops = {
44154- &isdn_x25iface_proto_new,
44155- &isdn_x25iface_proto_del,
44156- &isdn_x25iface_proto_restart,
44157- &isdn_x25iface_proto_close,
44158- &isdn_x25iface_xmit,
44159- &isdn_x25iface_receive,
44160- &isdn_x25iface_connect_ind,
44161- &isdn_x25iface_disconn_ind
44162+ .proto_new = &isdn_x25iface_proto_new,
44163+ .proto_del = &isdn_x25iface_proto_del,
44164+ .restart = &isdn_x25iface_proto_restart,
44165+ .close = &isdn_x25iface_proto_close,
44166+ .encap_and_xmit = &isdn_x25iface_xmit,
44167+ .data_ind = &isdn_x25iface_receive,
44168+ .connect_ind = &isdn_x25iface_connect_ind,
44169+ .disconn_ind = &isdn_x25iface_disconn_ind
44170 };
44171
44172 /* error message helper function */
44173diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
44174index 6a7447c..cae33fe 100644
44175--- a/drivers/isdn/icn/icn.c
44176+++ b/drivers/isdn/icn/icn.c
44177@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
44178 if (count > len)
44179 count = len;
44180 if (user) {
44181- if (copy_from_user(msg, buf, count))
44182+ if (count > sizeof msg || copy_from_user(msg, buf, count))
44183 return -EFAULT;
44184 } else
44185 memcpy(msg, buf, count);
44186diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
44187index 87f7dff..7300125 100644
44188--- a/drivers/isdn/mISDN/dsp_cmx.c
44189+++ b/drivers/isdn/mISDN/dsp_cmx.c
44190@@ -1625,7 +1625,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
44191 static u16 dsp_count; /* last sample count */
44192 static int dsp_count_valid; /* if we have last sample count */
44193
44194-void
44195+void __intentional_overflow(-1)
44196 dsp_cmx_send(void *arg)
44197 {
44198 struct dsp_conf *conf;
44199diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
44200index f58a354..fbae176 100644
44201--- a/drivers/leds/leds-clevo-mail.c
44202+++ b/drivers/leds/leds-clevo-mail.c
44203@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
44204 * detected as working, but in reality it is not) as low as
44205 * possible.
44206 */
44207-static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
44208+static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
44209 {
44210 .callback = clevo_mail_led_dmi_callback,
44211 .ident = "Clevo D410J",
44212diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
44213index 046cb70..6b20d39 100644
44214--- a/drivers/leds/leds-ss4200.c
44215+++ b/drivers/leds/leds-ss4200.c
44216@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
44217 * detected as working, but in reality it is not) as low as
44218 * possible.
44219 */
44220-static struct dmi_system_id nas_led_whitelist[] __initdata = {
44221+static struct dmi_system_id nas_led_whitelist[] __initconst = {
44222 {
44223 .callback = ss4200_led_dmi_callback,
44224 .ident = "Intel SS4200-E",
44225diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
44226index 6590558..a74c5dd 100644
44227--- a/drivers/lguest/core.c
44228+++ b/drivers/lguest/core.c
44229@@ -96,9 +96,17 @@ static __init int map_switcher(void)
44230 * The end address needs +1 because __get_vm_area allocates an
44231 * extra guard page, so we need space for that.
44232 */
44233+
44234+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
44235+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44236+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
44237+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44238+#else
44239 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44240 VM_ALLOC, switcher_addr, switcher_addr
44241 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44242+#endif
44243+
44244 if (!switcher_vma) {
44245 err = -ENOMEM;
44246 printk("lguest: could not map switcher pages high\n");
44247@@ -121,7 +129,7 @@ static __init int map_switcher(void)
44248 * Now the Switcher is mapped at the right address, we can't fail!
44249 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
44250 */
44251- memcpy(switcher_vma->addr, start_switcher_text,
44252+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
44253 end_switcher_text - start_switcher_text);
44254
44255 printk(KERN_INFO "lguest: mapped switcher at %p\n",
44256diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
44257index e8b55c3..3514c37 100644
44258--- a/drivers/lguest/page_tables.c
44259+++ b/drivers/lguest/page_tables.c
44260@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
44261 /*:*/
44262
44263 #ifdef CONFIG_X86_PAE
44264-static void release_pmd(pmd_t *spmd)
44265+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
44266 {
44267 /* If the entry's not present, there's nothing to release. */
44268 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
44269diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
44270index 922a1ac..9dd0c2a 100644
44271--- a/drivers/lguest/x86/core.c
44272+++ b/drivers/lguest/x86/core.c
44273@@ -59,7 +59,7 @@ static struct {
44274 /* Offset from where switcher.S was compiled to where we've copied it */
44275 static unsigned long switcher_offset(void)
44276 {
44277- return switcher_addr - (unsigned long)start_switcher_text;
44278+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
44279 }
44280
44281 /* This cpu's struct lguest_pages (after the Switcher text page) */
44282@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
44283 * These copies are pretty cheap, so we do them unconditionally: */
44284 /* Save the current Host top-level page directory.
44285 */
44286+
44287+#ifdef CONFIG_PAX_PER_CPU_PGD
44288+ pages->state.host_cr3 = read_cr3();
44289+#else
44290 pages->state.host_cr3 = __pa(current->mm->pgd);
44291+#endif
44292+
44293 /*
44294 * Set up the Guest's page tables to see this CPU's pages (and no
44295 * other CPU's pages).
44296@@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
44297 * compiled-in switcher code and the high-mapped copy we just made.
44298 */
44299 for (i = 0; i < IDT_ENTRIES; i++)
44300- default_idt_entries[i] += switcher_offset();
44301+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
44302
44303 /*
44304 * Set up the Switcher's per-cpu areas.
44305@@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
44306 * it will be undisturbed when we switch. To change %cs and jump we
44307 * need this structure to feed to Intel's "lcall" instruction.
44308 */
44309- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
44310+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
44311 lguest_entry.segment = LGUEST_CS;
44312
44313 /*
44314diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
44315index 40634b0..4f5855e 100644
44316--- a/drivers/lguest/x86/switcher_32.S
44317+++ b/drivers/lguest/x86/switcher_32.S
44318@@ -87,6 +87,7 @@
44319 #include <asm/page.h>
44320 #include <asm/segment.h>
44321 #include <asm/lguest.h>
44322+#include <asm/processor-flags.h>
44323
44324 // We mark the start of the code to copy
44325 // It's placed in .text tho it's never run here
44326@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
44327 // Changes type when we load it: damn Intel!
44328 // For after we switch over our page tables
44329 // That entry will be read-only: we'd crash.
44330+
44331+#ifdef CONFIG_PAX_KERNEXEC
44332+ mov %cr0, %edx
44333+ xor $X86_CR0_WP, %edx
44334+ mov %edx, %cr0
44335+#endif
44336+
44337 movl $(GDT_ENTRY_TSS*8), %edx
44338 ltr %dx
44339
44340@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
44341 // Let's clear it again for our return.
44342 // The GDT descriptor of the Host
44343 // Points to the table after two "size" bytes
44344- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
44345+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
44346 // Clear "used" from type field (byte 5, bit 2)
44347- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
44348+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
44349+
44350+#ifdef CONFIG_PAX_KERNEXEC
44351+ mov %cr0, %eax
44352+ xor $X86_CR0_WP, %eax
44353+ mov %eax, %cr0
44354+#endif
44355
44356 // Once our page table's switched, the Guest is live!
44357 // The Host fades as we run this final step.
44358@@ -295,13 +309,12 @@ deliver_to_host:
44359 // I consulted gcc, and it gave
44360 // These instructions, which I gladly credit:
44361 leal (%edx,%ebx,8), %eax
44362- movzwl (%eax),%edx
44363- movl 4(%eax), %eax
44364- xorw %ax, %ax
44365- orl %eax, %edx
44366+ movl 4(%eax), %edx
44367+ movw (%eax), %dx
44368 // Now the address of the handler's in %edx
44369 // We call it now: its "iret" drops us home.
44370- jmp *%edx
44371+ ljmp $__KERNEL_CS, $1f
44372+1: jmp *%edx
44373
44374 // Every interrupt can come to us here
44375 // But we must truly tell each apart.
44376diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
44377index a08e3ee..df8ade2 100644
44378--- a/drivers/md/bcache/closure.h
44379+++ b/drivers/md/bcache/closure.h
44380@@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
44381 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
44382 struct workqueue_struct *wq)
44383 {
44384- BUG_ON(object_is_on_stack(cl));
44385+ BUG_ON(object_starts_on_stack(cl));
44386 closure_set_ip(cl);
44387 cl->fn = fn;
44388 cl->wq = wq;
44389diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
44390index da3604e..7789cb4c 100644
44391--- a/drivers/md/bitmap.c
44392+++ b/drivers/md/bitmap.c
44393@@ -1771,7 +1771,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
44394 chunk_kb ? "KB" : "B");
44395 if (bitmap->storage.file) {
44396 seq_printf(seq, ", file: ");
44397- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
44398+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
44399 }
44400
44401 seq_printf(seq, "\n");
44402diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
44403index 0be9381..114262b 100644
44404--- a/drivers/md/dm-ioctl.c
44405+++ b/drivers/md/dm-ioctl.c
44406@@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
44407 cmd == DM_LIST_VERSIONS_CMD)
44408 return 0;
44409
44410- if ((cmd == DM_DEV_CREATE_CMD)) {
44411+ if (cmd == DM_DEV_CREATE_CMD) {
44412 if (!*param->name) {
44413 DMWARN("name not supplied when creating device");
44414 return -EINVAL;
44415diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
44416index 7dfdb5c..4caada6 100644
44417--- a/drivers/md/dm-raid1.c
44418+++ b/drivers/md/dm-raid1.c
44419@@ -40,7 +40,7 @@ enum dm_raid1_error {
44420
44421 struct mirror {
44422 struct mirror_set *ms;
44423- atomic_t error_count;
44424+ atomic_unchecked_t error_count;
44425 unsigned long error_type;
44426 struct dm_dev *dev;
44427 sector_t offset;
44428@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
44429 struct mirror *m;
44430
44431 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
44432- if (!atomic_read(&m->error_count))
44433+ if (!atomic_read_unchecked(&m->error_count))
44434 return m;
44435
44436 return NULL;
44437@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
44438 * simple way to tell if a device has encountered
44439 * errors.
44440 */
44441- atomic_inc(&m->error_count);
44442+ atomic_inc_unchecked(&m->error_count);
44443
44444 if (test_and_set_bit(error_type, &m->error_type))
44445 return;
44446@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
44447 struct mirror *m = get_default_mirror(ms);
44448
44449 do {
44450- if (likely(!atomic_read(&m->error_count)))
44451+ if (likely(!atomic_read_unchecked(&m->error_count)))
44452 return m;
44453
44454 if (m-- == ms->mirror)
44455@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
44456 {
44457 struct mirror *default_mirror = get_default_mirror(m->ms);
44458
44459- return !atomic_read(&default_mirror->error_count);
44460+ return !atomic_read_unchecked(&default_mirror->error_count);
44461 }
44462
44463 static int mirror_available(struct mirror_set *ms, struct bio *bio)
44464@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
44465 */
44466 if (likely(region_in_sync(ms, region, 1)))
44467 m = choose_mirror(ms, bio->bi_iter.bi_sector);
44468- else if (m && atomic_read(&m->error_count))
44469+ else if (m && atomic_read_unchecked(&m->error_count))
44470 m = NULL;
44471
44472 if (likely(m))
44473@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
44474 }
44475
44476 ms->mirror[mirror].ms = ms;
44477- atomic_set(&(ms->mirror[mirror].error_count), 0);
44478+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
44479 ms->mirror[mirror].error_type = 0;
44480 ms->mirror[mirror].offset = offset;
44481
44482@@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
44483 */
44484 static char device_status_char(struct mirror *m)
44485 {
44486- if (!atomic_read(&(m->error_count)))
44487+ if (!atomic_read_unchecked(&(m->error_count)))
44488 return 'A';
44489
44490 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
44491diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
44492index 87f86c7..a1a4100 100644
44493--- a/drivers/md/dm-stats.c
44494+++ b/drivers/md/dm-stats.c
44495@@ -382,7 +382,7 @@ do_sync_free:
44496 synchronize_rcu_expedited();
44497 dm_stat_free(&s->rcu_head);
44498 } else {
44499- ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
44500+ ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
44501 call_rcu(&s->rcu_head, dm_stat_free);
44502 }
44503 return 0;
44504@@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
44505 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
44506 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
44507 ));
44508- ACCESS_ONCE(last->last_sector) = end_sector;
44509- ACCESS_ONCE(last->last_rw) = bi_rw;
44510+ ACCESS_ONCE_RW(last->last_sector) = end_sector;
44511+ ACCESS_ONCE_RW(last->last_rw) = bi_rw;
44512 }
44513
44514 rcu_read_lock();
44515diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
44516index f8b37d4..5c5cafd 100644
44517--- a/drivers/md/dm-stripe.c
44518+++ b/drivers/md/dm-stripe.c
44519@@ -21,7 +21,7 @@ struct stripe {
44520 struct dm_dev *dev;
44521 sector_t physical_start;
44522
44523- atomic_t error_count;
44524+ atomic_unchecked_t error_count;
44525 };
44526
44527 struct stripe_c {
44528@@ -188,7 +188,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
44529 kfree(sc);
44530 return r;
44531 }
44532- atomic_set(&(sc->stripe[i].error_count), 0);
44533+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
44534 }
44535
44536 ti->private = sc;
44537@@ -332,7 +332,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
44538 DMEMIT("%d ", sc->stripes);
44539 for (i = 0; i < sc->stripes; i++) {
44540 DMEMIT("%s ", sc->stripe[i].dev->name);
44541- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
44542+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
44543 'D' : 'A';
44544 }
44545 buffer[i] = '\0';
44546@@ -377,8 +377,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
44547 */
44548 for (i = 0; i < sc->stripes; i++)
44549 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
44550- atomic_inc(&(sc->stripe[i].error_count));
44551- if (atomic_read(&(sc->stripe[i].error_count)) <
44552+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
44553+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
44554 DM_IO_ERROR_THRESHOLD)
44555 schedule_work(&sc->trigger_event);
44556 }
44557diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
44558index b2bd1eb..38f7a44 100644
44559--- a/drivers/md/dm-table.c
44560+++ b/drivers/md/dm-table.c
44561@@ -303,7 +303,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
44562 if (!dev_size)
44563 return 0;
44564
44565- if ((start >= dev_size) || (start + len > dev_size)) {
44566+ if ((start >= dev_size) || (len > dev_size - start)) {
44567 DMWARN("%s: %s too small for target: "
44568 "start=%llu, len=%llu, dev_size=%llu",
44569 dm_device_name(ti->table->md), bdevname(bdev, b),
44570diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
44571index e9d33ad..dae9880d 100644
44572--- a/drivers/md/dm-thin-metadata.c
44573+++ b/drivers/md/dm-thin-metadata.c
44574@@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44575 {
44576 pmd->info.tm = pmd->tm;
44577 pmd->info.levels = 2;
44578- pmd->info.value_type.context = pmd->data_sm;
44579+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44580 pmd->info.value_type.size = sizeof(__le64);
44581 pmd->info.value_type.inc = data_block_inc;
44582 pmd->info.value_type.dec = data_block_dec;
44583@@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44584
44585 pmd->bl_info.tm = pmd->tm;
44586 pmd->bl_info.levels = 1;
44587- pmd->bl_info.value_type.context = pmd->data_sm;
44588+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44589 pmd->bl_info.value_type.size = sizeof(__le64);
44590 pmd->bl_info.value_type.inc = data_block_inc;
44591 pmd->bl_info.value_type.dec = data_block_dec;
44592diff --git a/drivers/md/dm.c b/drivers/md/dm.c
44593index 58f3927..bfbad3e 100644
44594--- a/drivers/md/dm.c
44595+++ b/drivers/md/dm.c
44596@@ -183,9 +183,9 @@ struct mapped_device {
44597 /*
44598 * Event handling.
44599 */
44600- atomic_t event_nr;
44601+ atomic_unchecked_t event_nr;
44602 wait_queue_head_t eventq;
44603- atomic_t uevent_seq;
44604+ atomic_unchecked_t uevent_seq;
44605 struct list_head uevent_list;
44606 spinlock_t uevent_lock; /* Protect access to uevent_list */
44607
44608@@ -2071,8 +2071,8 @@ static struct mapped_device *alloc_dev(int minor)
44609 spin_lock_init(&md->deferred_lock);
44610 atomic_set(&md->holders, 1);
44611 atomic_set(&md->open_count, 0);
44612- atomic_set(&md->event_nr, 0);
44613- atomic_set(&md->uevent_seq, 0);
44614+ atomic_set_unchecked(&md->event_nr, 0);
44615+ atomic_set_unchecked(&md->uevent_seq, 0);
44616 INIT_LIST_HEAD(&md->uevent_list);
44617 INIT_LIST_HEAD(&md->table_devices);
44618 spin_lock_init(&md->uevent_lock);
44619@@ -2228,7 +2228,7 @@ static void event_callback(void *context)
44620
44621 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
44622
44623- atomic_inc(&md->event_nr);
44624+ atomic_inc_unchecked(&md->event_nr);
44625 wake_up(&md->eventq);
44626 }
44627
44628@@ -2921,18 +2921,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
44629
44630 uint32_t dm_next_uevent_seq(struct mapped_device *md)
44631 {
44632- return atomic_add_return(1, &md->uevent_seq);
44633+ return atomic_add_return_unchecked(1, &md->uevent_seq);
44634 }
44635
44636 uint32_t dm_get_event_nr(struct mapped_device *md)
44637 {
44638- return atomic_read(&md->event_nr);
44639+ return atomic_read_unchecked(&md->event_nr);
44640 }
44641
44642 int dm_wait_event(struct mapped_device *md, int event_nr)
44643 {
44644 return wait_event_interruptible(md->eventq,
44645- (event_nr != atomic_read(&md->event_nr)));
44646+ (event_nr != atomic_read_unchecked(&md->event_nr)));
44647 }
44648
44649 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
44650diff --git a/drivers/md/md.c b/drivers/md/md.c
44651index 9233c71..ed5243a 100644
44652--- a/drivers/md/md.c
44653+++ b/drivers/md/md.c
44654@@ -190,10 +190,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
44655 * start build, activate spare
44656 */
44657 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
44658-static atomic_t md_event_count;
44659+static atomic_unchecked_t md_event_count;
44660 void md_new_event(struct mddev *mddev)
44661 {
44662- atomic_inc(&md_event_count);
44663+ atomic_inc_unchecked(&md_event_count);
44664 wake_up(&md_event_waiters);
44665 }
44666 EXPORT_SYMBOL_GPL(md_new_event);
44667@@ -203,7 +203,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
44668 */
44669 static void md_new_event_inintr(struct mddev *mddev)
44670 {
44671- atomic_inc(&md_event_count);
44672+ atomic_inc_unchecked(&md_event_count);
44673 wake_up(&md_event_waiters);
44674 }
44675
44676@@ -1426,7 +1426,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
44677 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
44678 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
44679 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
44680- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44681+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44682
44683 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
44684 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
44685@@ -1677,7 +1677,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
44686 else
44687 sb->resync_offset = cpu_to_le64(0);
44688
44689- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
44690+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
44691
44692 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
44693 sb->size = cpu_to_le64(mddev->dev_sectors);
44694@@ -2547,7 +2547,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
44695 static ssize_t
44696 errors_show(struct md_rdev *rdev, char *page)
44697 {
44698- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
44699+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
44700 }
44701
44702 static ssize_t
44703@@ -2556,7 +2556,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
44704 char *e;
44705 unsigned long n = simple_strtoul(buf, &e, 10);
44706 if (*buf && (*e == 0 || *e == '\n')) {
44707- atomic_set(&rdev->corrected_errors, n);
44708+ atomic_set_unchecked(&rdev->corrected_errors, n);
44709 return len;
44710 }
44711 return -EINVAL;
44712@@ -3000,8 +3000,8 @@ int md_rdev_init(struct md_rdev *rdev)
44713 rdev->sb_loaded = 0;
44714 rdev->bb_page = NULL;
44715 atomic_set(&rdev->nr_pending, 0);
44716- atomic_set(&rdev->read_errors, 0);
44717- atomic_set(&rdev->corrected_errors, 0);
44718+ atomic_set_unchecked(&rdev->read_errors, 0);
44719+ atomic_set_unchecked(&rdev->corrected_errors, 0);
44720
44721 INIT_LIST_HEAD(&rdev->same_set);
44722 init_waitqueue_head(&rdev->blocked_wait);
44723@@ -6855,7 +6855,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
44724
44725 spin_unlock(&pers_lock);
44726 seq_printf(seq, "\n");
44727- seq->poll_event = atomic_read(&md_event_count);
44728+ seq->poll_event = atomic_read_unchecked(&md_event_count);
44729 return 0;
44730 }
44731 if (v == (void*)2) {
44732@@ -6958,7 +6958,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
44733 return error;
44734
44735 seq = file->private_data;
44736- seq->poll_event = atomic_read(&md_event_count);
44737+ seq->poll_event = atomic_read_unchecked(&md_event_count);
44738 return error;
44739 }
44740
44741@@ -6975,7 +6975,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
44742 /* always allow read */
44743 mask = POLLIN | POLLRDNORM;
44744
44745- if (seq->poll_event != atomic_read(&md_event_count))
44746+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
44747 mask |= POLLERR | POLLPRI;
44748 return mask;
44749 }
44750@@ -7022,7 +7022,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
44751 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
44752 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
44753 (int)part_stat_read(&disk->part0, sectors[1]) -
44754- atomic_read(&disk->sync_io);
44755+ atomic_read_unchecked(&disk->sync_io);
44756 /* sync IO will cause sync_io to increase before the disk_stats
44757 * as sync_io is counted when a request starts, and
44758 * disk_stats is counted when it completes.
44759diff --git a/drivers/md/md.h b/drivers/md/md.h
44760index 03cec5b..0a658c1 100644
44761--- a/drivers/md/md.h
44762+++ b/drivers/md/md.h
44763@@ -94,13 +94,13 @@ struct md_rdev {
44764 * only maintained for arrays that
44765 * support hot removal
44766 */
44767- atomic_t read_errors; /* number of consecutive read errors that
44768+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
44769 * we have tried to ignore.
44770 */
44771 struct timespec last_read_error; /* monotonic time since our
44772 * last read error
44773 */
44774- atomic_t corrected_errors; /* number of corrected read errors,
44775+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
44776 * for reporting to userspace and storing
44777 * in superblock.
44778 */
44779@@ -448,7 +448,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44780
44781 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44782 {
44783- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44784+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44785 }
44786
44787 struct md_personality
44788diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
44789index 786b689..ea8c956 100644
44790--- a/drivers/md/persistent-data/dm-space-map-metadata.c
44791+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
44792@@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
44793 * Flick into a mode where all blocks get allocated in the new area.
44794 */
44795 smm->begin = old_len;
44796- memcpy(sm, &bootstrap_ops, sizeof(*sm));
44797+ memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44798
44799 /*
44800 * Extend.
44801@@ -710,7 +710,7 @@ out:
44802 /*
44803 * Switch back to normal behaviour.
44804 */
44805- memcpy(sm, &ops, sizeof(*sm));
44806+ memcpy((void *)sm, &ops, sizeof(*sm));
44807 return r;
44808 }
44809
44810diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44811index 3e6d115..ffecdeb 100644
44812--- a/drivers/md/persistent-data/dm-space-map.h
44813+++ b/drivers/md/persistent-data/dm-space-map.h
44814@@ -71,6 +71,7 @@ struct dm_space_map {
44815 dm_sm_threshold_fn fn,
44816 void *context);
44817 };
44818+typedef struct dm_space_map __no_const dm_space_map_no_const;
44819
44820 /*----------------------------------------------------------------*/
44821
44822diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44823index 40b35be..a327e11 100644
44824--- a/drivers/md/raid1.c
44825+++ b/drivers/md/raid1.c
44826@@ -1931,7 +1931,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44827 if (r1_sync_page_io(rdev, sect, s,
44828 bio->bi_io_vec[idx].bv_page,
44829 READ) != 0)
44830- atomic_add(s, &rdev->corrected_errors);
44831+ atomic_add_unchecked(s, &rdev->corrected_errors);
44832 }
44833 sectors -= s;
44834 sect += s;
44835@@ -2164,7 +2164,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44836 !test_bit(Faulty, &rdev->flags)) {
44837 if (r1_sync_page_io(rdev, sect, s,
44838 conf->tmppage, READ)) {
44839- atomic_add(s, &rdev->corrected_errors);
44840+ atomic_add_unchecked(s, &rdev->corrected_errors);
44841 printk(KERN_INFO
44842 "md/raid1:%s: read error corrected "
44843 "(%d sectors at %llu on %s)\n",
44844diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44845index 32e282f..5cec803 100644
44846--- a/drivers/md/raid10.c
44847+++ b/drivers/md/raid10.c
44848@@ -1944,7 +1944,7 @@ static void end_sync_read(struct bio *bio, int error)
44849 /* The write handler will notice the lack of
44850 * R10BIO_Uptodate and record any errors etc
44851 */
44852- atomic_add(r10_bio->sectors,
44853+ atomic_add_unchecked(r10_bio->sectors,
44854 &conf->mirrors[d].rdev->corrected_errors);
44855
44856 /* for reconstruct, we always reschedule after a read.
44857@@ -2301,7 +2301,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44858 {
44859 struct timespec cur_time_mon;
44860 unsigned long hours_since_last;
44861- unsigned int read_errors = atomic_read(&rdev->read_errors);
44862+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44863
44864 ktime_get_ts(&cur_time_mon);
44865
44866@@ -2323,9 +2323,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44867 * overflowing the shift of read_errors by hours_since_last.
44868 */
44869 if (hours_since_last >= 8 * sizeof(read_errors))
44870- atomic_set(&rdev->read_errors, 0);
44871+ atomic_set_unchecked(&rdev->read_errors, 0);
44872 else
44873- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44874+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44875 }
44876
44877 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44878@@ -2379,8 +2379,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44879 return;
44880
44881 check_decay_read_errors(mddev, rdev);
44882- atomic_inc(&rdev->read_errors);
44883- if (atomic_read(&rdev->read_errors) > max_read_errors) {
44884+ atomic_inc_unchecked(&rdev->read_errors);
44885+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44886 char b[BDEVNAME_SIZE];
44887 bdevname(rdev->bdev, b);
44888
44889@@ -2388,7 +2388,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44890 "md/raid10:%s: %s: Raid device exceeded "
44891 "read_error threshold [cur %d:max %d]\n",
44892 mdname(mddev), b,
44893- atomic_read(&rdev->read_errors), max_read_errors);
44894+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44895 printk(KERN_NOTICE
44896 "md/raid10:%s: %s: Failing raid device\n",
44897 mdname(mddev), b);
44898@@ -2543,7 +2543,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44899 sect +
44900 choose_data_offset(r10_bio, rdev)),
44901 bdevname(rdev->bdev, b));
44902- atomic_add(s, &rdev->corrected_errors);
44903+ atomic_add_unchecked(s, &rdev->corrected_errors);
44904 }
44905
44906 rdev_dec_pending(rdev, mddev);
44907diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44908index 9c66e59..42a8eac 100644
44909--- a/drivers/md/raid5.c
44910+++ b/drivers/md/raid5.c
44911@@ -1730,6 +1730,10 @@ static int grow_one_stripe(struct r5conf *conf, int hash)
44912 return 1;
44913 }
44914
44915+#ifdef CONFIG_GRKERNSEC_HIDESYM
44916+static atomic_unchecked_t raid5_cache_id = ATOMIC_INIT(0);
44917+#endif
44918+
44919 static int grow_stripes(struct r5conf *conf, int num)
44920 {
44921 struct kmem_cache *sc;
44922@@ -1741,7 +1745,11 @@ static int grow_stripes(struct r5conf *conf, int num)
44923 "raid%d-%s", conf->level, mdname(conf->mddev));
44924 else
44925 sprintf(conf->cache_name[0],
44926+#ifdef CONFIG_GRKERNSEC_HIDESYM
44927+ "raid%d-%08lx", conf->level, atomic_inc_return_unchecked(&raid5_cache_id));
44928+#else
44929 "raid%d-%p", conf->level, conf->mddev);
44930+#endif
44931 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
44932
44933 conf->active_name = 0;
44934@@ -2017,21 +2025,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44935 mdname(conf->mddev), STRIPE_SECTORS,
44936 (unsigned long long)s,
44937 bdevname(rdev->bdev, b));
44938- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44939+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44940 clear_bit(R5_ReadError, &sh->dev[i].flags);
44941 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44942 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44943 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44944
44945- if (atomic_read(&rdev->read_errors))
44946- atomic_set(&rdev->read_errors, 0);
44947+ if (atomic_read_unchecked(&rdev->read_errors))
44948+ atomic_set_unchecked(&rdev->read_errors, 0);
44949 } else {
44950 const char *bdn = bdevname(rdev->bdev, b);
44951 int retry = 0;
44952 int set_bad = 0;
44953
44954 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44955- atomic_inc(&rdev->read_errors);
44956+ atomic_inc_unchecked(&rdev->read_errors);
44957 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44958 printk_ratelimited(
44959 KERN_WARNING
44960@@ -2059,7 +2067,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44961 mdname(conf->mddev),
44962 (unsigned long long)s,
44963 bdn);
44964- } else if (atomic_read(&rdev->read_errors)
44965+ } else if (atomic_read_unchecked(&rdev->read_errors)
44966 > conf->max_nr_stripes)
44967 printk(KERN_WARNING
44968 "md/raid:%s: Too many read errors, failing device %s.\n",
44969diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44970index 983db75..ef9248c 100644
44971--- a/drivers/media/dvb-core/dvbdev.c
44972+++ b/drivers/media/dvb-core/dvbdev.c
44973@@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44974 const struct dvb_device *template, void *priv, int type)
44975 {
44976 struct dvb_device *dvbdev;
44977- struct file_operations *dvbdevfops;
44978+ file_operations_no_const *dvbdevfops;
44979 struct device *clsdev;
44980 int minor;
44981 int id;
44982diff --git a/drivers/media/dvb-frontends/af9033.h b/drivers/media/dvb-frontends/af9033.h
44983index 6ad22b6..6e90e2a 100644
44984--- a/drivers/media/dvb-frontends/af9033.h
44985+++ b/drivers/media/dvb-frontends/af9033.h
44986@@ -96,6 +96,6 @@ struct af9033_ops {
44987 int (*pid_filter_ctrl)(struct dvb_frontend *fe, int onoff);
44988 int (*pid_filter)(struct dvb_frontend *fe, int index, u16 pid,
44989 int onoff);
44990-};
44991+} __no_const;
44992
44993 #endif /* AF9033_H */
44994diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
44995index 9b6c3bb..baeb5c7 100644
44996--- a/drivers/media/dvb-frontends/dib3000.h
44997+++ b/drivers/media/dvb-frontends/dib3000.h
44998@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
44999 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
45000 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
45001 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
45002-};
45003+} __no_const;
45004
45005 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
45006 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
45007diff --git a/drivers/media/dvb-frontends/dib7000p.h b/drivers/media/dvb-frontends/dib7000p.h
45008index 1fea0e9..321ce8f 100644
45009--- a/drivers/media/dvb-frontends/dib7000p.h
45010+++ b/drivers/media/dvb-frontends/dib7000p.h
45011@@ -64,7 +64,7 @@ struct dib7000p_ops {
45012 int (*get_adc_power)(struct dvb_frontend *fe);
45013 int (*slave_reset)(struct dvb_frontend *fe);
45014 struct dvb_frontend *(*init)(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000p_config *cfg);
45015-};
45016+} __no_const;
45017
45018 #if IS_ENABLED(CONFIG_DVB_DIB7000P)
45019 void *dib7000p_attach(struct dib7000p_ops *ops);
45020diff --git a/drivers/media/dvb-frontends/dib8000.h b/drivers/media/dvb-frontends/dib8000.h
45021index 84cc103..5780c54 100644
45022--- a/drivers/media/dvb-frontends/dib8000.h
45023+++ b/drivers/media/dvb-frontends/dib8000.h
45024@@ -61,7 +61,7 @@ struct dib8000_ops {
45025 int (*pid_filter_ctrl)(struct dvb_frontend *fe, u8 onoff);
45026 int (*pid_filter)(struct dvb_frontend *fe, u8 id, u16 pid, u8 onoff);
45027 struct dvb_frontend *(*init)(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib8000_config *cfg);
45028-};
45029+} __no_const;
45030
45031 #if IS_ENABLED(CONFIG_DVB_DIB8000)
45032 void *dib8000_attach(struct dib8000_ops *ops);
45033diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
45034index ce27e6d..b70435a 100644
45035--- a/drivers/media/pci/cx88/cx88-video.c
45036+++ b/drivers/media/pci/cx88/cx88-video.c
45037@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
45038
45039 /* ------------------------------------------------------------------ */
45040
45041-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45042-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45043-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45044+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45045+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45046+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45047
45048 module_param_array(video_nr, int, NULL, 0444);
45049 module_param_array(vbi_nr, int, NULL, 0444);
45050diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
45051index 802642d..5534900 100644
45052--- a/drivers/media/pci/ivtv/ivtv-driver.c
45053+++ b/drivers/media/pci/ivtv/ivtv-driver.c
45054@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
45055 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
45056
45057 /* ivtv instance counter */
45058-static atomic_t ivtv_instance = ATOMIC_INIT(0);
45059+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
45060
45061 /* Parameter declarations */
45062 static int cardtype[IVTV_MAX_CARDS];
45063diff --git a/drivers/media/pci/solo6x10/solo6x10-core.c b/drivers/media/pci/solo6x10/solo6x10-core.c
45064index 8cbe6b4..ea3601c 100644
45065--- a/drivers/media/pci/solo6x10/solo6x10-core.c
45066+++ b/drivers/media/pci/solo6x10/solo6x10-core.c
45067@@ -424,7 +424,7 @@ static void solo_device_release(struct device *dev)
45068
45069 static int solo_sysfs_init(struct solo_dev *solo_dev)
45070 {
45071- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
45072+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
45073 struct device *dev = &solo_dev->dev;
45074 const char *driver;
45075 int i;
45076diff --git a/drivers/media/pci/solo6x10/solo6x10-g723.c b/drivers/media/pci/solo6x10/solo6x10-g723.c
45077index c7141f2..5301fec 100644
45078--- a/drivers/media/pci/solo6x10/solo6x10-g723.c
45079+++ b/drivers/media/pci/solo6x10/solo6x10-g723.c
45080@@ -351,7 +351,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
45081
45082 int solo_g723_init(struct solo_dev *solo_dev)
45083 {
45084- static struct snd_device_ops ops = { NULL };
45085+ static struct snd_device_ops ops = { };
45086 struct snd_card *card;
45087 struct snd_kcontrol_new kctl;
45088 char name[32];
45089diff --git a/drivers/media/pci/solo6x10/solo6x10-p2m.c b/drivers/media/pci/solo6x10/solo6x10-p2m.c
45090index 8c84846..27b4f83 100644
45091--- a/drivers/media/pci/solo6x10/solo6x10-p2m.c
45092+++ b/drivers/media/pci/solo6x10/solo6x10-p2m.c
45093@@ -73,7 +73,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
45094
45095 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
45096 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
45097- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
45098+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
45099 if (p2m_id < 0)
45100 p2m_id = -p2m_id;
45101 }
45102diff --git a/drivers/media/pci/solo6x10/solo6x10.h b/drivers/media/pci/solo6x10/solo6x10.h
45103index 72017b7..dd37ae6 100644
45104--- a/drivers/media/pci/solo6x10/solo6x10.h
45105+++ b/drivers/media/pci/solo6x10/solo6x10.h
45106@@ -219,7 +219,7 @@ struct solo_dev {
45107
45108 /* P2M DMA Engine */
45109 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
45110- atomic_t p2m_count;
45111+ atomic_unchecked_t p2m_count;
45112 int p2m_jiffies;
45113 unsigned int p2m_timeouts;
45114
45115diff --git a/drivers/media/pci/tw68/tw68-core.c b/drivers/media/pci/tw68/tw68-core.c
45116index 63f0b64..a017c1c 100644
45117--- a/drivers/media/pci/tw68/tw68-core.c
45118+++ b/drivers/media/pci/tw68/tw68-core.c
45119@@ -60,7 +60,7 @@ static unsigned int card[] = {[0 ... (TW68_MAXBOARDS - 1)] = UNSET };
45120 module_param_array(card, int, NULL, 0444);
45121 MODULE_PARM_DESC(card, "card type");
45122
45123-static atomic_t tw68_instance = ATOMIC_INIT(0);
45124+static atomic_unchecked_t tw68_instance = ATOMIC_INIT(0);
45125
45126 /* ------------------------------------------------------------------ */
45127
45128diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
45129index 64ab6fb..ef4a8b9 100644
45130--- a/drivers/media/platform/omap/omap_vout.c
45131+++ b/drivers/media/platform/omap/omap_vout.c
45132@@ -63,7 +63,6 @@ enum omap_vout_channels {
45133 OMAP_VIDEO2,
45134 };
45135
45136-static struct videobuf_queue_ops video_vbq_ops;
45137 /* Variables configurable through module params*/
45138 static u32 video1_numbuffers = 3;
45139 static u32 video2_numbuffers = 3;
45140@@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
45141 {
45142 struct videobuf_queue *q;
45143 struct omap_vout_device *vout = NULL;
45144+ static struct videobuf_queue_ops video_vbq_ops = {
45145+ .buf_setup = omap_vout_buffer_setup,
45146+ .buf_prepare = omap_vout_buffer_prepare,
45147+ .buf_release = omap_vout_buffer_release,
45148+ .buf_queue = omap_vout_buffer_queue,
45149+ };
45150
45151 vout = video_drvdata(file);
45152 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
45153@@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
45154 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
45155
45156 q = &vout->vbq;
45157- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
45158- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
45159- video_vbq_ops.buf_release = omap_vout_buffer_release;
45160- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
45161 spin_lock_init(&vout->vbq_lock);
45162
45163 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
45164diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
45165index fb2acc5..a2fcbdc4 100644
45166--- a/drivers/media/platform/s5p-tv/mixer.h
45167+++ b/drivers/media/platform/s5p-tv/mixer.h
45168@@ -156,7 +156,7 @@ struct mxr_layer {
45169 /** layer index (unique identifier) */
45170 int idx;
45171 /** callbacks for layer methods */
45172- struct mxr_layer_ops ops;
45173+ struct mxr_layer_ops *ops;
45174 /** format array */
45175 const struct mxr_format **fmt_array;
45176 /** size of format array */
45177diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45178index 74344c7..a39e70e 100644
45179--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45180+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45181@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
45182 {
45183 struct mxr_layer *layer;
45184 int ret;
45185- struct mxr_layer_ops ops = {
45186+ static struct mxr_layer_ops ops = {
45187 .release = mxr_graph_layer_release,
45188 .buffer_set = mxr_graph_buffer_set,
45189 .stream_set = mxr_graph_stream_set,
45190diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
45191index b713403..53cb5ad 100644
45192--- a/drivers/media/platform/s5p-tv/mixer_reg.c
45193+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
45194@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
45195 layer->update_buf = next;
45196 }
45197
45198- layer->ops.buffer_set(layer, layer->update_buf);
45199+ layer->ops->buffer_set(layer, layer->update_buf);
45200
45201 if (done && done != layer->shadow_buf)
45202 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
45203diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
45204index b4d2696..91df48e 100644
45205--- a/drivers/media/platform/s5p-tv/mixer_video.c
45206+++ b/drivers/media/platform/s5p-tv/mixer_video.c
45207@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
45208 layer->geo.src.height = layer->geo.src.full_height;
45209
45210 mxr_geometry_dump(mdev, &layer->geo);
45211- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45212+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45213 mxr_geometry_dump(mdev, &layer->geo);
45214 }
45215
45216@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
45217 layer->geo.dst.full_width = mbus_fmt.width;
45218 layer->geo.dst.full_height = mbus_fmt.height;
45219 layer->geo.dst.field = mbus_fmt.field;
45220- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45221+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45222
45223 mxr_geometry_dump(mdev, &layer->geo);
45224 }
45225@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
45226 /* set source size to highest accepted value */
45227 geo->src.full_width = max(geo->dst.full_width, pix->width);
45228 geo->src.full_height = max(geo->dst.full_height, pix->height);
45229- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45230+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45231 mxr_geometry_dump(mdev, &layer->geo);
45232 /* set cropping to total visible screen */
45233 geo->src.width = pix->width;
45234@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
45235 geo->src.x_offset = 0;
45236 geo->src.y_offset = 0;
45237 /* assure consistency of geometry */
45238- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
45239+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
45240 mxr_geometry_dump(mdev, &layer->geo);
45241 /* set full size to lowest possible value */
45242 geo->src.full_width = 0;
45243 geo->src.full_height = 0;
45244- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45245+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45246 mxr_geometry_dump(mdev, &layer->geo);
45247
45248 /* returning results */
45249@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
45250 target->width = s->r.width;
45251 target->height = s->r.height;
45252
45253- layer->ops.fix_geometry(layer, stage, s->flags);
45254+ layer->ops->fix_geometry(layer, stage, s->flags);
45255
45256 /* retrieve update selection rectangle */
45257 res.left = target->x_offset;
45258@@ -954,13 +954,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
45259 mxr_output_get(mdev);
45260
45261 mxr_layer_update_output(layer);
45262- layer->ops.format_set(layer);
45263+ layer->ops->format_set(layer);
45264 /* enabling layer in hardware */
45265 spin_lock_irqsave(&layer->enq_slock, flags);
45266 layer->state = MXR_LAYER_STREAMING;
45267 spin_unlock_irqrestore(&layer->enq_slock, flags);
45268
45269- layer->ops.stream_set(layer, MXR_ENABLE);
45270+ layer->ops->stream_set(layer, MXR_ENABLE);
45271 mxr_streamer_get(mdev);
45272
45273 return 0;
45274@@ -1030,7 +1030,7 @@ static void stop_streaming(struct vb2_queue *vq)
45275 spin_unlock_irqrestore(&layer->enq_slock, flags);
45276
45277 /* disabling layer in hardware */
45278- layer->ops.stream_set(layer, MXR_DISABLE);
45279+ layer->ops->stream_set(layer, MXR_DISABLE);
45280 /* remove one streamer */
45281 mxr_streamer_put(mdev);
45282 /* allow changes in output configuration */
45283@@ -1068,8 +1068,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
45284
45285 void mxr_layer_release(struct mxr_layer *layer)
45286 {
45287- if (layer->ops.release)
45288- layer->ops.release(layer);
45289+ if (layer->ops->release)
45290+ layer->ops->release(layer);
45291 }
45292
45293 void mxr_base_layer_release(struct mxr_layer *layer)
45294@@ -1095,7 +1095,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
45295
45296 layer->mdev = mdev;
45297 layer->idx = idx;
45298- layer->ops = *ops;
45299+ layer->ops = ops;
45300
45301 spin_lock_init(&layer->enq_slock);
45302 INIT_LIST_HEAD(&layer->enq_list);
45303diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45304index c9388c4..ce71ece 100644
45305--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45306+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45307@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
45308 {
45309 struct mxr_layer *layer;
45310 int ret;
45311- struct mxr_layer_ops ops = {
45312+ static struct mxr_layer_ops ops = {
45313 .release = mxr_vp_layer_release,
45314 .buffer_set = mxr_vp_buffer_set,
45315 .stream_set = mxr_vp_stream_set,
45316diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
45317index 82affae..42833ec 100644
45318--- a/drivers/media/radio/radio-cadet.c
45319+++ b/drivers/media/radio/radio-cadet.c
45320@@ -333,6 +333,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45321 unsigned char readbuf[RDS_BUFFER];
45322 int i = 0;
45323
45324+ if (count > RDS_BUFFER)
45325+ return -EFAULT;
45326 mutex_lock(&dev->lock);
45327 if (dev->rdsstat == 0)
45328 cadet_start_rds(dev);
45329@@ -349,8 +351,9 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45330 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
45331 mutex_unlock(&dev->lock);
45332
45333- if (i && copy_to_user(data, readbuf, i))
45334- return -EFAULT;
45335+ if (i > sizeof(readbuf) || (i && copy_to_user(data, readbuf, i)))
45336+ i = -EFAULT;
45337+
45338 return i;
45339 }
45340
45341diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
45342index 5236035..c622c74 100644
45343--- a/drivers/media/radio/radio-maxiradio.c
45344+++ b/drivers/media/radio/radio-maxiradio.c
45345@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
45346 /* TEA5757 pin mappings */
45347 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
45348
45349-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
45350+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
45351
45352 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
45353 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
45354diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
45355index 050b3bb..79f62b9 100644
45356--- a/drivers/media/radio/radio-shark.c
45357+++ b/drivers/media/radio/radio-shark.c
45358@@ -79,7 +79,7 @@ struct shark_device {
45359 u32 last_val;
45360 };
45361
45362-static atomic_t shark_instance = ATOMIC_INIT(0);
45363+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45364
45365 static void shark_write_val(struct snd_tea575x *tea, u32 val)
45366 {
45367diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
45368index 8654e0d..0608a64 100644
45369--- a/drivers/media/radio/radio-shark2.c
45370+++ b/drivers/media/radio/radio-shark2.c
45371@@ -74,7 +74,7 @@ struct shark_device {
45372 u8 *transfer_buffer;
45373 };
45374
45375-static atomic_t shark_instance = ATOMIC_INIT(0);
45376+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45377
45378 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
45379 {
45380diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
45381index 633022b..7f10754 100644
45382--- a/drivers/media/radio/radio-si476x.c
45383+++ b/drivers/media/radio/radio-si476x.c
45384@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
45385 struct si476x_radio *radio;
45386 struct v4l2_ctrl *ctrl;
45387
45388- static atomic_t instance = ATOMIC_INIT(0);
45389+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
45390
45391 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
45392 if (!radio)
45393diff --git a/drivers/media/usb/dvb-usb/cinergyT2-core.c b/drivers/media/usb/dvb-usb/cinergyT2-core.c
45394index 9fd1527..8927230 100644
45395--- a/drivers/media/usb/dvb-usb/cinergyT2-core.c
45396+++ b/drivers/media/usb/dvb-usb/cinergyT2-core.c
45397@@ -50,29 +50,73 @@ static struct dvb_usb_device_properties cinergyt2_properties;
45398
45399 static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter *adap, int enable)
45400 {
45401- char buf[] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 0 };
45402- char result[64];
45403- return dvb_usb_generic_rw(adap->dev, buf, sizeof(buf), result,
45404- sizeof(result), 0);
45405+ char *buf;
45406+ char *result;
45407+ int retval;
45408+
45409+ buf = kmalloc(2, GFP_KERNEL);
45410+ if (buf == NULL)
45411+ return -ENOMEM;
45412+ result = kmalloc(64, GFP_KERNEL);
45413+ if (result == NULL) {
45414+ kfree(buf);
45415+ return -ENOMEM;
45416+ }
45417+
45418+ buf[0] = CINERGYT2_EP1_CONTROL_STREAM_TRANSFER;
45419+ buf[1] = enable ? 1 : 0;
45420+
45421+ retval = dvb_usb_generic_rw(adap->dev, buf, 2, result, 64, 0);
45422+
45423+ kfree(buf);
45424+ kfree(result);
45425+ return retval;
45426 }
45427
45428 static int cinergyt2_power_ctrl(struct dvb_usb_device *d, int enable)
45429 {
45430- char buf[] = { CINERGYT2_EP1_SLEEP_MODE, enable ? 0 : 1 };
45431- char state[3];
45432- return dvb_usb_generic_rw(d, buf, sizeof(buf), state, sizeof(state), 0);
45433+ char *buf;
45434+ char *state;
45435+ int retval;
45436+
45437+ buf = kmalloc(2, GFP_KERNEL);
45438+ if (buf == NULL)
45439+ return -ENOMEM;
45440+ state = kmalloc(3, GFP_KERNEL);
45441+ if (state == NULL) {
45442+ kfree(buf);
45443+ return -ENOMEM;
45444+ }
45445+
45446+ buf[0] = CINERGYT2_EP1_SLEEP_MODE;
45447+ buf[1] = enable ? 1 : 0;
45448+
45449+ retval = dvb_usb_generic_rw(d, buf, 2, state, 3, 0);
45450+
45451+ kfree(buf);
45452+ kfree(state);
45453+ return retval;
45454 }
45455
45456 static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
45457 {
45458- char query[] = { CINERGYT2_EP1_GET_FIRMWARE_VERSION };
45459- char state[3];
45460+ char *query;
45461+ char *state;
45462 int ret;
45463+ query = kmalloc(1, GFP_KERNEL);
45464+ if (query == NULL)
45465+ return -ENOMEM;
45466+ state = kmalloc(3, GFP_KERNEL);
45467+ if (state == NULL) {
45468+ kfree(query);
45469+ return -ENOMEM;
45470+ }
45471+
45472+ query[0] = CINERGYT2_EP1_GET_FIRMWARE_VERSION;
45473
45474 adap->fe_adap[0].fe = cinergyt2_fe_attach(adap->dev);
45475
45476- ret = dvb_usb_generic_rw(adap->dev, query, sizeof(query), state,
45477- sizeof(state), 0);
45478+ ret = dvb_usb_generic_rw(adap->dev, query, 1, state, 3, 0);
45479 if (ret < 0) {
45480 deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep "
45481 "state info\n");
45482@@ -80,7 +124,8 @@ static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
45483
45484 /* Copy this pointer as we are gonna need it in the release phase */
45485 cinergyt2_usb_device = adap->dev;
45486-
45487+ kfree(query);
45488+ kfree(state);
45489 return 0;
45490 }
45491
45492@@ -141,12 +186,23 @@ static int repeatable_keys[] = {
45493 static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45494 {
45495 struct cinergyt2_state *st = d->priv;
45496- u8 key[5] = {0, 0, 0, 0, 0}, cmd = CINERGYT2_EP1_GET_RC_EVENTS;
45497+ u8 *key, *cmd;
45498 int i;
45499
45500+ cmd = kmalloc(1, GFP_KERNEL);
45501+ if (cmd == NULL)
45502+ return -EINVAL;
45503+ key = kzalloc(5, GFP_KERNEL);
45504+ if (key == NULL) {
45505+ kfree(cmd);
45506+ return -EINVAL;
45507+ }
45508+
45509+ cmd[0] = CINERGYT2_EP1_GET_RC_EVENTS;
45510+
45511 *state = REMOTE_NO_KEY_PRESSED;
45512
45513- dvb_usb_generic_rw(d, &cmd, 1, key, sizeof(key), 0);
45514+ dvb_usb_generic_rw(d, cmd, 1, key, 5, 0);
45515 if (key[4] == 0xff) {
45516 /* key repeat */
45517 st->rc_counter++;
45518@@ -157,12 +213,12 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45519 *event = d->last_event;
45520 deb_rc("repeat key, event %x\n",
45521 *event);
45522- return 0;
45523+ goto out;
45524 }
45525 }
45526 deb_rc("repeated key (non repeatable)\n");
45527 }
45528- return 0;
45529+ goto out;
45530 }
45531
45532 /* hack to pass checksum on the custom field */
45533@@ -174,6 +230,9 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45534
45535 deb_rc("key: %*ph\n", 5, key);
45536 }
45537+out:
45538+ kfree(cmd);
45539+ kfree(key);
45540 return 0;
45541 }
45542
45543diff --git a/drivers/media/usb/dvb-usb/cinergyT2-fe.c b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45544index c890fe4..f9b2ae6 100644
45545--- a/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45546+++ b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45547@@ -145,103 +145,176 @@ static int cinergyt2_fe_read_status(struct dvb_frontend *fe,
45548 fe_status_t *status)
45549 {
45550 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45551- struct dvbt_get_status_msg result;
45552- u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45553+ struct dvbt_get_status_msg *result;
45554+ u8 *cmd;
45555 int ret;
45556
45557- ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&result,
45558- sizeof(result), 0);
45559+ cmd = kmalloc(1, GFP_KERNEL);
45560+ if (cmd == NULL)
45561+ return -ENOMEM;
45562+ result = kmalloc(sizeof(*result), GFP_KERNEL);
45563+ if (result == NULL) {
45564+ kfree(cmd);
45565+ return -ENOMEM;
45566+ }
45567+
45568+ cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45569+
45570+ ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)result,
45571+ sizeof(*result), 0);
45572 if (ret < 0)
45573- return ret;
45574+ goto out;
45575
45576 *status = 0;
45577
45578- if (0xffff - le16_to_cpu(result.gain) > 30)
45579+ if (0xffff - le16_to_cpu(result->gain) > 30)
45580 *status |= FE_HAS_SIGNAL;
45581- if (result.lock_bits & (1 << 6))
45582+ if (result->lock_bits & (1 << 6))
45583 *status |= FE_HAS_LOCK;
45584- if (result.lock_bits & (1 << 5))
45585+ if (result->lock_bits & (1 << 5))
45586 *status |= FE_HAS_SYNC;
45587- if (result.lock_bits & (1 << 4))
45588+ if (result->lock_bits & (1 << 4))
45589 *status |= FE_HAS_CARRIER;
45590- if (result.lock_bits & (1 << 1))
45591+ if (result->lock_bits & (1 << 1))
45592 *status |= FE_HAS_VITERBI;
45593
45594 if ((*status & (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC)) !=
45595 (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC))
45596 *status &= ~FE_HAS_LOCK;
45597
45598- return 0;
45599+out:
45600+ kfree(cmd);
45601+ kfree(result);
45602+ return ret;
45603 }
45604
45605 static int cinergyt2_fe_read_ber(struct dvb_frontend *fe, u32 *ber)
45606 {
45607 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45608- struct dvbt_get_status_msg status;
45609- char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45610+ struct dvbt_get_status_msg *status;
45611+ char *cmd;
45612 int ret;
45613
45614- ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
45615- sizeof(status), 0);
45616+ cmd = kmalloc(1, GFP_KERNEL);
45617+ if (cmd == NULL)
45618+ return -ENOMEM;
45619+ status = kmalloc(sizeof(*status), GFP_KERNEL);
45620+ if (status == NULL) {
45621+ kfree(cmd);
45622+ return -ENOMEM;
45623+ }
45624+
45625+ cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45626+
45627+ ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
45628+ sizeof(*status), 0);
45629 if (ret < 0)
45630- return ret;
45631+ goto out;
45632
45633- *ber = le32_to_cpu(status.viterbi_error_rate);
45634+ *ber = le32_to_cpu(status->viterbi_error_rate);
45635+out:
45636+ kfree(cmd);
45637+ kfree(status);
45638 return 0;
45639 }
45640
45641 static int cinergyt2_fe_read_unc_blocks(struct dvb_frontend *fe, u32 *unc)
45642 {
45643 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45644- struct dvbt_get_status_msg status;
45645- u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45646+ struct dvbt_get_status_msg *status;
45647+ u8 *cmd;
45648 int ret;
45649
45650- ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&status,
45651- sizeof(status), 0);
45652+ cmd = kmalloc(1, GFP_KERNEL);
45653+ if (cmd == NULL)
45654+ return -ENOMEM;
45655+ status = kmalloc(sizeof(*status), GFP_KERNEL);
45656+ if (status == NULL) {
45657+ kfree(cmd);
45658+ return -ENOMEM;
45659+ }
45660+
45661+ cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45662+
45663+ ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)status,
45664+ sizeof(*status), 0);
45665 if (ret < 0) {
45666 err("cinergyt2_fe_read_unc_blocks() Failed! (Error=%d)\n",
45667 ret);
45668- return ret;
45669+ goto out;
45670 }
45671- *unc = le32_to_cpu(status.uncorrected_block_count);
45672- return 0;
45673+ *unc = le32_to_cpu(status->uncorrected_block_count);
45674+
45675+out:
45676+ kfree(cmd);
45677+ kfree(status);
45678+ return ret;
45679 }
45680
45681 static int cinergyt2_fe_read_signal_strength(struct dvb_frontend *fe,
45682 u16 *strength)
45683 {
45684 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45685- struct dvbt_get_status_msg status;
45686- char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45687+ struct dvbt_get_status_msg *status;
45688+ char *cmd;
45689 int ret;
45690
45691- ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
45692- sizeof(status), 0);
45693+ cmd = kmalloc(1, GFP_KERNEL);
45694+ if (cmd == NULL)
45695+ return -ENOMEM;
45696+ status = kmalloc(sizeof(*status), GFP_KERNEL);
45697+ if (status == NULL) {
45698+ kfree(cmd);
45699+ return -ENOMEM;
45700+ }
45701+
45702+ cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45703+
45704+ ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
45705+ sizeof(*status), 0);
45706 if (ret < 0) {
45707 err("cinergyt2_fe_read_signal_strength() Failed!"
45708 " (Error=%d)\n", ret);
45709- return ret;
45710+ goto out;
45711 }
45712- *strength = (0xffff - le16_to_cpu(status.gain));
45713+ *strength = (0xffff - le16_to_cpu(status->gain));
45714+
45715+out:
45716+ kfree(cmd);
45717+ kfree(status);
45718 return 0;
45719 }
45720
45721 static int cinergyt2_fe_read_snr(struct dvb_frontend *fe, u16 *snr)
45722 {
45723 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45724- struct dvbt_get_status_msg status;
45725- char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45726+ struct dvbt_get_status_msg *status;
45727+ char *cmd;
45728 int ret;
45729
45730- ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
45731- sizeof(status), 0);
45732+ cmd = kmalloc(1, GFP_KERNEL);
45733+ if (cmd == NULL)
45734+ return -ENOMEM;
45735+ status = kmalloc(sizeof(*status), GFP_KERNEL);
45736+ if (status == NULL) {
45737+ kfree(cmd);
45738+ return -ENOMEM;
45739+ }
45740+
45741+ cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45742+
45743+ ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
45744+ sizeof(*status), 0);
45745 if (ret < 0) {
45746 err("cinergyt2_fe_read_snr() Failed! (Error=%d)\n", ret);
45747- return ret;
45748+ goto out;
45749 }
45750- *snr = (status.snr << 8) | status.snr;
45751- return 0;
45752+ *snr = (status->snr << 8) | status->snr;
45753+
45754+out:
45755+ kfree(cmd);
45756+ kfree(status);
45757+ return ret;
45758 }
45759
45760 static int cinergyt2_fe_init(struct dvb_frontend *fe)
45761@@ -266,35 +339,46 @@ static int cinergyt2_fe_set_frontend(struct dvb_frontend *fe)
45762 {
45763 struct dtv_frontend_properties *fep = &fe->dtv_property_cache;
45764 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45765- struct dvbt_set_parameters_msg param;
45766- char result[2];
45767+ struct dvbt_set_parameters_msg *param;
45768+ char *result;
45769 int err;
45770
45771- param.cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
45772- param.tps = cpu_to_le16(compute_tps(fep));
45773- param.freq = cpu_to_le32(fep->frequency / 1000);
45774- param.flags = 0;
45775+ result = kmalloc(2, GFP_KERNEL);
45776+ if (result == NULL)
45777+ return -ENOMEM;
45778+ param = kmalloc(sizeof(*param), GFP_KERNEL);
45779+ if (param == NULL) {
45780+ kfree(result);
45781+ return -ENOMEM;
45782+ }
45783+
45784+ param->cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
45785+ param->tps = cpu_to_le16(compute_tps(fep));
45786+ param->freq = cpu_to_le32(fep->frequency / 1000);
45787+ param->flags = 0;
45788
45789 switch (fep->bandwidth_hz) {
45790 default:
45791 case 8000000:
45792- param.bandwidth = 8;
45793+ param->bandwidth = 8;
45794 break;
45795 case 7000000:
45796- param.bandwidth = 7;
45797+ param->bandwidth = 7;
45798 break;
45799 case 6000000:
45800- param.bandwidth = 6;
45801+ param->bandwidth = 6;
45802 break;
45803 }
45804
45805 err = dvb_usb_generic_rw(state->d,
45806- (char *)&param, sizeof(param),
45807- result, sizeof(result), 0);
45808+ (char *)param, sizeof(*param),
45809+ result, 2, 0);
45810 if (err < 0)
45811 err("cinergyt2_fe_set_frontend() Failed! err=%d\n", err);
45812
45813- return (err < 0) ? err : 0;
45814+ kfree(result);
45815+ kfree(param);
45816+ return err;
45817 }
45818
45819 static void cinergyt2_fe_release(struct dvb_frontend *fe)
45820diff --git a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
45821index 733a7ff..f8b52e3 100644
45822--- a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
45823+++ b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
45824@@ -35,42 +35,57 @@ static int usb_cypress_writemem(struct usb_device *udev,u16 addr,u8 *data, u8 le
45825
45826 int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type)
45827 {
45828- struct hexline hx;
45829- u8 reset;
45830+ struct hexline *hx;
45831+ u8 *reset;
45832 int ret,pos=0;
45833
45834+ reset = kmalloc(1, GFP_KERNEL);
45835+ if (reset == NULL)
45836+ return -ENOMEM;
45837+
45838+ hx = kmalloc(sizeof(struct hexline), GFP_KERNEL);
45839+ if (hx == NULL) {
45840+ kfree(reset);
45841+ return -ENOMEM;
45842+ }
45843+
45844 /* stop the CPU */
45845- reset = 1;
45846- if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1)) != 1)
45847+ reset[0] = 1;
45848+ if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1)) != 1)
45849 err("could not stop the USB controller CPU.");
45850
45851- while ((ret = dvb_usb_get_hexline(fw,&hx,&pos)) > 0) {
45852- deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx.addr,hx.len,hx.chk);
45853- ret = usb_cypress_writemem(udev,hx.addr,hx.data,hx.len);
45854+ while ((ret = dvb_usb_get_hexline(fw,hx,&pos)) > 0) {
45855+ deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx->addr,hx->len,hx->chk);
45856+ ret = usb_cypress_writemem(udev,hx->addr,hx->data,hx->len);
45857
45858- if (ret != hx.len) {
45859+ if (ret != hx->len) {
45860 err("error while transferring firmware "
45861 "(transferred size: %d, block size: %d)",
45862- ret,hx.len);
45863+ ret,hx->len);
45864 ret = -EINVAL;
45865 break;
45866 }
45867 }
45868 if (ret < 0) {
45869 err("firmware download failed at %d with %d",pos,ret);
45870+ kfree(reset);
45871+ kfree(hx);
45872 return ret;
45873 }
45874
45875 if (ret == 0) {
45876 /* restart the CPU */
45877- reset = 0;
45878- if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1) != 1) {
45879+ reset[0] = 0;
45880+ if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1) != 1) {
45881 err("could not restart the USB controller CPU.");
45882 ret = -EINVAL;
45883 }
45884 } else
45885 ret = -EIO;
45886
45887+ kfree(reset);
45888+ kfree(hx);
45889+
45890 return ret;
45891 }
45892 EXPORT_SYMBOL(usb_cypress_load_firmware);
45893diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
45894index 1a3df10..57997a5 100644
45895--- a/drivers/media/usb/dvb-usb/dw2102.c
45896+++ b/drivers/media/usb/dvb-usb/dw2102.c
45897@@ -118,7 +118,7 @@ struct su3000_state {
45898
45899 struct s6x0_state {
45900 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
45901-};
45902+} __no_const;
45903
45904 /* debug */
45905 static int dvb_usb_dw2102_debug;
45906diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c b/drivers/media/usb/dvb-usb/technisat-usb2.c
45907index 6b0b8b6b..4038398 100644
45908--- a/drivers/media/usb/dvb-usb/technisat-usb2.c
45909+++ b/drivers/media/usb/dvb-usb/technisat-usb2.c
45910@@ -87,8 +87,11 @@ struct technisat_usb2_state {
45911 static int technisat_usb2_i2c_access(struct usb_device *udev,
45912 u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
45913 {
45914- u8 b[64];
45915- int ret, actual_length;
45916+ u8 *b = kmalloc(64, GFP_KERNEL);
45917+ int ret, actual_length, error = 0;
45918+
45919+ if (b == NULL)
45920+ return -ENOMEM;
45921
45922 deb_i2c("i2c-access: %02x, tx: ", device_addr);
45923 debug_dump(tx, txlen, deb_i2c);
45924@@ -121,7 +124,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
45925
45926 if (ret < 0) {
45927 err("i2c-error: out failed %02x = %d", device_addr, ret);
45928- return -ENODEV;
45929+ error = -ENODEV;
45930+ goto out;
45931 }
45932
45933 ret = usb_bulk_msg(udev,
45934@@ -129,7 +133,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
45935 b, 64, &actual_length, 1000);
45936 if (ret < 0) {
45937 err("i2c-error: in failed %02x = %d", device_addr, ret);
45938- return -ENODEV;
45939+ error = -ENODEV;
45940+ goto out;
45941 }
45942
45943 if (b[0] != I2C_STATUS_OK) {
45944@@ -137,8 +142,10 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
45945 /* handle tuner-i2c-nak */
45946 if (!(b[0] == I2C_STATUS_NAK &&
45947 device_addr == 0x60
45948- /* && device_is_technisat_usb2 */))
45949- return -ENODEV;
45950+ /* && device_is_technisat_usb2 */)) {
45951+ error = -ENODEV;
45952+ goto out;
45953+ }
45954 }
45955
45956 deb_i2c("status: %d, ", b[0]);
45957@@ -152,7 +159,9 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
45958
45959 deb_i2c("\n");
45960
45961- return 0;
45962+out:
45963+ kfree(b);
45964+ return error;
45965 }
45966
45967 static int technisat_usb2_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
45968@@ -224,14 +233,16 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
45969 {
45970 int ret;
45971
45972- u8 led[8] = {
45973- red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
45974- 0
45975- };
45976+ u8 *led = kzalloc(8, GFP_KERNEL);
45977+
45978+ if (led == NULL)
45979+ return -ENOMEM;
45980
45981 if (disable_led_control && state != TECH_LED_OFF)
45982 return 0;
45983
45984+ led[0] = red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST;
45985+
45986 switch (state) {
45987 case TECH_LED_ON:
45988 led[1] = 0x82;
45989@@ -263,16 +274,22 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
45990 red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
45991 USB_TYPE_VENDOR | USB_DIR_OUT,
45992 0, 0,
45993- led, sizeof(led), 500);
45994+ led, 8, 500);
45995
45996 mutex_unlock(&d->i2c_mutex);
45997+
45998+ kfree(led);
45999+
46000 return ret;
46001 }
46002
46003 static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 green)
46004 {
46005 int ret;
46006- u8 b = 0;
46007+ u8 *b = kzalloc(1, GFP_KERNEL);
46008+
46009+ if (b == NULL)
46010+ return -ENOMEM;
46011
46012 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
46013 return -EAGAIN;
46014@@ -281,10 +298,12 @@ static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 gre
46015 SET_LED_TIMER_DIVIDER_VENDOR_REQUEST,
46016 USB_TYPE_VENDOR | USB_DIR_OUT,
46017 (red << 8) | green, 0,
46018- &b, 1, 500);
46019+ b, 1, 500);
46020
46021 mutex_unlock(&d->i2c_mutex);
46022
46023+ kfree(b);
46024+
46025 return ret;
46026 }
46027
46028@@ -328,7 +347,7 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46029 struct dvb_usb_device_description **desc, int *cold)
46030 {
46031 int ret;
46032- u8 version[3];
46033+ u8 *version = kmalloc(3, GFP_KERNEL);
46034
46035 /* first select the interface */
46036 if (usb_set_interface(udev, 0, 1) != 0)
46037@@ -338,11 +357,14 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46038
46039 *cold = 0; /* by default do not download a firmware - just in case something is wrong */
46040
46041+ if (version == NULL)
46042+ return 0;
46043+
46044 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
46045 GET_VERSION_INFO_VENDOR_REQUEST,
46046 USB_TYPE_VENDOR | USB_DIR_IN,
46047 0, 0,
46048- version, sizeof(version), 500);
46049+ version, 3, 500);
46050
46051 if (ret < 0)
46052 *cold = 1;
46053@@ -351,6 +373,8 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46054 *cold = 0;
46055 }
46056
46057+ kfree(version);
46058+
46059 return 0;
46060 }
46061
46062@@ -591,10 +615,15 @@ static int technisat_usb2_frontend_attach(struct dvb_usb_adapter *a)
46063
46064 static int technisat_usb2_get_ir(struct dvb_usb_device *d)
46065 {
46066- u8 buf[62], *b;
46067+ u8 *buf, *b;
46068 int ret;
46069 struct ir_raw_event ev;
46070
46071+ buf = kmalloc(62, GFP_KERNEL);
46072+
46073+ if (buf == NULL)
46074+ return -ENOMEM;
46075+
46076 buf[0] = GET_IR_DATA_VENDOR_REQUEST;
46077 buf[1] = 0x08;
46078 buf[2] = 0x8f;
46079@@ -617,16 +646,20 @@ static int technisat_usb2_get_ir(struct dvb_usb_device *d)
46080 GET_IR_DATA_VENDOR_REQUEST,
46081 USB_TYPE_VENDOR | USB_DIR_IN,
46082 0x8080, 0,
46083- buf, sizeof(buf), 500);
46084+ buf, 62, 500);
46085
46086 unlock:
46087 mutex_unlock(&d->i2c_mutex);
46088
46089- if (ret < 0)
46090+ if (ret < 0) {
46091+ kfree(buf);
46092 return ret;
46093+ }
46094
46095- if (ret == 1)
46096+ if (ret == 1) {
46097+ kfree(buf);
46098 return 0; /* no key pressed */
46099+ }
46100
46101 /* decoding */
46102 b = buf+1;
46103@@ -653,6 +686,8 @@ unlock:
46104
46105 ir_raw_event_handle(d->rc_dev);
46106
46107+ kfree(buf);
46108+
46109 return 1;
46110 }
46111
46112diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46113index e502a5f..2a27f40 100644
46114--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46115+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46116@@ -427,7 +427,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
46117 * by passing a very big num_planes value */
46118 uplane = compat_alloc_user_space(num_planes *
46119 sizeof(struct v4l2_plane));
46120- kp->m.planes = (__force struct v4l2_plane *)uplane;
46121+ kp->m.planes = (__force_kernel struct v4l2_plane *)uplane;
46122
46123 while (--num_planes >= 0) {
46124 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
46125@@ -498,7 +498,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
46126 if (num_planes == 0)
46127 return 0;
46128
46129- uplane = (__force struct v4l2_plane __user *)kp->m.planes;
46130+ uplane = (struct v4l2_plane __force_user *)kp->m.planes;
46131 if (get_user(p, &up->m.planes))
46132 return -EFAULT;
46133 uplane32 = compat_ptr(p);
46134@@ -562,7 +562,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
46135 get_user(kp->flags, &up->flags) ||
46136 copy_from_user(&kp->fmt, &up->fmt, sizeof(up->fmt)))
46137 return -EFAULT;
46138- kp->base = (__force void *)compat_ptr(tmp);
46139+ kp->base = (__force_kernel void *)compat_ptr(tmp);
46140 return 0;
46141 }
46142
46143@@ -667,7 +667,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
46144 n * sizeof(struct v4l2_ext_control32)))
46145 return -EFAULT;
46146 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
46147- kp->controls = (__force struct v4l2_ext_control *)kcontrols;
46148+ kp->controls = (__force_kernel struct v4l2_ext_control *)kcontrols;
46149 while (--n >= 0) {
46150 u32 id;
46151
46152@@ -694,7 +694,7 @@ static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
46153 {
46154 struct v4l2_ext_control32 __user *ucontrols;
46155 struct v4l2_ext_control __user *kcontrols =
46156- (__force struct v4l2_ext_control __user *)kp->controls;
46157+ (struct v4l2_ext_control __force_user *)kp->controls;
46158 int n = kp->count;
46159 compat_caddr_t p;
46160
46161@@ -778,7 +778,7 @@ static int get_v4l2_edid32(struct v4l2_edid *kp, struct v4l2_edid32 __user *up)
46162 get_user(tmp, &up->edid) ||
46163 copy_from_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
46164 return -EFAULT;
46165- kp->edid = (__force u8 *)compat_ptr(tmp);
46166+ kp->edid = (__force_kernel u8 *)compat_ptr(tmp);
46167 return 0;
46168 }
46169
46170diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
46171index 015f92a..59e311e 100644
46172--- a/drivers/media/v4l2-core/v4l2-device.c
46173+++ b/drivers/media/v4l2-core/v4l2-device.c
46174@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
46175 EXPORT_SYMBOL_GPL(v4l2_device_put);
46176
46177 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
46178- atomic_t *instance)
46179+ atomic_unchecked_t *instance)
46180 {
46181- int num = atomic_inc_return(instance) - 1;
46182+ int num = atomic_inc_return_unchecked(instance) - 1;
46183 int len = strlen(basename);
46184
46185 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
46186diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
46187index 9ccb19a..d131468 100644
46188--- a/drivers/media/v4l2-core/v4l2-ioctl.c
46189+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
46190@@ -2142,7 +2142,8 @@ struct v4l2_ioctl_info {
46191 struct file *file, void *fh, void *p);
46192 } u;
46193 void (*debug)(const void *arg, bool write_only);
46194-};
46195+} __do_const;
46196+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
46197
46198 /* This control needs a priority check */
46199 #define INFO_FL_PRIO (1 << 0)
46200@@ -2326,7 +2327,7 @@ static long __video_do_ioctl(struct file *file,
46201 struct video_device *vfd = video_devdata(file);
46202 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
46203 bool write_only = false;
46204- struct v4l2_ioctl_info default_info;
46205+ v4l2_ioctl_info_no_const default_info;
46206 const struct v4l2_ioctl_info *info;
46207 void *fh = file->private_data;
46208 struct v4l2_fh *vfh = NULL;
46209@@ -2413,7 +2414,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46210 ret = -EINVAL;
46211 break;
46212 }
46213- *user_ptr = (void __user *)buf->m.planes;
46214+ *user_ptr = (void __force_user *)buf->m.planes;
46215 *kernel_ptr = (void **)&buf->m.planes;
46216 *array_size = sizeof(struct v4l2_plane) * buf->length;
46217 ret = 1;
46218@@ -2430,7 +2431,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46219 ret = -EINVAL;
46220 break;
46221 }
46222- *user_ptr = (void __user *)edid->edid;
46223+ *user_ptr = (void __force_user *)edid->edid;
46224 *kernel_ptr = (void **)&edid->edid;
46225 *array_size = edid->blocks * 128;
46226 ret = 1;
46227@@ -2448,7 +2449,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46228 ret = -EINVAL;
46229 break;
46230 }
46231- *user_ptr = (void __user *)ctrls->controls;
46232+ *user_ptr = (void __force_user *)ctrls->controls;
46233 *kernel_ptr = (void **)&ctrls->controls;
46234 *array_size = sizeof(struct v4l2_ext_control)
46235 * ctrls->count;
46236@@ -2549,7 +2550,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
46237 }
46238
46239 if (has_array_args) {
46240- *kernel_ptr = (void __force *)user_ptr;
46241+ *kernel_ptr = (void __force_kernel *)user_ptr;
46242 if (copy_to_user(user_ptr, mbuf, array_size))
46243 err = -EFAULT;
46244 goto out_array_args;
46245diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
46246index 187f836..679544b 100644
46247--- a/drivers/message/fusion/mptbase.c
46248+++ b/drivers/message/fusion/mptbase.c
46249@@ -6746,8 +6746,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
46250 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
46251 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
46252
46253+#ifdef CONFIG_GRKERNSEC_HIDESYM
46254+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
46255+#else
46256 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
46257 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
46258+#endif
46259+
46260 /*
46261 * Rounding UP to nearest 4-kB boundary here...
46262 */
46263@@ -6760,7 +6765,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
46264 ioc->facts.GlobalCredits);
46265
46266 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
46267+#ifdef CONFIG_GRKERNSEC_HIDESYM
46268+ NULL, NULL);
46269+#else
46270 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
46271+#endif
46272 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
46273 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
46274 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
46275diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
46276index 0707fa2..70ca794 100644
46277--- a/drivers/message/fusion/mptsas.c
46278+++ b/drivers/message/fusion/mptsas.c
46279@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
46280 return 0;
46281 }
46282
46283+static inline void
46284+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
46285+{
46286+ if (phy_info->port_details) {
46287+ phy_info->port_details->rphy = rphy;
46288+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
46289+ ioc->name, rphy));
46290+ }
46291+
46292+ if (rphy) {
46293+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
46294+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
46295+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
46296+ ioc->name, rphy, rphy->dev.release));
46297+ }
46298+}
46299+
46300 /* no mutex */
46301 static void
46302 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
46303@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
46304 return NULL;
46305 }
46306
46307-static inline void
46308-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
46309-{
46310- if (phy_info->port_details) {
46311- phy_info->port_details->rphy = rphy;
46312- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
46313- ioc->name, rphy));
46314- }
46315-
46316- if (rphy) {
46317- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
46318- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
46319- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
46320- ioc->name, rphy, rphy->dev.release));
46321- }
46322-}
46323-
46324 static inline struct sas_port *
46325 mptsas_get_port(struct mptsas_phyinfo *phy_info)
46326 {
46327diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
46328index b7d87cd..3fb36da 100644
46329--- a/drivers/message/i2o/i2o_proc.c
46330+++ b/drivers/message/i2o/i2o_proc.c
46331@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
46332 "Array Controller Device"
46333 };
46334
46335-static char *chtostr(char *tmp, u8 *chars, int n)
46336-{
46337- tmp[0] = 0;
46338- return strncat(tmp, (char *)chars, n);
46339-}
46340-
46341 static int i2o_report_query_status(struct seq_file *seq, int block_status,
46342 char *group)
46343 {
46344@@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
46345 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
46346 {
46347 struct i2o_controller *c = (struct i2o_controller *)seq->private;
46348- static u32 work32[5];
46349- static u8 *work8 = (u8 *) work32;
46350- static u16 *work16 = (u16 *) work32;
46351+ u32 work32[5];
46352+ u8 *work8 = (u8 *) work32;
46353+ u16 *work16 = (u16 *) work32;
46354 int token;
46355 u32 hwcap;
46356
46357@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
46358 } *result;
46359
46360 i2o_exec_execute_ddm_table ddm_table;
46361- char tmp[28 + 1];
46362
46363 result = kmalloc(sizeof(*result), GFP_KERNEL);
46364 if (!result)
46365@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
46366
46367 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
46368 seq_printf(seq, "%-#8x", ddm_table.module_id);
46369- seq_printf(seq, "%-29s",
46370- chtostr(tmp, ddm_table.module_name_version, 28));
46371+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
46372 seq_printf(seq, "%9d ", ddm_table.data_size);
46373 seq_printf(seq, "%8d", ddm_table.code_size);
46374
46375@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
46376
46377 i2o_driver_result_table *result;
46378 i2o_driver_store_table *dst;
46379- char tmp[28 + 1];
46380
46381 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
46382 if (result == NULL)
46383@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
46384
46385 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
46386 seq_printf(seq, "%-#8x", dst->module_id);
46387- seq_printf(seq, "%-29s",
46388- chtostr(tmp, dst->module_name_version, 28));
46389- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
46390+ seq_printf(seq, "%-.28s", dst->module_name_version);
46391+ seq_printf(seq, "%-.8s", dst->date);
46392 seq_printf(seq, "%8d ", dst->module_size);
46393 seq_printf(seq, "%8d ", dst->mpb_size);
46394 seq_printf(seq, "0x%04x", dst->module_flags);
46395@@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
46396 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
46397 {
46398 struct i2o_device *d = (struct i2o_device *)seq->private;
46399- static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
46400+ u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
46401 // == (allow) 512d bytes (max)
46402- static u16 *work16 = (u16 *) work32;
46403+ u16 *work16 = (u16 *) work32;
46404 int token;
46405- char tmp[16 + 1];
46406
46407 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
46408
46409@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
46410 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
46411 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
46412 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
46413- seq_printf(seq, "Vendor info : %s\n",
46414- chtostr(tmp, (u8 *) (work32 + 2), 16));
46415- seq_printf(seq, "Product info : %s\n",
46416- chtostr(tmp, (u8 *) (work32 + 6), 16));
46417- seq_printf(seq, "Description : %s\n",
46418- chtostr(tmp, (u8 *) (work32 + 10), 16));
46419- seq_printf(seq, "Product rev. : %s\n",
46420- chtostr(tmp, (u8 *) (work32 + 14), 8));
46421+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
46422+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
46423+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
46424+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
46425
46426 seq_printf(seq, "Serial number : ");
46427 print_serial_number(seq, (u8 *) (work32 + 16),
46428@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
46429 u8 pad[256]; // allow up to 256 byte (max) serial number
46430 } result;
46431
46432- char tmp[24 + 1];
46433-
46434 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
46435
46436 if (token < 0) {
46437@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
46438 }
46439
46440 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
46441- seq_printf(seq, "Module name : %s\n",
46442- chtostr(tmp, result.module_name, 24));
46443- seq_printf(seq, "Module revision : %s\n",
46444- chtostr(tmp, result.module_rev, 8));
46445+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
46446+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
46447
46448 seq_printf(seq, "Serial number : ");
46449 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
46450@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46451 u8 instance_number[4];
46452 } result;
46453
46454- char tmp[64 + 1];
46455-
46456 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
46457
46458 if (token < 0) {
46459@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46460 return 0;
46461 }
46462
46463- seq_printf(seq, "Device name : %s\n",
46464- chtostr(tmp, result.device_name, 64));
46465- seq_printf(seq, "Service name : %s\n",
46466- chtostr(tmp, result.service_name, 64));
46467- seq_printf(seq, "Physical name : %s\n",
46468- chtostr(tmp, result.physical_location, 64));
46469- seq_printf(seq, "Instance number : %s\n",
46470- chtostr(tmp, result.instance_number, 4));
46471+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
46472+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
46473+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
46474+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
46475
46476 return 0;
46477 }
46478@@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46479 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
46480 {
46481 struct i2o_device *d = (struct i2o_device *)seq->private;
46482- static u32 work32[12];
46483- static u16 *work16 = (u16 *) work32;
46484- static u8 *work8 = (u8 *) work32;
46485+ u32 work32[12];
46486+ u16 *work16 = (u16 *) work32;
46487+ u8 *work8 = (u8 *) work32;
46488 int token;
46489
46490 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
46491diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
46492index 92752fb..a7494f6 100644
46493--- a/drivers/message/i2o/iop.c
46494+++ b/drivers/message/i2o/iop.c
46495@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
46496
46497 spin_lock_irqsave(&c->context_list_lock, flags);
46498
46499- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
46500- atomic_inc(&c->context_list_counter);
46501+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
46502+ atomic_inc_unchecked(&c->context_list_counter);
46503
46504- entry->context = atomic_read(&c->context_list_counter);
46505+ entry->context = atomic_read_unchecked(&c->context_list_counter);
46506
46507 list_add(&entry->list, &c->context_list);
46508
46509@@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
46510
46511 #if BITS_PER_LONG == 64
46512 spin_lock_init(&c->context_list_lock);
46513- atomic_set(&c->context_list_counter, 0);
46514+ atomic_set_unchecked(&c->context_list_counter, 0);
46515 INIT_LIST_HEAD(&c->context_list);
46516 #endif
46517
46518diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
46519index b2c7e3b..85aa4764 100644
46520--- a/drivers/mfd/ab8500-debugfs.c
46521+++ b/drivers/mfd/ab8500-debugfs.c
46522@@ -100,7 +100,7 @@ static int irq_last;
46523 static u32 *irq_count;
46524 static int num_irqs;
46525
46526-static struct device_attribute **dev_attr;
46527+static device_attribute_no_const **dev_attr;
46528 static char **event_name;
46529
46530 static u8 avg_sample = SAMPLE_16;
46531diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
46532index c880c89..45a7c68 100644
46533--- a/drivers/mfd/max8925-i2c.c
46534+++ b/drivers/mfd/max8925-i2c.c
46535@@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
46536 const struct i2c_device_id *id)
46537 {
46538 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
46539- static struct max8925_chip *chip;
46540+ struct max8925_chip *chip;
46541 struct device_node *node = client->dev.of_node;
46542
46543 if (node && !pdata) {
46544diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
46545index 7612d89..70549c2 100644
46546--- a/drivers/mfd/tps65910.c
46547+++ b/drivers/mfd/tps65910.c
46548@@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
46549 struct tps65910_platform_data *pdata)
46550 {
46551 int ret = 0;
46552- static struct regmap_irq_chip *tps6591x_irqs_chip;
46553+ struct regmap_irq_chip *tps6591x_irqs_chip;
46554
46555 if (!irq) {
46556 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
46557diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
46558index 1b772ef..01e77d33 100644
46559--- a/drivers/mfd/twl4030-irq.c
46560+++ b/drivers/mfd/twl4030-irq.c
46561@@ -34,6 +34,7 @@
46562 #include <linux/of.h>
46563 #include <linux/irqdomain.h>
46564 #include <linux/i2c/twl.h>
46565+#include <asm/pgtable.h>
46566
46567 #include "twl-core.h"
46568
46569@@ -729,10 +730,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
46570 * Install an irq handler for each of the SIH modules;
46571 * clone dummy irq_chip since PIH can't *do* anything
46572 */
46573- twl4030_irq_chip = dummy_irq_chip;
46574- twl4030_irq_chip.name = "twl4030";
46575+ pax_open_kernel();
46576+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
46577+ *(const char **)&twl4030_irq_chip.name = "twl4030";
46578
46579- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
46580+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
46581+ pax_close_kernel();
46582
46583 for (i = irq_base; i < irq_end; i++) {
46584 irq_set_chip_and_handler(i, &twl4030_irq_chip,
46585diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
46586index 464419b..64bae8d 100644
46587--- a/drivers/misc/c2port/core.c
46588+++ b/drivers/misc/c2port/core.c
46589@@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
46590 goto error_idr_alloc;
46591 c2dev->id = ret;
46592
46593- bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
46594+ pax_open_kernel();
46595+ *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
46596+ pax_close_kernel();
46597
46598 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
46599 "c2port%d", c2dev->id);
46600diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
46601index 3f2b625..945e179 100644
46602--- a/drivers/misc/eeprom/sunxi_sid.c
46603+++ b/drivers/misc/eeprom/sunxi_sid.c
46604@@ -126,7 +126,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
46605
46606 platform_set_drvdata(pdev, sid_data);
46607
46608- sid_bin_attr.size = sid_data->keysize;
46609+ pax_open_kernel();
46610+ *(size_t *)&sid_bin_attr.size = sid_data->keysize;
46611+ pax_close_kernel();
46612 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
46613 return -ENODEV;
46614
46615diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
46616index 36f5d52..32311c3 100644
46617--- a/drivers/misc/kgdbts.c
46618+++ b/drivers/misc/kgdbts.c
46619@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
46620 char before[BREAK_INSTR_SIZE];
46621 char after[BREAK_INSTR_SIZE];
46622
46623- probe_kernel_read(before, (char *)kgdbts_break_test,
46624+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
46625 BREAK_INSTR_SIZE);
46626 init_simple_test();
46627 ts.tst = plant_and_detach_test;
46628@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
46629 /* Activate test with initial breakpoint */
46630 if (!is_early)
46631 kgdb_breakpoint();
46632- probe_kernel_read(after, (char *)kgdbts_break_test,
46633+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
46634 BREAK_INSTR_SIZE);
46635 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
46636 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
46637diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
46638index 3ef4627..8d00486 100644
46639--- a/drivers/misc/lis3lv02d/lis3lv02d.c
46640+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
46641@@ -497,7 +497,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
46642 * the lid is closed. This leads to interrupts as soon as a little move
46643 * is done.
46644 */
46645- atomic_inc(&lis3->count);
46646+ atomic_inc_unchecked(&lis3->count);
46647
46648 wake_up_interruptible(&lis3->misc_wait);
46649 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
46650@@ -583,7 +583,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
46651 if (lis3->pm_dev)
46652 pm_runtime_get_sync(lis3->pm_dev);
46653
46654- atomic_set(&lis3->count, 0);
46655+ atomic_set_unchecked(&lis3->count, 0);
46656 return 0;
46657 }
46658
46659@@ -615,7 +615,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
46660 add_wait_queue(&lis3->misc_wait, &wait);
46661 while (true) {
46662 set_current_state(TASK_INTERRUPTIBLE);
46663- data = atomic_xchg(&lis3->count, 0);
46664+ data = atomic_xchg_unchecked(&lis3->count, 0);
46665 if (data)
46666 break;
46667
46668@@ -656,7 +656,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
46669 struct lis3lv02d, miscdev);
46670
46671 poll_wait(file, &lis3->misc_wait, wait);
46672- if (atomic_read(&lis3->count))
46673+ if (atomic_read_unchecked(&lis3->count))
46674 return POLLIN | POLLRDNORM;
46675 return 0;
46676 }
46677diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
46678index c439c82..1f20f57 100644
46679--- a/drivers/misc/lis3lv02d/lis3lv02d.h
46680+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
46681@@ -297,7 +297,7 @@ struct lis3lv02d {
46682 struct input_polled_dev *idev; /* input device */
46683 struct platform_device *pdev; /* platform device */
46684 struct regulator_bulk_data regulators[2];
46685- atomic_t count; /* interrupt count after last read */
46686+ atomic_unchecked_t count; /* interrupt count after last read */
46687 union axis_conversion ac; /* hw -> logical axis */
46688 int mapped_btns[3];
46689
46690diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
46691index 2f30bad..c4c13d0 100644
46692--- a/drivers/misc/sgi-gru/gruhandles.c
46693+++ b/drivers/misc/sgi-gru/gruhandles.c
46694@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
46695 unsigned long nsec;
46696
46697 nsec = CLKS2NSEC(clks);
46698- atomic_long_inc(&mcs_op_statistics[op].count);
46699- atomic_long_add(nsec, &mcs_op_statistics[op].total);
46700+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
46701+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
46702 if (mcs_op_statistics[op].max < nsec)
46703 mcs_op_statistics[op].max = nsec;
46704 }
46705diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
46706index 4f76359..cdfcb2e 100644
46707--- a/drivers/misc/sgi-gru/gruprocfs.c
46708+++ b/drivers/misc/sgi-gru/gruprocfs.c
46709@@ -32,9 +32,9 @@
46710
46711 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
46712
46713-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
46714+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
46715 {
46716- unsigned long val = atomic_long_read(v);
46717+ unsigned long val = atomic_long_read_unchecked(v);
46718
46719 seq_printf(s, "%16lu %s\n", val, id);
46720 }
46721@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
46722
46723 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
46724 for (op = 0; op < mcsop_last; op++) {
46725- count = atomic_long_read(&mcs_op_statistics[op].count);
46726- total = atomic_long_read(&mcs_op_statistics[op].total);
46727+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
46728+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
46729 max = mcs_op_statistics[op].max;
46730 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
46731 count ? total / count : 0, max);
46732diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
46733index 5c3ce24..4915ccb 100644
46734--- a/drivers/misc/sgi-gru/grutables.h
46735+++ b/drivers/misc/sgi-gru/grutables.h
46736@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
46737 * GRU statistics.
46738 */
46739 struct gru_stats_s {
46740- atomic_long_t vdata_alloc;
46741- atomic_long_t vdata_free;
46742- atomic_long_t gts_alloc;
46743- atomic_long_t gts_free;
46744- atomic_long_t gms_alloc;
46745- atomic_long_t gms_free;
46746- atomic_long_t gts_double_allocate;
46747- atomic_long_t assign_context;
46748- atomic_long_t assign_context_failed;
46749- atomic_long_t free_context;
46750- atomic_long_t load_user_context;
46751- atomic_long_t load_kernel_context;
46752- atomic_long_t lock_kernel_context;
46753- atomic_long_t unlock_kernel_context;
46754- atomic_long_t steal_user_context;
46755- atomic_long_t steal_kernel_context;
46756- atomic_long_t steal_context_failed;
46757- atomic_long_t nopfn;
46758- atomic_long_t asid_new;
46759- atomic_long_t asid_next;
46760- atomic_long_t asid_wrap;
46761- atomic_long_t asid_reuse;
46762- atomic_long_t intr;
46763- atomic_long_t intr_cbr;
46764- atomic_long_t intr_tfh;
46765- atomic_long_t intr_spurious;
46766- atomic_long_t intr_mm_lock_failed;
46767- atomic_long_t call_os;
46768- atomic_long_t call_os_wait_queue;
46769- atomic_long_t user_flush_tlb;
46770- atomic_long_t user_unload_context;
46771- atomic_long_t user_exception;
46772- atomic_long_t set_context_option;
46773- atomic_long_t check_context_retarget_intr;
46774- atomic_long_t check_context_unload;
46775- atomic_long_t tlb_dropin;
46776- atomic_long_t tlb_preload_page;
46777- atomic_long_t tlb_dropin_fail_no_asid;
46778- atomic_long_t tlb_dropin_fail_upm;
46779- atomic_long_t tlb_dropin_fail_invalid;
46780- atomic_long_t tlb_dropin_fail_range_active;
46781- atomic_long_t tlb_dropin_fail_idle;
46782- atomic_long_t tlb_dropin_fail_fmm;
46783- atomic_long_t tlb_dropin_fail_no_exception;
46784- atomic_long_t tfh_stale_on_fault;
46785- atomic_long_t mmu_invalidate_range;
46786- atomic_long_t mmu_invalidate_page;
46787- atomic_long_t flush_tlb;
46788- atomic_long_t flush_tlb_gru;
46789- atomic_long_t flush_tlb_gru_tgh;
46790- atomic_long_t flush_tlb_gru_zero_asid;
46791+ atomic_long_unchecked_t vdata_alloc;
46792+ atomic_long_unchecked_t vdata_free;
46793+ atomic_long_unchecked_t gts_alloc;
46794+ atomic_long_unchecked_t gts_free;
46795+ atomic_long_unchecked_t gms_alloc;
46796+ atomic_long_unchecked_t gms_free;
46797+ atomic_long_unchecked_t gts_double_allocate;
46798+ atomic_long_unchecked_t assign_context;
46799+ atomic_long_unchecked_t assign_context_failed;
46800+ atomic_long_unchecked_t free_context;
46801+ atomic_long_unchecked_t load_user_context;
46802+ atomic_long_unchecked_t load_kernel_context;
46803+ atomic_long_unchecked_t lock_kernel_context;
46804+ atomic_long_unchecked_t unlock_kernel_context;
46805+ atomic_long_unchecked_t steal_user_context;
46806+ atomic_long_unchecked_t steal_kernel_context;
46807+ atomic_long_unchecked_t steal_context_failed;
46808+ atomic_long_unchecked_t nopfn;
46809+ atomic_long_unchecked_t asid_new;
46810+ atomic_long_unchecked_t asid_next;
46811+ atomic_long_unchecked_t asid_wrap;
46812+ atomic_long_unchecked_t asid_reuse;
46813+ atomic_long_unchecked_t intr;
46814+ atomic_long_unchecked_t intr_cbr;
46815+ atomic_long_unchecked_t intr_tfh;
46816+ atomic_long_unchecked_t intr_spurious;
46817+ atomic_long_unchecked_t intr_mm_lock_failed;
46818+ atomic_long_unchecked_t call_os;
46819+ atomic_long_unchecked_t call_os_wait_queue;
46820+ atomic_long_unchecked_t user_flush_tlb;
46821+ atomic_long_unchecked_t user_unload_context;
46822+ atomic_long_unchecked_t user_exception;
46823+ atomic_long_unchecked_t set_context_option;
46824+ atomic_long_unchecked_t check_context_retarget_intr;
46825+ atomic_long_unchecked_t check_context_unload;
46826+ atomic_long_unchecked_t tlb_dropin;
46827+ atomic_long_unchecked_t tlb_preload_page;
46828+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
46829+ atomic_long_unchecked_t tlb_dropin_fail_upm;
46830+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
46831+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
46832+ atomic_long_unchecked_t tlb_dropin_fail_idle;
46833+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
46834+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
46835+ atomic_long_unchecked_t tfh_stale_on_fault;
46836+ atomic_long_unchecked_t mmu_invalidate_range;
46837+ atomic_long_unchecked_t mmu_invalidate_page;
46838+ atomic_long_unchecked_t flush_tlb;
46839+ atomic_long_unchecked_t flush_tlb_gru;
46840+ atomic_long_unchecked_t flush_tlb_gru_tgh;
46841+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
46842
46843- atomic_long_t copy_gpa;
46844- atomic_long_t read_gpa;
46845+ atomic_long_unchecked_t copy_gpa;
46846+ atomic_long_unchecked_t read_gpa;
46847
46848- atomic_long_t mesq_receive;
46849- atomic_long_t mesq_receive_none;
46850- atomic_long_t mesq_send;
46851- atomic_long_t mesq_send_failed;
46852- atomic_long_t mesq_noop;
46853- atomic_long_t mesq_send_unexpected_error;
46854- atomic_long_t mesq_send_lb_overflow;
46855- atomic_long_t mesq_send_qlimit_reached;
46856- atomic_long_t mesq_send_amo_nacked;
46857- atomic_long_t mesq_send_put_nacked;
46858- atomic_long_t mesq_page_overflow;
46859- atomic_long_t mesq_qf_locked;
46860- atomic_long_t mesq_qf_noop_not_full;
46861- atomic_long_t mesq_qf_switch_head_failed;
46862- atomic_long_t mesq_qf_unexpected_error;
46863- atomic_long_t mesq_noop_unexpected_error;
46864- atomic_long_t mesq_noop_lb_overflow;
46865- atomic_long_t mesq_noop_qlimit_reached;
46866- atomic_long_t mesq_noop_amo_nacked;
46867- atomic_long_t mesq_noop_put_nacked;
46868- atomic_long_t mesq_noop_page_overflow;
46869+ atomic_long_unchecked_t mesq_receive;
46870+ atomic_long_unchecked_t mesq_receive_none;
46871+ atomic_long_unchecked_t mesq_send;
46872+ atomic_long_unchecked_t mesq_send_failed;
46873+ atomic_long_unchecked_t mesq_noop;
46874+ atomic_long_unchecked_t mesq_send_unexpected_error;
46875+ atomic_long_unchecked_t mesq_send_lb_overflow;
46876+ atomic_long_unchecked_t mesq_send_qlimit_reached;
46877+ atomic_long_unchecked_t mesq_send_amo_nacked;
46878+ atomic_long_unchecked_t mesq_send_put_nacked;
46879+ atomic_long_unchecked_t mesq_page_overflow;
46880+ atomic_long_unchecked_t mesq_qf_locked;
46881+ atomic_long_unchecked_t mesq_qf_noop_not_full;
46882+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
46883+ atomic_long_unchecked_t mesq_qf_unexpected_error;
46884+ atomic_long_unchecked_t mesq_noop_unexpected_error;
46885+ atomic_long_unchecked_t mesq_noop_lb_overflow;
46886+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
46887+ atomic_long_unchecked_t mesq_noop_amo_nacked;
46888+ atomic_long_unchecked_t mesq_noop_put_nacked;
46889+ atomic_long_unchecked_t mesq_noop_page_overflow;
46890
46891 };
46892
46893@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
46894 tghop_invalidate, mcsop_last};
46895
46896 struct mcs_op_statistic {
46897- atomic_long_t count;
46898- atomic_long_t total;
46899+ atomic_long_unchecked_t count;
46900+ atomic_long_unchecked_t total;
46901 unsigned long max;
46902 };
46903
46904@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
46905
46906 #define STAT(id) do { \
46907 if (gru_options & OPT_STATS) \
46908- atomic_long_inc(&gru_stats.id); \
46909+ atomic_long_inc_unchecked(&gru_stats.id); \
46910 } while (0)
46911
46912 #ifdef CONFIG_SGI_GRU_DEBUG
46913diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
46914index c862cd4..0d176fe 100644
46915--- a/drivers/misc/sgi-xp/xp.h
46916+++ b/drivers/misc/sgi-xp/xp.h
46917@@ -288,7 +288,7 @@ struct xpc_interface {
46918 xpc_notify_func, void *);
46919 void (*received) (short, int, void *);
46920 enum xp_retval (*partid_to_nasids) (short, void *);
46921-};
46922+} __no_const;
46923
46924 extern struct xpc_interface xpc_interface;
46925
46926diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
46927index 01be66d..e3a0c7e 100644
46928--- a/drivers/misc/sgi-xp/xp_main.c
46929+++ b/drivers/misc/sgi-xp/xp_main.c
46930@@ -78,13 +78,13 @@ xpc_notloaded(void)
46931 }
46932
46933 struct xpc_interface xpc_interface = {
46934- (void (*)(int))xpc_notloaded,
46935- (void (*)(int))xpc_notloaded,
46936- (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
46937- (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
46938+ .connect = (void (*)(int))xpc_notloaded,
46939+ .disconnect = (void (*)(int))xpc_notloaded,
46940+ .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
46941+ .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
46942 void *))xpc_notloaded,
46943- (void (*)(short, int, void *))xpc_notloaded,
46944- (enum xp_retval(*)(short, void *))xpc_notloaded
46945+ .received = (void (*)(short, int, void *))xpc_notloaded,
46946+ .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
46947 };
46948 EXPORT_SYMBOL_GPL(xpc_interface);
46949
46950diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
46951index b94d5f7..7f494c5 100644
46952--- a/drivers/misc/sgi-xp/xpc.h
46953+++ b/drivers/misc/sgi-xp/xpc.h
46954@@ -835,6 +835,7 @@ struct xpc_arch_operations {
46955 void (*received_payload) (struct xpc_channel *, void *);
46956 void (*notify_senders_of_disconnect) (struct xpc_channel *);
46957 };
46958+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
46959
46960 /* struct xpc_partition act_state values (for XPC HB) */
46961
46962@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
46963 /* found in xpc_main.c */
46964 extern struct device *xpc_part;
46965 extern struct device *xpc_chan;
46966-extern struct xpc_arch_operations xpc_arch_ops;
46967+extern xpc_arch_operations_no_const xpc_arch_ops;
46968 extern int xpc_disengage_timelimit;
46969 extern int xpc_disengage_timedout;
46970 extern int xpc_activate_IRQ_rcvd;
46971diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
46972index 82dc574..8539ab2 100644
46973--- a/drivers/misc/sgi-xp/xpc_main.c
46974+++ b/drivers/misc/sgi-xp/xpc_main.c
46975@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
46976 .notifier_call = xpc_system_die,
46977 };
46978
46979-struct xpc_arch_operations xpc_arch_ops;
46980+xpc_arch_operations_no_const xpc_arch_ops;
46981
46982 /*
46983 * Timer function to enforce the timelimit on the partition disengage.
46984@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
46985
46986 if (((die_args->trapnr == X86_TRAP_MF) ||
46987 (die_args->trapnr == X86_TRAP_XF)) &&
46988- !user_mode_vm(die_args->regs))
46989+ !user_mode(die_args->regs))
46990 xpc_die_deactivate();
46991
46992 break;
46993diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
46994index 1fa4c80..59447c9 100644
46995--- a/drivers/mmc/card/block.c
46996+++ b/drivers/mmc/card/block.c
46997@@ -574,7 +574,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
46998 if (idata->ic.postsleep_min_us)
46999 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
47000
47001- if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
47002+ if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
47003 err = -EFAULT;
47004 goto cmd_rel_host;
47005 }
47006diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
47007index 7911e05..d0f9dda 100644
47008--- a/drivers/mmc/core/mmc_ops.c
47009+++ b/drivers/mmc/core/mmc_ops.c
47010@@ -267,7 +267,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
47011 void *data_buf;
47012 int is_on_stack;
47013
47014- is_on_stack = object_is_on_stack(buf);
47015+ is_on_stack = object_starts_on_stack(buf);
47016 if (is_on_stack) {
47017 /*
47018 * dma onto stack is unsafe/nonportable, but callers to this
47019diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
47020index 01b99e8..5c325e3 100644
47021--- a/drivers/mmc/host/dw_mmc.h
47022+++ b/drivers/mmc/host/dw_mmc.h
47023@@ -265,5 +265,5 @@ struct dw_mci_drv_data {
47024 int (*parse_dt)(struct dw_mci *host);
47025 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
47026 struct dw_mci_tuning_data *tuning_data);
47027-};
47028+} __do_const;
47029 #endif /* _DW_MMC_H_ */
47030diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
47031index 43af791..86f4c48 100644
47032--- a/drivers/mmc/host/mmci.c
47033+++ b/drivers/mmc/host/mmci.c
47034@@ -1628,7 +1628,9 @@ static int mmci_probe(struct amba_device *dev,
47035 mmc->caps |= MMC_CAP_CMD23;
47036
47037 if (variant->busy_detect) {
47038- mmci_ops.card_busy = mmci_card_busy;
47039+ pax_open_kernel();
47040+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
47041+ pax_close_kernel();
47042 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
47043 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
47044 mmc->max_busy_timeout = 0;
47045diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
47046index df27bb4..2085f0b 100644
47047--- a/drivers/mmc/host/omap_hsmmc.c
47048+++ b/drivers/mmc/host/omap_hsmmc.c
47049@@ -2111,7 +2111,9 @@ static int omap_hsmmc_probe(struct platform_device *pdev)
47050
47051 if (host->pdata->controller_flags & OMAP_HSMMC_BROKEN_MULTIBLOCK_READ) {
47052 dev_info(&pdev->dev, "multiblock reads disabled due to 35xx erratum 2.1.1.128; MMC read performance may suffer\n");
47053- omap_hsmmc_ops.multi_io_quirk = omap_hsmmc_multi_io_quirk;
47054+ pax_open_kernel();
47055+ *(void **)&omap_hsmmc_ops.multi_io_quirk = omap_hsmmc_multi_io_quirk;
47056+ pax_close_kernel();
47057 }
47058
47059 pm_runtime_enable(host->dev);
47060diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
47061index 587ee0e..b3bbcab 100644
47062--- a/drivers/mmc/host/sdhci-esdhc-imx.c
47063+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
47064@@ -1054,9 +1054,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
47065 host->mmc->caps |= MMC_CAP_1_8V_DDR;
47066 }
47067
47068- if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
47069- sdhci_esdhc_ops.platform_execute_tuning =
47070+ if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
47071+ pax_open_kernel();
47072+ *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
47073 esdhc_executing_tuning;
47074+ pax_close_kernel();
47075+ }
47076
47077 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
47078 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
47079diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
47080index 0ce6eb1..8dcce1b 100644
47081--- a/drivers/mmc/host/sdhci-s3c.c
47082+++ b/drivers/mmc/host/sdhci-s3c.c
47083@@ -584,9 +584,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
47084 * we can use overriding functions instead of default.
47085 */
47086 if (sc->no_divider) {
47087- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
47088- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
47089- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
47090+ pax_open_kernel();
47091+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
47092+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
47093+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
47094+ pax_close_kernel();
47095 }
47096
47097 /* It supports additional host capabilities if needed */
47098diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
47099index 423666b..81ff5eb 100644
47100--- a/drivers/mtd/chips/cfi_cmdset_0020.c
47101+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
47102@@ -666,7 +666,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
47103 size_t totlen = 0, thislen;
47104 int ret = 0;
47105 size_t buflen = 0;
47106- static char *buffer;
47107+ char *buffer;
47108
47109 if (!ECCBUF_SIZE) {
47110 /* We should fall back to a general writev implementation.
47111diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
47112index b3b7ca1..5dd4634 100644
47113--- a/drivers/mtd/nand/denali.c
47114+++ b/drivers/mtd/nand/denali.c
47115@@ -24,6 +24,7 @@
47116 #include <linux/slab.h>
47117 #include <linux/mtd/mtd.h>
47118 #include <linux/module.h>
47119+#include <linux/slab.h>
47120
47121 #include "denali.h"
47122
47123diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47124index 959cb9b..8520fe5 100644
47125--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47126+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47127@@ -386,7 +386,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
47128
47129 /* first try to map the upper buffer directly */
47130 if (virt_addr_valid(this->upper_buf) &&
47131- !object_is_on_stack(this->upper_buf)) {
47132+ !object_starts_on_stack(this->upper_buf)) {
47133 sg_init_one(sgl, this->upper_buf, this->upper_len);
47134 ret = dma_map_sg(this->dev, sgl, 1, dr);
47135 if (ret == 0)
47136diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
47137index 51b9d6a..52af9a7 100644
47138--- a/drivers/mtd/nftlmount.c
47139+++ b/drivers/mtd/nftlmount.c
47140@@ -24,6 +24,7 @@
47141 #include <asm/errno.h>
47142 #include <linux/delay.h>
47143 #include <linux/slab.h>
47144+#include <linux/sched.h>
47145 #include <linux/mtd/mtd.h>
47146 #include <linux/mtd/nand.h>
47147 #include <linux/mtd/nftl.h>
47148diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
47149index c23184a..4115c41 100644
47150--- a/drivers/mtd/sm_ftl.c
47151+++ b/drivers/mtd/sm_ftl.c
47152@@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
47153 #define SM_CIS_VENDOR_OFFSET 0x59
47154 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
47155 {
47156- struct attribute_group *attr_group;
47157+ attribute_group_no_const *attr_group;
47158 struct attribute **attributes;
47159 struct sm_sysfs_attribute *vendor_attribute;
47160 char *vendor;
47161diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
47162index a5115fb..81b03f6 100644
47163--- a/drivers/net/bonding/bond_main.c
47164+++ b/drivers/net/bonding/bond_main.c
47165@@ -3749,7 +3749,7 @@ int bond_3ad_xor_xmit(struct sk_buff *skb, struct net_device *dev)
47166 bond_dev_queue_xmit(bond, skb, slave->dev);
47167 } else {
47168 dev_kfree_skb_any(skb);
47169- atomic_long_inc(&dev->tx_dropped);
47170+ atomic_long_inc_unchecked(&dev->tx_dropped);
47171 }
47172
47173 return NETDEV_TX_OK;
47174diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
47175index 45f09a6..f154f8d 100644
47176--- a/drivers/net/bonding/bond_netlink.c
47177+++ b/drivers/net/bonding/bond_netlink.c
47178@@ -585,7 +585,7 @@ nla_put_failure:
47179 return -EMSGSIZE;
47180 }
47181
47182-struct rtnl_link_ops bond_link_ops __read_mostly = {
47183+struct rtnl_link_ops bond_link_ops = {
47184 .kind = "bond",
47185 .priv_size = sizeof(struct bonding),
47186 .setup = bond_setup,
47187diff --git a/drivers/net/caif/caif_hsi.c b/drivers/net/caif/caif_hsi.c
47188index 5e40a8b..126bfda 100644
47189--- a/drivers/net/caif/caif_hsi.c
47190+++ b/drivers/net/caif/caif_hsi.c
47191@@ -1445,7 +1445,7 @@ err:
47192 return -ENODEV;
47193 }
47194
47195-static struct rtnl_link_ops caif_hsi_link_ops __read_mostly = {
47196+static struct rtnl_link_ops caif_hsi_link_ops = {
47197 .kind = "cfhsi",
47198 .priv_size = sizeof(struct cfhsi),
47199 .setup = cfhsi_setup,
47200diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
47201index 98d73aa..63ef9da 100644
47202--- a/drivers/net/can/Kconfig
47203+++ b/drivers/net/can/Kconfig
47204@@ -98,7 +98,7 @@ config CAN_JANZ_ICAN3
47205
47206 config CAN_FLEXCAN
47207 tristate "Support for Freescale FLEXCAN based chips"
47208- depends on ARM || PPC
47209+ depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
47210 ---help---
47211 Say Y here if you want to support for Freescale FlexCAN.
47212
47213diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
47214index 2cfe501..477d4b5 100644
47215--- a/drivers/net/can/dev.c
47216+++ b/drivers/net/can/dev.c
47217@@ -868,7 +868,7 @@ static int can_newlink(struct net *src_net, struct net_device *dev,
47218 return -EOPNOTSUPP;
47219 }
47220
47221-static struct rtnl_link_ops can_link_ops __read_mostly = {
47222+static struct rtnl_link_ops can_link_ops = {
47223 .kind = "can",
47224 .maxtype = IFLA_CAN_MAX,
47225 .policy = can_policy,
47226diff --git a/drivers/net/can/vcan.c b/drivers/net/can/vcan.c
47227index 4e94057..32032ff 100644
47228--- a/drivers/net/can/vcan.c
47229+++ b/drivers/net/can/vcan.c
47230@@ -166,7 +166,7 @@ static void vcan_setup(struct net_device *dev)
47231 dev->destructor = free_netdev;
47232 }
47233
47234-static struct rtnl_link_ops vcan_link_ops __read_mostly = {
47235+static struct rtnl_link_ops vcan_link_ops = {
47236 .kind = "vcan",
47237 .setup = vcan_setup,
47238 };
47239diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c
47240index ff435fb..d408b1f 100644
47241--- a/drivers/net/dummy.c
47242+++ b/drivers/net/dummy.c
47243@@ -149,7 +149,7 @@ static int dummy_validate(struct nlattr *tb[], struct nlattr *data[])
47244 return 0;
47245 }
47246
47247-static struct rtnl_link_ops dummy_link_ops __read_mostly = {
47248+static struct rtnl_link_ops dummy_link_ops = {
47249 .kind = "dummy",
47250 .setup = dummy_setup,
47251 .validate = dummy_validate,
47252diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
47253index 1d162cc..b546a75 100644
47254--- a/drivers/net/ethernet/8390/ax88796.c
47255+++ b/drivers/net/ethernet/8390/ax88796.c
47256@@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
47257 if (ax->plat->reg_offsets)
47258 ei_local->reg_offset = ax->plat->reg_offsets;
47259 else {
47260+ resource_size_t _mem_size = mem_size;
47261+ do_div(_mem_size, 0x18);
47262 ei_local->reg_offset = ax->reg_offsets;
47263 for (ret = 0; ret < 0x18; ret++)
47264- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
47265+ ax->reg_offsets[ret] = _mem_size * ret;
47266 }
47267
47268 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
47269diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
47270index 4efc435..4ab9e14 100644
47271--- a/drivers/net/ethernet/altera/altera_tse_main.c
47272+++ b/drivers/net/ethernet/altera/altera_tse_main.c
47273@@ -1224,7 +1224,7 @@ static int tse_shutdown(struct net_device *dev)
47274 return 0;
47275 }
47276
47277-static struct net_device_ops altera_tse_netdev_ops = {
47278+static net_device_ops_no_const altera_tse_netdev_ops __read_only = {
47279 .ndo_open = tse_open,
47280 .ndo_stop = tse_shutdown,
47281 .ndo_start_xmit = tse_start_xmit,
47282@@ -1461,11 +1461,13 @@ static int altera_tse_probe(struct platform_device *pdev)
47283 ndev->netdev_ops = &altera_tse_netdev_ops;
47284 altera_tse_set_ethtool_ops(ndev);
47285
47286+ pax_open_kernel();
47287 altera_tse_netdev_ops.ndo_set_rx_mode = tse_set_rx_mode;
47288
47289 if (priv->hash_filter)
47290 altera_tse_netdev_ops.ndo_set_rx_mode =
47291 tse_set_rx_mode_hashfilter;
47292+ pax_close_kernel();
47293
47294 /* Scatter/gather IO is not supported,
47295 * so it is turned off
47296diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-common.h b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47297index caade30..3e257d9 100644
47298--- a/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47299+++ b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47300@@ -1072,14 +1072,14 @@ do { \
47301 * operations, everything works on mask values.
47302 */
47303 #define XMDIO_READ(_pdata, _mmd, _reg) \
47304- ((_pdata)->hw_if.read_mmd_regs((_pdata), 0, \
47305+ ((_pdata)->hw_if->read_mmd_regs((_pdata), 0, \
47306 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff)))
47307
47308 #define XMDIO_READ_BITS(_pdata, _mmd, _reg, _mask) \
47309 (XMDIO_READ((_pdata), _mmd, _reg) & _mask)
47310
47311 #define XMDIO_WRITE(_pdata, _mmd, _reg, _val) \
47312- ((_pdata)->hw_if.write_mmd_regs((_pdata), 0, \
47313+ ((_pdata)->hw_if->write_mmd_regs((_pdata), 0, \
47314 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff), (_val)))
47315
47316 #define XMDIO_WRITE_BITS(_pdata, _mmd, _reg, _mask, _val) \
47317diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47318index 8a50b01..39c1ad0 100644
47319--- a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47320+++ b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47321@@ -187,7 +187,7 @@ static int xgbe_dcb_ieee_setets(struct net_device *netdev,
47322
47323 memcpy(pdata->ets, ets, sizeof(*pdata->ets));
47324
47325- pdata->hw_if.config_dcb_tc(pdata);
47326+ pdata->hw_if->config_dcb_tc(pdata);
47327
47328 return 0;
47329 }
47330@@ -226,7 +226,7 @@ static int xgbe_dcb_ieee_setpfc(struct net_device *netdev,
47331
47332 memcpy(pdata->pfc, pfc, sizeof(*pdata->pfc));
47333
47334- pdata->hw_if.config_dcb_pfc(pdata);
47335+ pdata->hw_if->config_dcb_pfc(pdata);
47336
47337 return 0;
47338 }
47339diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47340index 6fc5da0..61ac2cb 100644
47341--- a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47342+++ b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47343@@ -235,7 +235,7 @@ err_ring:
47344
47345 static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
47346 {
47347- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47348+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47349 struct xgbe_channel *channel;
47350 struct xgbe_ring *ring;
47351 struct xgbe_ring_data *rdata;
47352@@ -276,7 +276,7 @@ static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
47353
47354 static void xgbe_wrapper_rx_descriptor_init(struct xgbe_prv_data *pdata)
47355 {
47356- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47357+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47358 struct xgbe_channel *channel;
47359 struct xgbe_ring *ring;
47360 struct xgbe_ring_desc *rdesc;
47361@@ -505,7 +505,7 @@ err_out:
47362 static void xgbe_realloc_skb(struct xgbe_channel *channel)
47363 {
47364 struct xgbe_prv_data *pdata = channel->pdata;
47365- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47366+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47367 struct xgbe_ring *ring = channel->rx_ring;
47368 struct xgbe_ring_data *rdata;
47369 struct sk_buff *skb = NULL;
47370@@ -546,17 +546,12 @@ static void xgbe_realloc_skb(struct xgbe_channel *channel)
47371 DBGPR("<--xgbe_realloc_skb\n");
47372 }
47373
47374-void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *desc_if)
47375-{
47376- DBGPR("-->xgbe_init_function_ptrs_desc\n");
47377-
47378- desc_if->alloc_ring_resources = xgbe_alloc_ring_resources;
47379- desc_if->free_ring_resources = xgbe_free_ring_resources;
47380- desc_if->map_tx_skb = xgbe_map_tx_skb;
47381- desc_if->realloc_skb = xgbe_realloc_skb;
47382- desc_if->unmap_skb = xgbe_unmap_skb;
47383- desc_if->wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init;
47384- desc_if->wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init;
47385-
47386- DBGPR("<--xgbe_init_function_ptrs_desc\n");
47387-}
47388+const struct xgbe_desc_if default_xgbe_desc_if = {
47389+ .alloc_ring_resources = xgbe_alloc_ring_resources,
47390+ .free_ring_resources = xgbe_free_ring_resources,
47391+ .map_tx_skb = xgbe_map_tx_skb,
47392+ .realloc_skb = xgbe_realloc_skb,
47393+ .unmap_skb = xgbe_unmap_skb,
47394+ .wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init,
47395+ .wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init,
47396+};
47397diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47398index 9da3a03..022f15c 100644
47399--- a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47400+++ b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47401@@ -2462,7 +2462,7 @@ static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
47402
47403 static int xgbe_init(struct xgbe_prv_data *pdata)
47404 {
47405- struct xgbe_desc_if *desc_if = &pdata->desc_if;
47406+ struct xgbe_desc_if *desc_if = pdata->desc_if;
47407 int ret;
47408
47409 DBGPR("-->xgbe_init\n");
47410@@ -2524,101 +2524,96 @@ static int xgbe_init(struct xgbe_prv_data *pdata)
47411 return 0;
47412 }
47413
47414-void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
47415-{
47416- DBGPR("-->xgbe_init_function_ptrs\n");
47417-
47418- hw_if->tx_complete = xgbe_tx_complete;
47419-
47420- hw_if->set_promiscuous_mode = xgbe_set_promiscuous_mode;
47421- hw_if->set_all_multicast_mode = xgbe_set_all_multicast_mode;
47422- hw_if->add_mac_addresses = xgbe_add_mac_addresses;
47423- hw_if->set_mac_address = xgbe_set_mac_address;
47424-
47425- hw_if->enable_rx_csum = xgbe_enable_rx_csum;
47426- hw_if->disable_rx_csum = xgbe_disable_rx_csum;
47427-
47428- hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
47429- hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
47430- hw_if->enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering;
47431- hw_if->disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering;
47432- hw_if->update_vlan_hash_table = xgbe_update_vlan_hash_table;
47433-
47434- hw_if->read_mmd_regs = xgbe_read_mmd_regs;
47435- hw_if->write_mmd_regs = xgbe_write_mmd_regs;
47436-
47437- hw_if->set_gmii_speed = xgbe_set_gmii_speed;
47438- hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
47439- hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
47440-
47441- hw_if->enable_tx = xgbe_enable_tx;
47442- hw_if->disable_tx = xgbe_disable_tx;
47443- hw_if->enable_rx = xgbe_enable_rx;
47444- hw_if->disable_rx = xgbe_disable_rx;
47445-
47446- hw_if->powerup_tx = xgbe_powerup_tx;
47447- hw_if->powerdown_tx = xgbe_powerdown_tx;
47448- hw_if->powerup_rx = xgbe_powerup_rx;
47449- hw_if->powerdown_rx = xgbe_powerdown_rx;
47450-
47451- hw_if->pre_xmit = xgbe_pre_xmit;
47452- hw_if->dev_read = xgbe_dev_read;
47453- hw_if->enable_int = xgbe_enable_int;
47454- hw_if->disable_int = xgbe_disable_int;
47455- hw_if->init = xgbe_init;
47456- hw_if->exit = xgbe_exit;
47457+const struct xgbe_hw_if default_xgbe_hw_if = {
47458+ .tx_complete = xgbe_tx_complete,
47459+
47460+ .set_promiscuous_mode = xgbe_set_promiscuous_mode,
47461+ .set_all_multicast_mode = xgbe_set_all_multicast_mode,
47462+ .add_mac_addresses = xgbe_add_mac_addresses,
47463+ .set_mac_address = xgbe_set_mac_address,
47464+
47465+ .enable_rx_csum = xgbe_enable_rx_csum,
47466+ .disable_rx_csum = xgbe_disable_rx_csum,
47467+
47468+ .enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping,
47469+ .disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping,
47470+ .enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering,
47471+ .disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering,
47472+ .update_vlan_hash_table = xgbe_update_vlan_hash_table,
47473+
47474+ .read_mmd_regs = xgbe_read_mmd_regs,
47475+ .write_mmd_regs = xgbe_write_mmd_regs,
47476+
47477+ .set_gmii_speed = xgbe_set_gmii_speed,
47478+ .set_gmii_2500_speed = xgbe_set_gmii_2500_speed,
47479+ .set_xgmii_speed = xgbe_set_xgmii_speed,
47480+
47481+ .enable_tx = xgbe_enable_tx,
47482+ .disable_tx = xgbe_disable_tx,
47483+ .enable_rx = xgbe_enable_rx,
47484+ .disable_rx = xgbe_disable_rx,
47485+
47486+ .powerup_tx = xgbe_powerup_tx,
47487+ .powerdown_tx = xgbe_powerdown_tx,
47488+ .powerup_rx = xgbe_powerup_rx,
47489+ .powerdown_rx = xgbe_powerdown_rx,
47490+
47491+ .pre_xmit = xgbe_pre_xmit,
47492+ .dev_read = xgbe_dev_read,
47493+ .enable_int = xgbe_enable_int,
47494+ .disable_int = xgbe_disable_int,
47495+ .init = xgbe_init,
47496+ .exit = xgbe_exit,
47497
47498 /* Descriptor related Sequences have to be initialized here */
47499- hw_if->tx_desc_init = xgbe_tx_desc_init;
47500- hw_if->rx_desc_init = xgbe_rx_desc_init;
47501- hw_if->tx_desc_reset = xgbe_tx_desc_reset;
47502- hw_if->rx_desc_reset = xgbe_rx_desc_reset;
47503- hw_if->is_last_desc = xgbe_is_last_desc;
47504- hw_if->is_context_desc = xgbe_is_context_desc;
47505+ .tx_desc_init = xgbe_tx_desc_init,
47506+ .rx_desc_init = xgbe_rx_desc_init,
47507+ .tx_desc_reset = xgbe_tx_desc_reset,
47508+ .rx_desc_reset = xgbe_rx_desc_reset,
47509+ .is_last_desc = xgbe_is_last_desc,
47510+ .is_context_desc = xgbe_is_context_desc,
47511
47512 /* For FLOW ctrl */
47513- hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
47514- hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
47515+ .config_tx_flow_control = xgbe_config_tx_flow_control,
47516+ .config_rx_flow_control = xgbe_config_rx_flow_control,
47517
47518 /* For RX coalescing */
47519- hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
47520- hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
47521- hw_if->usec_to_riwt = xgbe_usec_to_riwt;
47522- hw_if->riwt_to_usec = xgbe_riwt_to_usec;
47523+ .config_rx_coalesce = xgbe_config_rx_coalesce,
47524+ .config_tx_coalesce = xgbe_config_tx_coalesce,
47525+ .usec_to_riwt = xgbe_usec_to_riwt,
47526+ .riwt_to_usec = xgbe_riwt_to_usec,
47527
47528 /* For RX and TX threshold config */
47529- hw_if->config_rx_threshold = xgbe_config_rx_threshold;
47530- hw_if->config_tx_threshold = xgbe_config_tx_threshold;
47531+ .config_rx_threshold = xgbe_config_rx_threshold,
47532+ .config_tx_threshold = xgbe_config_tx_threshold,
47533
47534 /* For RX and TX Store and Forward Mode config */
47535- hw_if->config_rsf_mode = xgbe_config_rsf_mode;
47536- hw_if->config_tsf_mode = xgbe_config_tsf_mode;
47537+ .config_rsf_mode = xgbe_config_rsf_mode,
47538+ .config_tsf_mode = xgbe_config_tsf_mode,
47539
47540 /* For TX DMA Operating on Second Frame config */
47541- hw_if->config_osp_mode = xgbe_config_osp_mode;
47542+ .config_osp_mode = xgbe_config_osp_mode,
47543
47544 /* For RX and TX PBL config */
47545- hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
47546- hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
47547- hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
47548- hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
47549- hw_if->config_pblx8 = xgbe_config_pblx8;
47550+ .config_rx_pbl_val = xgbe_config_rx_pbl_val,
47551+ .get_rx_pbl_val = xgbe_get_rx_pbl_val,
47552+ .config_tx_pbl_val = xgbe_config_tx_pbl_val,
47553+ .get_tx_pbl_val = xgbe_get_tx_pbl_val,
47554+ .config_pblx8 = xgbe_config_pblx8,
47555
47556 /* For MMC statistics support */
47557- hw_if->tx_mmc_int = xgbe_tx_mmc_int;
47558- hw_if->rx_mmc_int = xgbe_rx_mmc_int;
47559- hw_if->read_mmc_stats = xgbe_read_mmc_stats;
47560+ .tx_mmc_int = xgbe_tx_mmc_int,
47561+ .rx_mmc_int = xgbe_rx_mmc_int,
47562+ .read_mmc_stats = xgbe_read_mmc_stats,
47563
47564 /* For PTP config */
47565- hw_if->config_tstamp = xgbe_config_tstamp;
47566- hw_if->update_tstamp_addend = xgbe_update_tstamp_addend;
47567- hw_if->set_tstamp_time = xgbe_set_tstamp_time;
47568- hw_if->get_tstamp_time = xgbe_get_tstamp_time;
47569- hw_if->get_tx_tstamp = xgbe_get_tx_tstamp;
47570+ .config_tstamp = xgbe_config_tstamp,
47571+ .update_tstamp_addend = xgbe_update_tstamp_addend,
47572+ .set_tstamp_time = xgbe_set_tstamp_time,
47573+ .get_tstamp_time = xgbe_get_tstamp_time,
47574+ .get_tx_tstamp = xgbe_get_tx_tstamp,
47575
47576 /* For Data Center Bridging config */
47577- hw_if->config_dcb_tc = xgbe_config_dcb_tc;
47578- hw_if->config_dcb_pfc = xgbe_config_dcb_pfc;
47579-
47580- DBGPR("<--xgbe_init_function_ptrs\n");
47581-}
47582+ .config_dcb_tc = xgbe_config_dcb_tc,
47583+ .config_dcb_pfc = xgbe_config_dcb_pfc,
47584+};
47585diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47586index 2349ea9..a83a677 100644
47587--- a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47588+++ b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47589@@ -154,7 +154,7 @@ static int xgbe_calc_rx_buf_size(struct net_device *netdev, unsigned int mtu)
47590
47591 static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
47592 {
47593- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47594+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47595 struct xgbe_channel *channel;
47596 enum xgbe_int int_id;
47597 unsigned int i;
47598@@ -176,7 +176,7 @@ static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
47599
47600 static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
47601 {
47602- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47603+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47604 struct xgbe_channel *channel;
47605 enum xgbe_int int_id;
47606 unsigned int i;
47607@@ -199,7 +199,7 @@ static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
47608 static irqreturn_t xgbe_isr(int irq, void *data)
47609 {
47610 struct xgbe_prv_data *pdata = data;
47611- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47612+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47613 struct xgbe_channel *channel;
47614 unsigned int dma_isr, dma_ch_isr;
47615 unsigned int mac_isr, mac_tssr;
47616@@ -446,7 +446,7 @@ static void xgbe_napi_disable(struct xgbe_prv_data *pdata, unsigned int del)
47617
47618 void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
47619 {
47620- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47621+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47622
47623 DBGPR("-->xgbe_init_tx_coalesce\n");
47624
47625@@ -460,7 +460,7 @@ void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
47626
47627 void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
47628 {
47629- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47630+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47631
47632 DBGPR("-->xgbe_init_rx_coalesce\n");
47633
47634@@ -474,7 +474,7 @@ void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
47635
47636 static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
47637 {
47638- struct xgbe_desc_if *desc_if = &pdata->desc_if;
47639+ struct xgbe_desc_if *desc_if = pdata->desc_if;
47640 struct xgbe_channel *channel;
47641 struct xgbe_ring *ring;
47642 struct xgbe_ring_data *rdata;
47643@@ -499,7 +499,7 @@ static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
47644
47645 static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
47646 {
47647- struct xgbe_desc_if *desc_if = &pdata->desc_if;
47648+ struct xgbe_desc_if *desc_if = pdata->desc_if;
47649 struct xgbe_channel *channel;
47650 struct xgbe_ring *ring;
47651 struct xgbe_ring_data *rdata;
47652@@ -525,7 +525,7 @@ static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
47653 static void xgbe_adjust_link(struct net_device *netdev)
47654 {
47655 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47656- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47657+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47658 struct phy_device *phydev = pdata->phydev;
47659 int new_state = 0;
47660
47661@@ -633,7 +633,7 @@ static void xgbe_phy_exit(struct xgbe_prv_data *pdata)
47662 int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
47663 {
47664 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47665- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47666+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47667 unsigned long flags;
47668
47669 DBGPR("-->xgbe_powerdown\n");
47670@@ -671,7 +671,7 @@ int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
47671 int xgbe_powerup(struct net_device *netdev, unsigned int caller)
47672 {
47673 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47674- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47675+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47676 unsigned long flags;
47677
47678 DBGPR("-->xgbe_powerup\n");
47679@@ -708,7 +708,7 @@ int xgbe_powerup(struct net_device *netdev, unsigned int caller)
47680
47681 static int xgbe_start(struct xgbe_prv_data *pdata)
47682 {
47683- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47684+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47685 struct net_device *netdev = pdata->netdev;
47686
47687 DBGPR("-->xgbe_start\n");
47688@@ -734,7 +734,7 @@ static int xgbe_start(struct xgbe_prv_data *pdata)
47689
47690 static void xgbe_stop(struct xgbe_prv_data *pdata)
47691 {
47692- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47693+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47694 struct net_device *netdev = pdata->netdev;
47695
47696 DBGPR("-->xgbe_stop\n");
47697@@ -754,7 +754,7 @@ static void xgbe_stop(struct xgbe_prv_data *pdata)
47698
47699 static void xgbe_restart_dev(struct xgbe_prv_data *pdata, unsigned int reset)
47700 {
47701- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47702+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47703
47704 DBGPR("-->xgbe_restart_dev\n");
47705
47706@@ -951,7 +951,7 @@ static int xgbe_set_hwtstamp_settings(struct xgbe_prv_data *pdata,
47707 return -ERANGE;
47708 }
47709
47710- pdata->hw_if.config_tstamp(pdata, mac_tscr);
47711+ pdata->hw_if->config_tstamp(pdata, mac_tscr);
47712
47713 memcpy(&pdata->tstamp_config, &config, sizeof(config));
47714
47715@@ -1089,8 +1089,8 @@ static void xgbe_packet_info(struct xgbe_prv_data *pdata,
47716 static int xgbe_open(struct net_device *netdev)
47717 {
47718 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47719- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47720- struct xgbe_desc_if *desc_if = &pdata->desc_if;
47721+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47722+ struct xgbe_desc_if *desc_if = pdata->desc_if;
47723 int ret;
47724
47725 DBGPR("-->xgbe_open\n");
47726@@ -1170,8 +1170,8 @@ err_phy_init:
47727 static int xgbe_close(struct net_device *netdev)
47728 {
47729 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47730- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47731- struct xgbe_desc_if *desc_if = &pdata->desc_if;
47732+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47733+ struct xgbe_desc_if *desc_if = pdata->desc_if;
47734
47735 DBGPR("-->xgbe_close\n");
47736
47737@@ -1205,8 +1205,8 @@ static int xgbe_close(struct net_device *netdev)
47738 static int xgbe_xmit(struct sk_buff *skb, struct net_device *netdev)
47739 {
47740 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47741- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47742- struct xgbe_desc_if *desc_if = &pdata->desc_if;
47743+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47744+ struct xgbe_desc_if *desc_if = pdata->desc_if;
47745 struct xgbe_channel *channel;
47746 struct xgbe_ring *ring;
47747 struct xgbe_packet_data *packet;
47748@@ -1275,7 +1275,7 @@ tx_netdev_return:
47749 static void xgbe_set_rx_mode(struct net_device *netdev)
47750 {
47751 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47752- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47753+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47754 unsigned int pr_mode, am_mode;
47755
47756 DBGPR("-->xgbe_set_rx_mode\n");
47757@@ -1294,7 +1294,7 @@ static void xgbe_set_rx_mode(struct net_device *netdev)
47758 static int xgbe_set_mac_address(struct net_device *netdev, void *addr)
47759 {
47760 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47761- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47762+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47763 struct sockaddr *saddr = addr;
47764
47765 DBGPR("-->xgbe_set_mac_address\n");
47766@@ -1361,7 +1361,7 @@ static struct rtnl_link_stats64 *xgbe_get_stats64(struct net_device *netdev,
47767
47768 DBGPR("-->%s\n", __func__);
47769
47770- pdata->hw_if.read_mmc_stats(pdata);
47771+ pdata->hw_if->read_mmc_stats(pdata);
47772
47773 s->rx_packets = pstats->rxframecount_gb;
47774 s->rx_bytes = pstats->rxoctetcount_gb;
47775@@ -1388,7 +1388,7 @@ static int xgbe_vlan_rx_add_vid(struct net_device *netdev, __be16 proto,
47776 u16 vid)
47777 {
47778 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47779- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47780+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47781
47782 DBGPR("-->%s\n", __func__);
47783
47784@@ -1404,7 +1404,7 @@ static int xgbe_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto,
47785 u16 vid)
47786 {
47787 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47788- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47789+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47790
47791 DBGPR("-->%s\n", __func__);
47792
47793@@ -1464,7 +1464,7 @@ static int xgbe_set_features(struct net_device *netdev,
47794 netdev_features_t features)
47795 {
47796 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47797- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47798+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47799 netdev_features_t rxcsum, rxvlan, rxvlan_filter;
47800
47801 rxcsum = pdata->netdev_features & NETIF_F_RXCSUM;
47802@@ -1520,7 +1520,7 @@ struct net_device_ops *xgbe_get_netdev_ops(void)
47803 static void xgbe_rx_refresh(struct xgbe_channel *channel)
47804 {
47805 struct xgbe_prv_data *pdata = channel->pdata;
47806- struct xgbe_desc_if *desc_if = &pdata->desc_if;
47807+ struct xgbe_desc_if *desc_if = pdata->desc_if;
47808 struct xgbe_ring *ring = channel->rx_ring;
47809 struct xgbe_ring_data *rdata;
47810
47811@@ -1536,8 +1536,8 @@ static void xgbe_rx_refresh(struct xgbe_channel *channel)
47812 static int xgbe_tx_poll(struct xgbe_channel *channel)
47813 {
47814 struct xgbe_prv_data *pdata = channel->pdata;
47815- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47816- struct xgbe_desc_if *desc_if = &pdata->desc_if;
47817+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47818+ struct xgbe_desc_if *desc_if = pdata->desc_if;
47819 struct xgbe_ring *ring = channel->tx_ring;
47820 struct xgbe_ring_data *rdata;
47821 struct xgbe_ring_desc *rdesc;
47822@@ -1589,7 +1589,7 @@ static int xgbe_tx_poll(struct xgbe_channel *channel)
47823 static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
47824 {
47825 struct xgbe_prv_data *pdata = channel->pdata;
47826- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47827+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47828 struct xgbe_ring *ring = channel->rx_ring;
47829 struct xgbe_ring_data *rdata;
47830 struct xgbe_packet_data *packet;
47831diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
47832index 49508ec..2617cca 100644
47833--- a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
47834+++ b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
47835@@ -203,7 +203,7 @@ static void xgbe_get_ethtool_stats(struct net_device *netdev,
47836
47837 DBGPR("-->%s\n", __func__);
47838
47839- pdata->hw_if.read_mmc_stats(pdata);
47840+ pdata->hw_if->read_mmc_stats(pdata);
47841 for (i = 0; i < XGBE_STATS_COUNT; i++) {
47842 stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset;
47843 *data++ = *(u64 *)stat;
47844@@ -378,7 +378,7 @@ static int xgbe_get_coalesce(struct net_device *netdev,
47845 struct ethtool_coalesce *ec)
47846 {
47847 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47848- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47849+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47850 unsigned int riwt;
47851
47852 DBGPR("-->xgbe_get_coalesce\n");
47853@@ -401,7 +401,7 @@ static int xgbe_set_coalesce(struct net_device *netdev,
47854 struct ethtool_coalesce *ec)
47855 {
47856 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47857- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47858+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47859 unsigned int rx_frames, rx_riwt, rx_usecs;
47860 unsigned int tx_frames, tx_usecs;
47861
47862diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-main.c b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
47863index f5a8fa0..0bb58ff 100644
47864--- a/drivers/net/ethernet/amd/xgbe/xgbe-main.c
47865+++ b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
47866@@ -209,12 +209,6 @@ static void xgbe_default_config(struct xgbe_prv_data *pdata)
47867 DBGPR("<--xgbe_default_config\n");
47868 }
47869
47870-static void xgbe_init_all_fptrs(struct xgbe_prv_data *pdata)
47871-{
47872- xgbe_init_function_ptrs_dev(&pdata->hw_if);
47873- xgbe_init_function_ptrs_desc(&pdata->desc_if);
47874-}
47875-
47876 static int xgbe_probe(struct platform_device *pdev)
47877 {
47878 struct xgbe_prv_data *pdata;
47879@@ -327,9 +321,8 @@ static int xgbe_probe(struct platform_device *pdev)
47880 netdev->base_addr = (unsigned long)pdata->xgmac_regs;
47881
47882 /* Set all the function pointers */
47883- xgbe_init_all_fptrs(pdata);
47884- hw_if = &pdata->hw_if;
47885- desc_if = &pdata->desc_if;
47886+ hw_if = pdata->hw_if = &default_xgbe_hw_if;
47887+ desc_if = pdata->desc_if = &default_xgbe_desc_if;
47888
47889 /* Issue software reset to device */
47890 hw_if->exit(pdata);
47891diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
47892index 363b210..b241389 100644
47893--- a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
47894+++ b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
47895@@ -126,7 +126,7 @@
47896 static int xgbe_mdio_read(struct mii_bus *mii, int prtad, int mmd_reg)
47897 {
47898 struct xgbe_prv_data *pdata = mii->priv;
47899- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47900+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47901 int mmd_data;
47902
47903 DBGPR_MDIO("-->xgbe_mdio_read: prtad=%#x mmd_reg=%#x\n",
47904@@ -143,7 +143,7 @@ static int xgbe_mdio_write(struct mii_bus *mii, int prtad, int mmd_reg,
47905 u16 mmd_val)
47906 {
47907 struct xgbe_prv_data *pdata = mii->priv;
47908- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47909+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47910 int mmd_data = mmd_val;
47911
47912 DBGPR_MDIO("-->xgbe_mdio_write: prtad=%#x mmd_reg=%#x mmd_data=%#x\n",
47913diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
47914index a1bf9d1c..84adcab 100644
47915--- a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
47916+++ b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
47917@@ -129,7 +129,7 @@ static cycle_t xgbe_cc_read(const struct cyclecounter *cc)
47918 tstamp_cc);
47919 u64 nsec;
47920
47921- nsec = pdata->hw_if.get_tstamp_time(pdata);
47922+ nsec = pdata->hw_if->get_tstamp_time(pdata);
47923
47924 return nsec;
47925 }
47926@@ -158,7 +158,7 @@ static int xgbe_adjfreq(struct ptp_clock_info *info, s32 delta)
47927
47928 spin_lock_irqsave(&pdata->tstamp_lock, flags);
47929
47930- pdata->hw_if.update_tstamp_addend(pdata, addend);
47931+ pdata->hw_if->update_tstamp_addend(pdata, addend);
47932
47933 spin_unlock_irqrestore(&pdata->tstamp_lock, flags);
47934
47935diff --git a/drivers/net/ethernet/amd/xgbe/xgbe.h b/drivers/net/ethernet/amd/xgbe/xgbe.h
47936index 789957d..d7d0245 100644
47937--- a/drivers/net/ethernet/amd/xgbe/xgbe.h
47938+++ b/drivers/net/ethernet/amd/xgbe/xgbe.h
47939@@ -583,8 +583,8 @@ struct xgbe_prv_data {
47940
47941 int irq_number;
47942
47943- struct xgbe_hw_if hw_if;
47944- struct xgbe_desc_if desc_if;
47945+ const struct xgbe_hw_if *hw_if;
47946+ const struct xgbe_desc_if *desc_if;
47947
47948 /* AXI DMA settings */
47949 unsigned int axdomain;
47950@@ -697,6 +697,9 @@ struct xgbe_prv_data {
47951 #endif
47952 };
47953
47954+extern const struct xgbe_hw_if default_xgbe_hw_if;
47955+extern const struct xgbe_desc_if default_xgbe_desc_if;
47956+
47957 /* Function prototypes*/
47958
47959 void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
47960diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
47961index adcacda..fa6e0ae 100644
47962--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
47963+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
47964@@ -1065,7 +1065,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
47965 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
47966 {
47967 /* RX_MODE controlling object */
47968- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
47969+ bnx2x_init_rx_mode_obj(bp);
47970
47971 /* multicast configuration controlling object */
47972 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
47973diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
47974index 7bc2924..2112002 100644
47975--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
47976+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
47977@@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
47978 return rc;
47979 }
47980
47981-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
47982- struct bnx2x_rx_mode_obj *o)
47983+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
47984 {
47985 if (CHIP_IS_E1x(bp)) {
47986- o->wait_comp = bnx2x_empty_rx_mode_wait;
47987- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
47988+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
47989+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
47990 } else {
47991- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
47992- o->config_rx_mode = bnx2x_set_rx_mode_e2;
47993+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
47994+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
47995 }
47996 }
47997
47998diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
47999index e97275f..52e28bc 100644
48000--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48001+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48002@@ -1409,8 +1409,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
48003
48004 /********************* RX MODE ****************/
48005
48006-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
48007- struct bnx2x_rx_mode_obj *o);
48008+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
48009
48010 /**
48011 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
48012diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
48013index 31c9f82..e65e986 100644
48014--- a/drivers/net/ethernet/broadcom/tg3.h
48015+++ b/drivers/net/ethernet/broadcom/tg3.h
48016@@ -150,6 +150,7 @@
48017 #define CHIPREV_ID_5750_A0 0x4000
48018 #define CHIPREV_ID_5750_A1 0x4001
48019 #define CHIPREV_ID_5750_A3 0x4003
48020+#define CHIPREV_ID_5750_C1 0x4201
48021 #define CHIPREV_ID_5750_C2 0x4202
48022 #define CHIPREV_ID_5752_A0_HW 0x5000
48023 #define CHIPREV_ID_5752_A0 0x6000
48024diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
48025index 903466e..b285864 100644
48026--- a/drivers/net/ethernet/brocade/bna/bna_enet.c
48027+++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
48028@@ -1693,10 +1693,10 @@ bna_cb_ioceth_reset(void *arg)
48029 }
48030
48031 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
48032- bna_cb_ioceth_enable,
48033- bna_cb_ioceth_disable,
48034- bna_cb_ioceth_hbfail,
48035- bna_cb_ioceth_reset
48036+ .enable_cbfn = bna_cb_ioceth_enable,
48037+ .disable_cbfn = bna_cb_ioceth_disable,
48038+ .hbfail_cbfn = bna_cb_ioceth_hbfail,
48039+ .reset_cbfn = bna_cb_ioceth_reset
48040 };
48041
48042 static void bna_attr_init(struct bna_ioceth *ioceth)
48043diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48044index 8cffcdf..aadf043 100644
48045--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48046+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48047@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
48048 */
48049 struct l2t_skb_cb {
48050 arp_failure_handler_func arp_failure_handler;
48051-};
48052+} __no_const;
48053
48054 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
48055
48056diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48057index 279873c..11e1921 100644
48058--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48059+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48060@@ -2365,7 +2365,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
48061
48062 int i;
48063 struct adapter *ap = netdev2adap(dev);
48064- static const unsigned int *reg_ranges;
48065+ const unsigned int *reg_ranges;
48066 int arr_size = 0, buf_size = 0;
48067
48068 if (is_t4(ap->params.chip)) {
48069diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
48070index cf8b6ff..274271e 100644
48071--- a/drivers/net/ethernet/dec/tulip/de4x5.c
48072+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
48073@@ -5387,7 +5387,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
48074 for (i=0; i<ETH_ALEN; i++) {
48075 tmp.addr[i] = dev->dev_addr[i];
48076 }
48077- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
48078+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
48079 break;
48080
48081 case DE4X5_SET_HWADDR: /* Set the hardware address */
48082@@ -5427,7 +5427,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
48083 spin_lock_irqsave(&lp->lock, flags);
48084 memcpy(&statbuf, &lp->pktStats, ioc->len);
48085 spin_unlock_irqrestore(&lp->lock, flags);
48086- if (copy_to_user(ioc->data, &statbuf, ioc->len))
48087+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
48088 return -EFAULT;
48089 break;
48090 }
48091diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
48092index 597c463..5cc1a7f 100644
48093--- a/drivers/net/ethernet/emulex/benet/be_main.c
48094+++ b/drivers/net/ethernet/emulex/benet/be_main.c
48095@@ -537,7 +537,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
48096
48097 if (wrapped)
48098 newacc += 65536;
48099- ACCESS_ONCE(*acc) = newacc;
48100+ ACCESS_ONCE_RW(*acc) = newacc;
48101 }
48102
48103 static void populate_erx_stats(struct be_adapter *adapter,
48104diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
48105index c77fa4a..7fd42fc 100644
48106--- a/drivers/net/ethernet/faraday/ftgmac100.c
48107+++ b/drivers/net/ethernet/faraday/ftgmac100.c
48108@@ -30,6 +30,8 @@
48109 #include <linux/netdevice.h>
48110 #include <linux/phy.h>
48111 #include <linux/platform_device.h>
48112+#include <linux/interrupt.h>
48113+#include <linux/irqreturn.h>
48114 #include <net/ip.h>
48115
48116 #include "ftgmac100.h"
48117diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
48118index 4ff1adc..0ea6bf4 100644
48119--- a/drivers/net/ethernet/faraday/ftmac100.c
48120+++ b/drivers/net/ethernet/faraday/ftmac100.c
48121@@ -31,6 +31,8 @@
48122 #include <linux/module.h>
48123 #include <linux/netdevice.h>
48124 #include <linux/platform_device.h>
48125+#include <linux/interrupt.h>
48126+#include <linux/irqreturn.h>
48127
48128 #include "ftmac100.h"
48129
48130diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48131index 537b621..07f87ce 100644
48132--- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48133+++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48134@@ -401,7 +401,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
48135 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
48136
48137 /* Update the base adjustement value. */
48138- ACCESS_ONCE(pf->ptp_base_adj) = incval;
48139+ ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
48140 smp_mb(); /* Force the above update. */
48141 }
48142
48143diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48144index 5fd4b52..87aa34b 100644
48145--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48146+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48147@@ -794,7 +794,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
48148 }
48149
48150 /* update the base incval used to calculate frequency adjustment */
48151- ACCESS_ONCE(adapter->base_incval) = incval;
48152+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
48153 smp_mb();
48154
48155 /* need lock to prevent incorrect read while modifying cyclecounter */
48156diff --git a/drivers/net/ethernet/mellanox/mlx4/en_tx.c b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
48157index 454d9fe..59f0f0b 100644
48158--- a/drivers/net/ethernet/mellanox/mlx4/en_tx.c
48159+++ b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
48160@@ -458,8 +458,8 @@ static bool mlx4_en_process_tx_cq(struct net_device *dev,
48161 wmb();
48162
48163 /* we want to dirty this cache line once */
48164- ACCESS_ONCE(ring->last_nr_txbb) = last_nr_txbb;
48165- ACCESS_ONCE(ring->cons) = ring_cons + txbbs_skipped;
48166+ ACCESS_ONCE_RW(ring->last_nr_txbb) = last_nr_txbb;
48167+ ACCESS_ONCE_RW(ring->cons) = ring_cons + txbbs_skipped;
48168
48169 netdev_tx_completed_queue(ring->tx_queue, packets, bytes);
48170
48171diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
48172index 2bbd01f..e8baa64 100644
48173--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
48174+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
48175@@ -3457,7 +3457,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
48176 struct __vxge_hw_fifo *fifo;
48177 struct vxge_hw_fifo_config *config;
48178 u32 txdl_size, txdl_per_memblock;
48179- struct vxge_hw_mempool_cbs fifo_mp_callback;
48180+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
48181+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
48182+ };
48183+
48184 struct __vxge_hw_virtualpath *vpath;
48185
48186 if ((vp == NULL) || (attr == NULL)) {
48187@@ -3540,8 +3543,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
48188 goto exit;
48189 }
48190
48191- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
48192-
48193 fifo->mempool =
48194 __vxge_hw_mempool_create(vpath->hldev,
48195 fifo->config->memblock_size,
48196diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48197index 2bb48d5..d1a865d 100644
48198--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48199+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48200@@ -2324,7 +2324,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
48201 max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
48202 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
48203 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
48204- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
48205+ pax_open_kernel();
48206+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
48207+ pax_close_kernel();
48208 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48209 max_sds_rings = QLCNIC_MAX_SDS_RINGS;
48210 max_tx_rings = QLCNIC_MAX_TX_RINGS;
48211diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48212index be7d7a6..a8983f8 100644
48213--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48214+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48215@@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
48216 case QLCNIC_NON_PRIV_FUNC:
48217 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
48218 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48219- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
48220+ pax_open_kernel();
48221+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
48222+ pax_close_kernel();
48223 break;
48224 case QLCNIC_PRIV_FUNC:
48225 ahw->op_mode = QLCNIC_PRIV_FUNC;
48226 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
48227- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
48228+ pax_open_kernel();
48229+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
48230+ pax_close_kernel();
48231 break;
48232 case QLCNIC_MGMT_FUNC:
48233 ahw->op_mode = QLCNIC_MGMT_FUNC;
48234 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48235- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
48236+ pax_open_kernel();
48237+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
48238+ pax_close_kernel();
48239 break;
48240 default:
48241 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
48242diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48243index c9f57fb..208bdc1 100644
48244--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48245+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48246@@ -1285,7 +1285,7 @@ flash_temp:
48247 int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
48248 {
48249 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
48250- static const struct qlcnic_dump_operations *fw_dump_ops;
48251+ const struct qlcnic_dump_operations *fw_dump_ops;
48252 struct qlcnic_83xx_dump_template_hdr *hdr_83xx;
48253 u32 entry_offset, dump, no_entries, buf_offset = 0;
48254 int i, k, ops_cnt, ops_index, dump_size = 0;
48255diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
48256index cf154f7..c948d1b 100644
48257--- a/drivers/net/ethernet/realtek/r8169.c
48258+++ b/drivers/net/ethernet/realtek/r8169.c
48259@@ -788,22 +788,22 @@ struct rtl8169_private {
48260 struct mdio_ops {
48261 void (*write)(struct rtl8169_private *, int, int);
48262 int (*read)(struct rtl8169_private *, int);
48263- } mdio_ops;
48264+ } __no_const mdio_ops;
48265
48266 struct pll_power_ops {
48267 void (*down)(struct rtl8169_private *);
48268 void (*up)(struct rtl8169_private *);
48269- } pll_power_ops;
48270+ } __no_const pll_power_ops;
48271
48272 struct jumbo_ops {
48273 void (*enable)(struct rtl8169_private *);
48274 void (*disable)(struct rtl8169_private *);
48275- } jumbo_ops;
48276+ } __no_const jumbo_ops;
48277
48278 struct csi_ops {
48279 void (*write)(struct rtl8169_private *, int, int);
48280 u32 (*read)(struct rtl8169_private *, int);
48281- } csi_ops;
48282+ } __no_const csi_ops;
48283
48284 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
48285 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
48286diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
48287index 6b861e3..204ac86 100644
48288--- a/drivers/net/ethernet/sfc/ptp.c
48289+++ b/drivers/net/ethernet/sfc/ptp.c
48290@@ -822,7 +822,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
48291 ptp->start.dma_addr);
48292
48293 /* Clear flag that signals MC ready */
48294- ACCESS_ONCE(*start) = 0;
48295+ ACCESS_ONCE_RW(*start) = 0;
48296 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
48297 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
48298 EFX_BUG_ON_PARANOID(rc);
48299diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48300index 08c483b..2c4a553 100644
48301--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48302+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48303@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
48304
48305 writel(value, ioaddr + MMC_CNTRL);
48306
48307- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
48308- MMC_CNTRL, value);
48309+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
48310+// MMC_CNTRL, value);
48311 }
48312
48313 /* To mask all all interrupts.*/
48314diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
48315index 2f48f79..8ae1a1a 100644
48316--- a/drivers/net/hyperv/hyperv_net.h
48317+++ b/drivers/net/hyperv/hyperv_net.h
48318@@ -171,7 +171,7 @@ struct rndis_device {
48319 enum rndis_device_state state;
48320 bool link_state;
48321 bool link_change;
48322- atomic_t new_req_id;
48323+ atomic_unchecked_t new_req_id;
48324
48325 spinlock_t request_lock;
48326 struct list_head req_list;
48327diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
48328index 2b86f0b..ecc996f 100644
48329--- a/drivers/net/hyperv/rndis_filter.c
48330+++ b/drivers/net/hyperv/rndis_filter.c
48331@@ -102,7 +102,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
48332 * template
48333 */
48334 set = &rndis_msg->msg.set_req;
48335- set->req_id = atomic_inc_return(&dev->new_req_id);
48336+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
48337
48338 /* Add to the request list */
48339 spin_lock_irqsave(&dev->request_lock, flags);
48340@@ -911,7 +911,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
48341
48342 /* Setup the rndis set */
48343 halt = &request->request_msg.msg.halt_req;
48344- halt->req_id = atomic_inc_return(&dev->new_req_id);
48345+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
48346
48347 /* Ignore return since this msg is optional. */
48348 rndis_filter_send_request(dev, request);
48349diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
48350index 6cbc56a..5f7e6c8 100644
48351--- a/drivers/net/ieee802154/fakehard.c
48352+++ b/drivers/net/ieee802154/fakehard.c
48353@@ -365,7 +365,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
48354 phy->transmit_power = 0xbf;
48355
48356 dev->netdev_ops = &fake_ops;
48357- dev->ml_priv = &fake_mlme;
48358+ dev->ml_priv = (void *)&fake_mlme;
48359
48360 priv = netdev_priv(dev);
48361 priv->phy = phy;
48362diff --git a/drivers/net/ifb.c b/drivers/net/ifb.c
48363index 34f846b..4a0d5b1 100644
48364--- a/drivers/net/ifb.c
48365+++ b/drivers/net/ifb.c
48366@@ -253,7 +253,7 @@ static int ifb_validate(struct nlattr *tb[], struct nlattr *data[])
48367 return 0;
48368 }
48369
48370-static struct rtnl_link_ops ifb_link_ops __read_mostly = {
48371+static struct rtnl_link_ops ifb_link_ops = {
48372 .kind = "ifb",
48373 .priv_size = sizeof(struct ifb_private),
48374 .setup = ifb_setup,
48375diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
48376index bfb0b6e..5c396ce 100644
48377--- a/drivers/net/macvlan.c
48378+++ b/drivers/net/macvlan.c
48379@@ -335,7 +335,7 @@ static void macvlan_broadcast_enqueue(struct macvlan_port *port,
48380 free_nskb:
48381 kfree_skb(nskb);
48382 err:
48383- atomic_long_inc(&skb->dev->rx_dropped);
48384+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
48385 }
48386
48387 static void macvlan_flush_sources(struct macvlan_port *port,
48388@@ -1454,13 +1454,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
48389 int macvlan_link_register(struct rtnl_link_ops *ops)
48390 {
48391 /* common fields */
48392- ops->priv_size = sizeof(struct macvlan_dev);
48393- ops->validate = macvlan_validate;
48394- ops->maxtype = IFLA_MACVLAN_MAX;
48395- ops->policy = macvlan_policy;
48396- ops->changelink = macvlan_changelink;
48397- ops->get_size = macvlan_get_size;
48398- ops->fill_info = macvlan_fill_info;
48399+ pax_open_kernel();
48400+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
48401+ *(void **)&ops->validate = macvlan_validate;
48402+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
48403+ *(const void **)&ops->policy = macvlan_policy;
48404+ *(void **)&ops->changelink = macvlan_changelink;
48405+ *(void **)&ops->get_size = macvlan_get_size;
48406+ *(void **)&ops->fill_info = macvlan_fill_info;
48407+ pax_close_kernel();
48408
48409 return rtnl_link_register(ops);
48410 };
48411@@ -1540,7 +1542,7 @@ static int macvlan_device_event(struct notifier_block *unused,
48412 return NOTIFY_DONE;
48413 }
48414
48415-static struct notifier_block macvlan_notifier_block __read_mostly = {
48416+static struct notifier_block macvlan_notifier_block = {
48417 .notifier_call = macvlan_device_event,
48418 };
48419
48420diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
48421index 880cc09..6a68ba6 100644
48422--- a/drivers/net/macvtap.c
48423+++ b/drivers/net/macvtap.c
48424@@ -422,7 +422,7 @@ static void macvtap_setup(struct net_device *dev)
48425 dev->tx_queue_len = TUN_READQ_SIZE;
48426 }
48427
48428-static struct rtnl_link_ops macvtap_link_ops __read_mostly = {
48429+static struct rtnl_link_ops macvtap_link_ops = {
48430 .kind = "macvtap",
48431 .setup = macvtap_setup,
48432 .newlink = macvtap_newlink,
48433@@ -1020,7 +1020,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
48434 }
48435
48436 ret = 0;
48437- if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
48438+ if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
48439 put_user(q->flags, &ifr->ifr_flags))
48440 ret = -EFAULT;
48441 macvtap_put_vlan(vlan);
48442@@ -1190,7 +1190,7 @@ static int macvtap_device_event(struct notifier_block *unused,
48443 return NOTIFY_DONE;
48444 }
48445
48446-static struct notifier_block macvtap_notifier_block __read_mostly = {
48447+static struct notifier_block macvtap_notifier_block = {
48448 .notifier_call = macvtap_device_event,
48449 };
48450
48451diff --git a/drivers/net/nlmon.c b/drivers/net/nlmon.c
48452index 34924df..a747360 100644
48453--- a/drivers/net/nlmon.c
48454+++ b/drivers/net/nlmon.c
48455@@ -154,7 +154,7 @@ static int nlmon_validate(struct nlattr *tb[], struct nlattr *data[])
48456 return 0;
48457 }
48458
48459-static struct rtnl_link_ops nlmon_link_ops __read_mostly = {
48460+static struct rtnl_link_ops nlmon_link_ops = {
48461 .kind = "nlmon",
48462 .priv_size = sizeof(struct nlmon),
48463 .setup = nlmon_setup,
48464diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
48465index 794a473..9fd437b 100644
48466--- a/drivers/net/ppp/ppp_generic.c
48467+++ b/drivers/net/ppp/ppp_generic.c
48468@@ -1020,7 +1020,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48469 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
48470 struct ppp_stats stats;
48471 struct ppp_comp_stats cstats;
48472- char *vers;
48473
48474 switch (cmd) {
48475 case SIOCGPPPSTATS:
48476@@ -1042,8 +1041,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48477 break;
48478
48479 case SIOCGPPPVER:
48480- vers = PPP_VERSION;
48481- if (copy_to_user(addr, vers, strlen(vers) + 1))
48482+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
48483 break;
48484 err = 0;
48485 break;
48486diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
48487index 079f7ad..b2a2bfa7 100644
48488--- a/drivers/net/slip/slhc.c
48489+++ b/drivers/net/slip/slhc.c
48490@@ -487,7 +487,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
48491 register struct tcphdr *thp;
48492 register struct iphdr *ip;
48493 register struct cstate *cs;
48494- int len, hdrlen;
48495+ long len, hdrlen;
48496 unsigned char *cp = icp;
48497
48498 /* We've got a compressed packet; read the change byte */
48499diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
48500index 2368395..bf6fe96 100644
48501--- a/drivers/net/team/team.c
48502+++ b/drivers/net/team/team.c
48503@@ -2090,7 +2090,7 @@ static unsigned int team_get_num_rx_queues(void)
48504 return TEAM_DEFAULT_NUM_RX_QUEUES;
48505 }
48506
48507-static struct rtnl_link_ops team_link_ops __read_mostly = {
48508+static struct rtnl_link_ops team_link_ops = {
48509 .kind = DRV_NAME,
48510 .priv_size = sizeof(struct team),
48511 .setup = team_setup,
48512@@ -2880,7 +2880,7 @@ static int team_device_event(struct notifier_block *unused,
48513 return NOTIFY_DONE;
48514 }
48515
48516-static struct notifier_block team_notifier_block __read_mostly = {
48517+static struct notifier_block team_notifier_block = {
48518 .notifier_call = team_device_event,
48519 };
48520
48521diff --git a/drivers/net/tun.c b/drivers/net/tun.c
48522index 9dd3746..74f191e 100644
48523--- a/drivers/net/tun.c
48524+++ b/drivers/net/tun.c
48525@@ -1426,7 +1426,7 @@ static int tun_validate(struct nlattr *tb[], struct nlattr *data[])
48526 return -EINVAL;
48527 }
48528
48529-static struct rtnl_link_ops tun_link_ops __read_mostly = {
48530+static struct rtnl_link_ops tun_link_ops = {
48531 .kind = DRV_NAME,
48532 .priv_size = sizeof(struct tun_struct),
48533 .setup = tun_setup,
48534@@ -1868,7 +1868,7 @@ unlock:
48535 }
48536
48537 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
48538- unsigned long arg, int ifreq_len)
48539+ unsigned long arg, size_t ifreq_len)
48540 {
48541 struct tun_file *tfile = file->private_data;
48542 struct tun_struct *tun;
48543@@ -1881,6 +1881,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
48544 unsigned int ifindex;
48545 int ret;
48546
48547+ if (ifreq_len > sizeof ifr)
48548+ return -EFAULT;
48549+
48550 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
48551 if (copy_from_user(&ifr, argp, ifreq_len))
48552 return -EFAULT;
48553diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
48554index babda7d..e40c90a 100644
48555--- a/drivers/net/usb/hso.c
48556+++ b/drivers/net/usb/hso.c
48557@@ -71,7 +71,7 @@
48558 #include <asm/byteorder.h>
48559 #include <linux/serial_core.h>
48560 #include <linux/serial.h>
48561-
48562+#include <asm/local.h>
48563
48564 #define MOD_AUTHOR "Option Wireless"
48565 #define MOD_DESCRIPTION "USB High Speed Option driver"
48566@@ -1178,7 +1178,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
48567 struct urb *urb;
48568
48569 urb = serial->rx_urb[0];
48570- if (serial->port.count > 0) {
48571+ if (atomic_read(&serial->port.count) > 0) {
48572 count = put_rxbuf_data(urb, serial);
48573 if (count == -1)
48574 return;
48575@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
48576 DUMP1(urb->transfer_buffer, urb->actual_length);
48577
48578 /* Anyone listening? */
48579- if (serial->port.count == 0)
48580+ if (atomic_read(&serial->port.count) == 0)
48581 return;
48582
48583 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
48584@@ -1278,8 +1278,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
48585 tty_port_tty_set(&serial->port, tty);
48586
48587 /* check for port already opened, if not set the termios */
48588- serial->port.count++;
48589- if (serial->port.count == 1) {
48590+ if (atomic_inc_return(&serial->port.count) == 1) {
48591 serial->rx_state = RX_IDLE;
48592 /* Force default termio settings */
48593 _hso_serial_set_termios(tty, NULL);
48594@@ -1289,7 +1288,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
48595 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
48596 if (result) {
48597 hso_stop_serial_device(serial->parent);
48598- serial->port.count--;
48599+ atomic_dec(&serial->port.count);
48600 kref_put(&serial->parent->ref, hso_serial_ref_free);
48601 }
48602 } else {
48603@@ -1326,10 +1325,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
48604
48605 /* reset the rts and dtr */
48606 /* do the actual close */
48607- serial->port.count--;
48608+ atomic_dec(&serial->port.count);
48609
48610- if (serial->port.count <= 0) {
48611- serial->port.count = 0;
48612+ if (atomic_read(&serial->port.count) <= 0) {
48613+ atomic_set(&serial->port.count, 0);
48614 tty_port_tty_set(&serial->port, NULL);
48615 if (!usb_gone)
48616 hso_stop_serial_device(serial->parent);
48617@@ -1404,7 +1403,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
48618
48619 /* the actual setup */
48620 spin_lock_irqsave(&serial->serial_lock, flags);
48621- if (serial->port.count)
48622+ if (atomic_read(&serial->port.count))
48623 _hso_serial_set_termios(tty, old);
48624 else
48625 tty->termios = *old;
48626@@ -1873,7 +1872,7 @@ static void intr_callback(struct urb *urb)
48627 D1("Pending read interrupt on port %d\n", i);
48628 spin_lock(&serial->serial_lock);
48629 if (serial->rx_state == RX_IDLE &&
48630- serial->port.count > 0) {
48631+ atomic_read(&serial->port.count) > 0) {
48632 /* Setup and send a ctrl req read on
48633 * port i */
48634 if (!serial->rx_urb_filled[0]) {
48635@@ -3047,7 +3046,7 @@ static int hso_resume(struct usb_interface *iface)
48636 /* Start all serial ports */
48637 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
48638 if (serial_table[i] && (serial_table[i]->interface == iface)) {
48639- if (dev2ser(serial_table[i])->port.count) {
48640+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
48641 result =
48642 hso_start_serial_device(serial_table[i], GFP_NOIO);
48643 hso_kick_transmit(dev2ser(serial_table[i]));
48644diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
48645index c6554c7..7e2ebd7 100644
48646--- a/drivers/net/usb/r8152.c
48647+++ b/drivers/net/usb/r8152.c
48648@@ -577,7 +577,7 @@ struct r8152 {
48649 void (*unload)(struct r8152 *);
48650 int (*eee_get)(struct r8152 *, struct ethtool_eee *);
48651 int (*eee_set)(struct r8152 *, struct ethtool_eee *);
48652- } rtl_ops;
48653+ } __no_const rtl_ops;
48654
48655 int intr_interval;
48656 u32 saved_wolopts;
48657diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
48658index a2515887..6d13233 100644
48659--- a/drivers/net/usb/sierra_net.c
48660+++ b/drivers/net/usb/sierra_net.c
48661@@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
48662 /* atomic counter partially included in MAC address to make sure 2 devices
48663 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
48664 */
48665-static atomic_t iface_counter = ATOMIC_INIT(0);
48666+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
48667
48668 /*
48669 * SYNC Timer Delay definition used to set the expiry time
48670@@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
48671 dev->net->netdev_ops = &sierra_net_device_ops;
48672
48673 /* change MAC addr to include, ifacenum, and to be unique */
48674- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
48675+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
48676 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
48677
48678 /* we will have to manufacture ethernet headers, prepare template */
48679diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
48680index b0bc8ea..3af931b5 100644
48681--- a/drivers/net/virtio_net.c
48682+++ b/drivers/net/virtio_net.c
48683@@ -48,7 +48,7 @@ module_param(gso, bool, 0444);
48684 #define RECEIVE_AVG_WEIGHT 64
48685
48686 /* Minimum alignment for mergeable packet buffers. */
48687-#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256)
48688+#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256UL)
48689
48690 #define VIRTNET_DRIVER_VERSION "1.0.0"
48691
48692diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
48693index 42b2d6a5..2a2cb41 100644
48694--- a/drivers/net/vxlan.c
48695+++ b/drivers/net/vxlan.c
48696@@ -2695,7 +2695,7 @@ nla_put_failure:
48697 return -EMSGSIZE;
48698 }
48699
48700-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
48701+static struct rtnl_link_ops vxlan_link_ops = {
48702 .kind = "vxlan",
48703 .maxtype = IFLA_VXLAN_MAX,
48704 .policy = vxlan_policy,
48705@@ -2742,7 +2742,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
48706 return NOTIFY_DONE;
48707 }
48708
48709-static struct notifier_block vxlan_notifier_block __read_mostly = {
48710+static struct notifier_block vxlan_notifier_block = {
48711 .notifier_call = vxlan_lowerdev_event,
48712 };
48713
48714diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
48715index 5920c99..ff2e4a5 100644
48716--- a/drivers/net/wan/lmc/lmc_media.c
48717+++ b/drivers/net/wan/lmc/lmc_media.c
48718@@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
48719 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
48720
48721 lmc_media_t lmc_ds3_media = {
48722- lmc_ds3_init, /* special media init stuff */
48723- lmc_ds3_default, /* reset to default state */
48724- lmc_ds3_set_status, /* reset status to state provided */
48725- lmc_dummy_set_1, /* set clock source */
48726- lmc_dummy_set2_1, /* set line speed */
48727- lmc_ds3_set_100ft, /* set cable length */
48728- lmc_ds3_set_scram, /* set scrambler */
48729- lmc_ds3_get_link_status, /* get link status */
48730- lmc_dummy_set_1, /* set link status */
48731- lmc_ds3_set_crc_length, /* set CRC length */
48732- lmc_dummy_set_1, /* set T1 or E1 circuit type */
48733- lmc_ds3_watchdog
48734+ .init = lmc_ds3_init, /* special media init stuff */
48735+ .defaults = lmc_ds3_default, /* reset to default state */
48736+ .set_status = lmc_ds3_set_status, /* reset status to state provided */
48737+ .set_clock_source = lmc_dummy_set_1, /* set clock source */
48738+ .set_speed = lmc_dummy_set2_1, /* set line speed */
48739+ .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
48740+ .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
48741+ .get_link_status = lmc_ds3_get_link_status, /* get link status */
48742+ .set_link_status = lmc_dummy_set_1, /* set link status */
48743+ .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
48744+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
48745+ .watchdog = lmc_ds3_watchdog
48746 };
48747
48748 lmc_media_t lmc_hssi_media = {
48749- lmc_hssi_init, /* special media init stuff */
48750- lmc_hssi_default, /* reset to default state */
48751- lmc_hssi_set_status, /* reset status to state provided */
48752- lmc_hssi_set_clock, /* set clock source */
48753- lmc_dummy_set2_1, /* set line speed */
48754- lmc_dummy_set_1, /* set cable length */
48755- lmc_dummy_set_1, /* set scrambler */
48756- lmc_hssi_get_link_status, /* get link status */
48757- lmc_hssi_set_link_status, /* set link status */
48758- lmc_hssi_set_crc_length, /* set CRC length */
48759- lmc_dummy_set_1, /* set T1 or E1 circuit type */
48760- lmc_hssi_watchdog
48761+ .init = lmc_hssi_init, /* special media init stuff */
48762+ .defaults = lmc_hssi_default, /* reset to default state */
48763+ .set_status = lmc_hssi_set_status, /* reset status to state provided */
48764+ .set_clock_source = lmc_hssi_set_clock, /* set clock source */
48765+ .set_speed = lmc_dummy_set2_1, /* set line speed */
48766+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
48767+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
48768+ .get_link_status = lmc_hssi_get_link_status, /* get link status */
48769+ .set_link_status = lmc_hssi_set_link_status, /* set link status */
48770+ .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
48771+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
48772+ .watchdog = lmc_hssi_watchdog
48773 };
48774
48775-lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
48776- lmc_ssi_default, /* reset to default state */
48777- lmc_ssi_set_status, /* reset status to state provided */
48778- lmc_ssi_set_clock, /* set clock source */
48779- lmc_ssi_set_speed, /* set line speed */
48780- lmc_dummy_set_1, /* set cable length */
48781- lmc_dummy_set_1, /* set scrambler */
48782- lmc_ssi_get_link_status, /* get link status */
48783- lmc_ssi_set_link_status, /* set link status */
48784- lmc_ssi_set_crc_length, /* set CRC length */
48785- lmc_dummy_set_1, /* set T1 or E1 circuit type */
48786- lmc_ssi_watchdog
48787+lmc_media_t lmc_ssi_media = {
48788+ .init = lmc_ssi_init, /* special media init stuff */
48789+ .defaults = lmc_ssi_default, /* reset to default state */
48790+ .set_status = lmc_ssi_set_status, /* reset status to state provided */
48791+ .set_clock_source = lmc_ssi_set_clock, /* set clock source */
48792+ .set_speed = lmc_ssi_set_speed, /* set line speed */
48793+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
48794+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
48795+ .get_link_status = lmc_ssi_get_link_status, /* get link status */
48796+ .set_link_status = lmc_ssi_set_link_status, /* set link status */
48797+ .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
48798+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
48799+ .watchdog = lmc_ssi_watchdog
48800 };
48801
48802 lmc_media_t lmc_t1_media = {
48803- lmc_t1_init, /* special media init stuff */
48804- lmc_t1_default, /* reset to default state */
48805- lmc_t1_set_status, /* reset status to state provided */
48806- lmc_t1_set_clock, /* set clock source */
48807- lmc_dummy_set2_1, /* set line speed */
48808- lmc_dummy_set_1, /* set cable length */
48809- lmc_dummy_set_1, /* set scrambler */
48810- lmc_t1_get_link_status, /* get link status */
48811- lmc_dummy_set_1, /* set link status */
48812- lmc_t1_set_crc_length, /* set CRC length */
48813- lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
48814- lmc_t1_watchdog
48815+ .init = lmc_t1_init, /* special media init stuff */
48816+ .defaults = lmc_t1_default, /* reset to default state */
48817+ .set_status = lmc_t1_set_status, /* reset status to state provided */
48818+ .set_clock_source = lmc_t1_set_clock, /* set clock source */
48819+ .set_speed = lmc_dummy_set2_1, /* set line speed */
48820+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
48821+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
48822+ .get_link_status = lmc_t1_get_link_status, /* get link status */
48823+ .set_link_status = lmc_dummy_set_1, /* set link status */
48824+ .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
48825+ .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
48826+ .watchdog = lmc_t1_watchdog
48827 };
48828
48829 static void
48830diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
48831index feacc3b..5bac0de 100644
48832--- a/drivers/net/wan/z85230.c
48833+++ b/drivers/net/wan/z85230.c
48834@@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
48835
48836 struct z8530_irqhandler z8530_sync =
48837 {
48838- z8530_rx,
48839- z8530_tx,
48840- z8530_status
48841+ .rx = z8530_rx,
48842+ .tx = z8530_tx,
48843+ .status = z8530_status
48844 };
48845
48846 EXPORT_SYMBOL(z8530_sync);
48847@@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
48848 }
48849
48850 static struct z8530_irqhandler z8530_dma_sync = {
48851- z8530_dma_rx,
48852- z8530_dma_tx,
48853- z8530_dma_status
48854+ .rx = z8530_dma_rx,
48855+ .tx = z8530_dma_tx,
48856+ .status = z8530_dma_status
48857 };
48858
48859 static struct z8530_irqhandler z8530_txdma_sync = {
48860- z8530_rx,
48861- z8530_dma_tx,
48862- z8530_dma_status
48863+ .rx = z8530_rx,
48864+ .tx = z8530_dma_tx,
48865+ .status = z8530_dma_status
48866 };
48867
48868 /**
48869@@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
48870
48871 struct z8530_irqhandler z8530_nop=
48872 {
48873- z8530_rx_clear,
48874- z8530_tx_clear,
48875- z8530_status_clear
48876+ .rx = z8530_rx_clear,
48877+ .tx = z8530_tx_clear,
48878+ .status = z8530_status_clear
48879 };
48880
48881
48882diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
48883index 0b60295..b8bfa5b 100644
48884--- a/drivers/net/wimax/i2400m/rx.c
48885+++ b/drivers/net/wimax/i2400m/rx.c
48886@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
48887 if (i2400m->rx_roq == NULL)
48888 goto error_roq_alloc;
48889
48890- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
48891+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
48892 GFP_KERNEL);
48893 if (rd == NULL) {
48894 result = -ENOMEM;
48895diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
48896index e71a2ce..2268d61 100644
48897--- a/drivers/net/wireless/airo.c
48898+++ b/drivers/net/wireless/airo.c
48899@@ -7846,7 +7846,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
48900 struct airo_info *ai = dev->ml_priv;
48901 int ridcode;
48902 int enabled;
48903- static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
48904+ int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
48905 unsigned char *iobuf;
48906
48907 /* Only super-user can write RIDs */
48908diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
48909index da92bfa..5a9001a 100644
48910--- a/drivers/net/wireless/at76c50x-usb.c
48911+++ b/drivers/net/wireless/at76c50x-usb.c
48912@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
48913 }
48914
48915 /* Convert timeout from the DFU status to jiffies */
48916-static inline unsigned long at76_get_timeout(struct dfu_status *s)
48917+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
48918 {
48919 return msecs_to_jiffies((s->poll_timeout[2] << 16)
48920 | (s->poll_timeout[1] << 8)
48921diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
48922index 676bd4e..0b807a3 100644
48923--- a/drivers/net/wireless/ath/ath10k/htc.c
48924+++ b/drivers/net/wireless/ath/ath10k/htc.c
48925@@ -848,7 +848,10 @@ int ath10k_htc_start(struct ath10k_htc *htc)
48926 /* registered target arrival callback from the HIF layer */
48927 int ath10k_htc_init(struct ath10k *ar)
48928 {
48929- struct ath10k_hif_cb htc_callbacks;
48930+ static struct ath10k_hif_cb htc_callbacks = {
48931+ .rx_completion = ath10k_htc_rx_completion_handler,
48932+ .tx_completion = ath10k_htc_tx_completion_handler,
48933+ };
48934 struct ath10k_htc_ep *ep = NULL;
48935 struct ath10k_htc *htc = &ar->htc;
48936
48937@@ -857,8 +860,6 @@ int ath10k_htc_init(struct ath10k *ar)
48938 ath10k_htc_reset_endpoint_states(htc);
48939
48940 /* setup HIF layer callbacks */
48941- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
48942- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
48943 htc->ar = ar;
48944
48945 /* Get HIF default pipe for HTC message exchange */
48946diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
48947index 527179c..a890150 100644
48948--- a/drivers/net/wireless/ath/ath10k/htc.h
48949+++ b/drivers/net/wireless/ath/ath10k/htc.h
48950@@ -270,13 +270,13 @@ enum ath10k_htc_ep_id {
48951
48952 struct ath10k_htc_ops {
48953 void (*target_send_suspend_complete)(struct ath10k *ar);
48954-};
48955+} __no_const;
48956
48957 struct ath10k_htc_ep_ops {
48958 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
48959 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
48960 void (*ep_tx_credits)(struct ath10k *);
48961-};
48962+} __no_const;
48963
48964 /* service connection information */
48965 struct ath10k_htc_svc_conn_req {
48966diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
48967index 2a93519..7052786 100644
48968--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
48969+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
48970@@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
48971 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
48972 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
48973
48974- ACCESS_ONCE(ads->ds_link) = i->link;
48975- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
48976+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
48977+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
48978
48979 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
48980 ctl6 = SM(i->keytype, AR_EncrType);
48981@@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
48982
48983 if ((i->is_first || i->is_last) &&
48984 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
48985- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
48986+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
48987 | set11nTries(i->rates, 1)
48988 | set11nTries(i->rates, 2)
48989 | set11nTries(i->rates, 3)
48990 | (i->dur_update ? AR_DurUpdateEna : 0)
48991 | SM(0, AR_BurstDur);
48992
48993- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
48994+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
48995 | set11nRate(i->rates, 1)
48996 | set11nRate(i->rates, 2)
48997 | set11nRate(i->rates, 3);
48998 } else {
48999- ACCESS_ONCE(ads->ds_ctl2) = 0;
49000- ACCESS_ONCE(ads->ds_ctl3) = 0;
49001+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
49002+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
49003 }
49004
49005 if (!i->is_first) {
49006- ACCESS_ONCE(ads->ds_ctl0) = 0;
49007- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
49008- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
49009+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
49010+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
49011+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
49012 return;
49013 }
49014
49015@@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49016 break;
49017 }
49018
49019- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
49020+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
49021 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
49022 | SM(i->txpower, AR_XmitPower0)
49023 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
49024@@ -289,27 +289,27 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49025 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
49026 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
49027
49028- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
49029- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
49030+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
49031+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
49032
49033 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
49034 return;
49035
49036- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
49037+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
49038 | set11nPktDurRTSCTS(i->rates, 1);
49039
49040- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
49041+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
49042 | set11nPktDurRTSCTS(i->rates, 3);
49043
49044- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
49045+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
49046 | set11nRateFlags(i->rates, 1)
49047 | set11nRateFlags(i->rates, 2)
49048 | set11nRateFlags(i->rates, 3)
49049 | SM(i->rtscts_rate, AR_RTSCTSRate);
49050
49051- ACCESS_ONCE(ads->ds_ctl9) = SM(i->txpower, AR_XmitPower1);
49052- ACCESS_ONCE(ads->ds_ctl10) = SM(i->txpower, AR_XmitPower2);
49053- ACCESS_ONCE(ads->ds_ctl11) = SM(i->txpower, AR_XmitPower3);
49054+ ACCESS_ONCE_RW(ads->ds_ctl9) = SM(i->txpower, AR_XmitPower1);
49055+ ACCESS_ONCE_RW(ads->ds_ctl10) = SM(i->txpower, AR_XmitPower2);
49056+ ACCESS_ONCE_RW(ads->ds_ctl11) = SM(i->txpower, AR_XmitPower3);
49057 }
49058
49059 static int ar9002_hw_proc_txdesc(struct ath_hw *ah, void *ds,
49060diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49061index 057b165..98ae88f 100644
49062--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49063+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49064@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49065 (i->qcu << AR_TxQcuNum_S) | desc_len;
49066
49067 checksum += val;
49068- ACCESS_ONCE(ads->info) = val;
49069+ ACCESS_ONCE_RW(ads->info) = val;
49070
49071 checksum += i->link;
49072- ACCESS_ONCE(ads->link) = i->link;
49073+ ACCESS_ONCE_RW(ads->link) = i->link;
49074
49075 checksum += i->buf_addr[0];
49076- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
49077+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
49078 checksum += i->buf_addr[1];
49079- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
49080+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
49081 checksum += i->buf_addr[2];
49082- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
49083+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
49084 checksum += i->buf_addr[3];
49085- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
49086+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
49087
49088 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
49089- ACCESS_ONCE(ads->ctl3) = val;
49090+ ACCESS_ONCE_RW(ads->ctl3) = val;
49091 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
49092- ACCESS_ONCE(ads->ctl5) = val;
49093+ ACCESS_ONCE_RW(ads->ctl5) = val;
49094 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
49095- ACCESS_ONCE(ads->ctl7) = val;
49096+ ACCESS_ONCE_RW(ads->ctl7) = val;
49097 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
49098- ACCESS_ONCE(ads->ctl9) = val;
49099+ ACCESS_ONCE_RW(ads->ctl9) = val;
49100
49101 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
49102- ACCESS_ONCE(ads->ctl10) = checksum;
49103+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
49104
49105 if (i->is_first || i->is_last) {
49106- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
49107+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
49108 | set11nTries(i->rates, 1)
49109 | set11nTries(i->rates, 2)
49110 | set11nTries(i->rates, 3)
49111 | (i->dur_update ? AR_DurUpdateEna : 0)
49112 | SM(0, AR_BurstDur);
49113
49114- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
49115+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
49116 | set11nRate(i->rates, 1)
49117 | set11nRate(i->rates, 2)
49118 | set11nRate(i->rates, 3);
49119 } else {
49120- ACCESS_ONCE(ads->ctl13) = 0;
49121- ACCESS_ONCE(ads->ctl14) = 0;
49122+ ACCESS_ONCE_RW(ads->ctl13) = 0;
49123+ ACCESS_ONCE_RW(ads->ctl14) = 0;
49124 }
49125
49126 ads->ctl20 = 0;
49127@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49128
49129 ctl17 = SM(i->keytype, AR_EncrType);
49130 if (!i->is_first) {
49131- ACCESS_ONCE(ads->ctl11) = 0;
49132- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
49133- ACCESS_ONCE(ads->ctl15) = 0;
49134- ACCESS_ONCE(ads->ctl16) = 0;
49135- ACCESS_ONCE(ads->ctl17) = ctl17;
49136- ACCESS_ONCE(ads->ctl18) = 0;
49137- ACCESS_ONCE(ads->ctl19) = 0;
49138+ ACCESS_ONCE_RW(ads->ctl11) = 0;
49139+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
49140+ ACCESS_ONCE_RW(ads->ctl15) = 0;
49141+ ACCESS_ONCE_RW(ads->ctl16) = 0;
49142+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
49143+ ACCESS_ONCE_RW(ads->ctl18) = 0;
49144+ ACCESS_ONCE_RW(ads->ctl19) = 0;
49145 return;
49146 }
49147
49148- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
49149+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
49150 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
49151 | SM(i->txpower, AR_XmitPower0)
49152 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
49153@@ -135,26 +135,26 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49154 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
49155 ctl12 |= SM(val, AR_PAPRDChainMask);
49156
49157- ACCESS_ONCE(ads->ctl12) = ctl12;
49158- ACCESS_ONCE(ads->ctl17) = ctl17;
49159+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
49160+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
49161
49162- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
49163+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
49164 | set11nPktDurRTSCTS(i->rates, 1);
49165
49166- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
49167+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
49168 | set11nPktDurRTSCTS(i->rates, 3);
49169
49170- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
49171+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
49172 | set11nRateFlags(i->rates, 1)
49173 | set11nRateFlags(i->rates, 2)
49174 | set11nRateFlags(i->rates, 3)
49175 | SM(i->rtscts_rate, AR_RTSCTSRate);
49176
49177- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
49178+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
49179
49180- ACCESS_ONCE(ads->ctl20) = SM(i->txpower, AR_XmitPower1);
49181- ACCESS_ONCE(ads->ctl21) = SM(i->txpower, AR_XmitPower2);
49182- ACCESS_ONCE(ads->ctl22) = SM(i->txpower, AR_XmitPower3);
49183+ ACCESS_ONCE_RW(ads->ctl20) = SM(i->txpower, AR_XmitPower1);
49184+ ACCESS_ONCE_RW(ads->ctl21) = SM(i->txpower, AR_XmitPower2);
49185+ ACCESS_ONCE_RW(ads->ctl22) = SM(i->txpower, AR_XmitPower3);
49186 }
49187
49188 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
49189diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
49190index 975074f..e9440da 100644
49191--- a/drivers/net/wireless/ath/ath9k/hw.h
49192+++ b/drivers/net/wireless/ath/ath9k/hw.h
49193@@ -630,7 +630,7 @@ struct ath_hw_private_ops {
49194
49195 /* ANI */
49196 void (*ani_cache_ini_regs)(struct ath_hw *ah);
49197-};
49198+} __no_const;
49199
49200 /**
49201 * struct ath_spec_scan - parameters for Atheros spectral scan
49202@@ -708,7 +708,7 @@ struct ath_hw_ops {
49203 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
49204 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
49205 #endif
49206-};
49207+} __no_const;
49208
49209 struct ath_nf_limits {
49210 s16 max;
49211diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
49212index 4f18a6b..b07d92f 100644
49213--- a/drivers/net/wireless/ath/ath9k/main.c
49214+++ b/drivers/net/wireless/ath/ath9k/main.c
49215@@ -2454,16 +2454,18 @@ void ath9k_fill_chanctx_ops(void)
49216 if (!ath9k_is_chanctx_enabled())
49217 return;
49218
49219- ath9k_ops.hw_scan = ath9k_hw_scan;
49220- ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
49221- ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
49222- ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
49223- ath9k_ops.add_chanctx = ath9k_add_chanctx;
49224- ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
49225- ath9k_ops.change_chanctx = ath9k_change_chanctx;
49226- ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
49227- ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
49228- ath9k_ops.mgd_prepare_tx = ath9k_mgd_prepare_tx;
49229+ pax_open_kernel();
49230+ *(void **)&ath9k_ops.hw_scan = ath9k_hw_scan;
49231+ *(void **)&ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
49232+ *(void **)&ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
49233+ *(void **)&ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
49234+ *(void **)&ath9k_ops.add_chanctx = ath9k_add_chanctx;
49235+ *(void **)&ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
49236+ *(void **)&ath9k_ops.change_chanctx = ath9k_change_chanctx;
49237+ *(void **)&ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
49238+ *(void **)&ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
49239+ *(void **)&ath9k_ops.mgd_prepare_tx = ath9k_mgd_prepare_tx;
49240+ pax_close_kernel();
49241 }
49242
49243 #endif
49244diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
49245index 058a9f2..d5cb1ba 100644
49246--- a/drivers/net/wireless/b43/phy_lp.c
49247+++ b/drivers/net/wireless/b43/phy_lp.c
49248@@ -2502,7 +2502,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
49249 {
49250 struct ssb_bus *bus = dev->dev->sdev->bus;
49251
49252- static const struct b206x_channel *chandata = NULL;
49253+ const struct b206x_channel *chandata = NULL;
49254 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
49255 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
49256 u16 old_comm15, scale;
49257diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
49258index dc1d20c..f7a4f06 100644
49259--- a/drivers/net/wireless/iwlegacy/3945-mac.c
49260+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
49261@@ -3633,7 +3633,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
49262 */
49263 if (il3945_mod_params.disable_hw_scan) {
49264 D_INFO("Disabling hw_scan\n");
49265- il3945_mac_ops.hw_scan = NULL;
49266+ pax_open_kernel();
49267+ *(void **)&il3945_mac_ops.hw_scan = NULL;
49268+ pax_close_kernel();
49269 }
49270
49271 D_INFO("*** LOAD DRIVER ***\n");
49272diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49273index 0ffb6ff..c0b7f0e 100644
49274--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49275+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49276@@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
49277 {
49278 struct iwl_priv *priv = file->private_data;
49279 char buf[64];
49280- int buf_size;
49281+ size_t buf_size;
49282 u32 offset, len;
49283
49284 memset(buf, 0, sizeof(buf));
49285@@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
49286 struct iwl_priv *priv = file->private_data;
49287
49288 char buf[8];
49289- int buf_size;
49290+ size_t buf_size;
49291 u32 reset_flag;
49292
49293 memset(buf, 0, sizeof(buf));
49294@@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
49295 {
49296 struct iwl_priv *priv = file->private_data;
49297 char buf[8];
49298- int buf_size;
49299+ size_t buf_size;
49300 int ht40;
49301
49302 memset(buf, 0, sizeof(buf));
49303@@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
49304 {
49305 struct iwl_priv *priv = file->private_data;
49306 char buf[8];
49307- int buf_size;
49308+ size_t buf_size;
49309 int value;
49310
49311 memset(buf, 0, sizeof(buf));
49312@@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
49313 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
49314 DEBUGFS_READ_FILE_OPS(current_sleep_command);
49315
49316-static const char *fmt_value = " %-30s %10u\n";
49317-static const char *fmt_hex = " %-30s 0x%02X\n";
49318-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
49319-static const char *fmt_header =
49320+static const char fmt_value[] = " %-30s %10u\n";
49321+static const char fmt_hex[] = " %-30s 0x%02X\n";
49322+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
49323+static const char fmt_header[] =
49324 "%-32s current cumulative delta max\n";
49325
49326 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
49327@@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
49328 {
49329 struct iwl_priv *priv = file->private_data;
49330 char buf[8];
49331- int buf_size;
49332+ size_t buf_size;
49333 int clear;
49334
49335 memset(buf, 0, sizeof(buf));
49336@@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
49337 {
49338 struct iwl_priv *priv = file->private_data;
49339 char buf[8];
49340- int buf_size;
49341+ size_t buf_size;
49342 int trace;
49343
49344 memset(buf, 0, sizeof(buf));
49345@@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
49346 {
49347 struct iwl_priv *priv = file->private_data;
49348 char buf[8];
49349- int buf_size;
49350+ size_t buf_size;
49351 int missed;
49352
49353 memset(buf, 0, sizeof(buf));
49354@@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
49355
49356 struct iwl_priv *priv = file->private_data;
49357 char buf[8];
49358- int buf_size;
49359+ size_t buf_size;
49360 int plcp;
49361
49362 memset(buf, 0, sizeof(buf));
49363@@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
49364
49365 struct iwl_priv *priv = file->private_data;
49366 char buf[8];
49367- int buf_size;
49368+ size_t buf_size;
49369 int flush;
49370
49371 memset(buf, 0, sizeof(buf));
49372@@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
49373
49374 struct iwl_priv *priv = file->private_data;
49375 char buf[8];
49376- int buf_size;
49377+ size_t buf_size;
49378 int rts;
49379
49380 if (!priv->cfg->ht_params)
49381@@ -2204,7 +2204,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
49382 {
49383 struct iwl_priv *priv = file->private_data;
49384 char buf[8];
49385- int buf_size;
49386+ size_t buf_size;
49387
49388 memset(buf, 0, sizeof(buf));
49389 buf_size = min(count, sizeof(buf) - 1);
49390@@ -2238,7 +2238,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
49391 struct iwl_priv *priv = file->private_data;
49392 u32 event_log_flag;
49393 char buf[8];
49394- int buf_size;
49395+ size_t buf_size;
49396
49397 /* check that the interface is up */
49398 if (!iwl_is_ready(priv))
49399@@ -2292,7 +2292,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
49400 struct iwl_priv *priv = file->private_data;
49401 char buf[8];
49402 u32 calib_disabled;
49403- int buf_size;
49404+ size_t buf_size;
49405
49406 memset(buf, 0, sizeof(buf));
49407 buf_size = min(count, sizeof(buf) - 1);
49408diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
49409index dd2f3f8..fb1ae88 100644
49410--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
49411+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
49412@@ -1689,7 +1689,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
49413 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
49414
49415 char buf[8];
49416- int buf_size;
49417+ size_t buf_size;
49418 u32 reset_flag;
49419
49420 memset(buf, 0, sizeof(buf));
49421@@ -1710,7 +1710,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
49422 {
49423 struct iwl_trans *trans = file->private_data;
49424 char buf[8];
49425- int buf_size;
49426+ size_t buf_size;
49427 int csr;
49428
49429 memset(buf, 0, sizeof(buf));
49430diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
49431index c9ad4cf..49a2fa0 100644
49432--- a/drivers/net/wireless/mac80211_hwsim.c
49433+++ b/drivers/net/wireless/mac80211_hwsim.c
49434@@ -2577,20 +2577,20 @@ static int __init init_mac80211_hwsim(void)
49435 if (channels < 1)
49436 return -EINVAL;
49437
49438- mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
49439- mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
49440- mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
49441- mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
49442- mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
49443- mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
49444- mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
49445- mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
49446- mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
49447- mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
49448- mac80211_hwsim_mchan_ops.assign_vif_chanctx =
49449- mac80211_hwsim_assign_vif_chanctx;
49450- mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
49451- mac80211_hwsim_unassign_vif_chanctx;
49452+ pax_open_kernel();
49453+ memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
49454+ *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
49455+ *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
49456+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
49457+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
49458+ *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
49459+ *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
49460+ *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
49461+ *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
49462+ *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
49463+ *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
49464+ *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
49465+ pax_close_kernel();
49466
49467 spin_lock_init(&hwsim_radio_lock);
49468 INIT_LIST_HEAD(&hwsim_radios);
49469diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
49470index 1a4facd..a2ecbbd 100644
49471--- a/drivers/net/wireless/rndis_wlan.c
49472+++ b/drivers/net/wireless/rndis_wlan.c
49473@@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
49474
49475 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
49476
49477- if (rts_threshold < 0 || rts_threshold > 2347)
49478+ if (rts_threshold > 2347)
49479 rts_threshold = 2347;
49480
49481 tmp = cpu_to_le32(rts_threshold);
49482diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
49483index d13f25c..2573994 100644
49484--- a/drivers/net/wireless/rt2x00/rt2x00.h
49485+++ b/drivers/net/wireless/rt2x00/rt2x00.h
49486@@ -375,7 +375,7 @@ struct rt2x00_intf {
49487 * for hardware which doesn't support hardware
49488 * sequence counting.
49489 */
49490- atomic_t seqno;
49491+ atomic_unchecked_t seqno;
49492 };
49493
49494 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
49495diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
49496index 66ff364..3ce34f7 100644
49497--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
49498+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
49499@@ -224,9 +224,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
49500 * sequence counter given by mac80211.
49501 */
49502 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
49503- seqno = atomic_add_return(0x10, &intf->seqno);
49504+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
49505 else
49506- seqno = atomic_read(&intf->seqno);
49507+ seqno = atomic_read_unchecked(&intf->seqno);
49508
49509 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
49510 hdr->seq_ctrl |= cpu_to_le16(seqno);
49511diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
49512index b661f896..ddf7d2b 100644
49513--- a/drivers/net/wireless/ti/wl1251/sdio.c
49514+++ b/drivers/net/wireless/ti/wl1251/sdio.c
49515@@ -282,13 +282,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
49516
49517 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
49518
49519- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
49520- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
49521+ pax_open_kernel();
49522+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
49523+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
49524+ pax_close_kernel();
49525
49526 wl1251_info("using dedicated interrupt line");
49527 } else {
49528- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
49529- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
49530+ pax_open_kernel();
49531+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
49532+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
49533+ pax_close_kernel();
49534
49535 wl1251_info("using SDIO interrupt");
49536 }
49537diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
49538index 0bccf12..3d95068 100644
49539--- a/drivers/net/wireless/ti/wl12xx/main.c
49540+++ b/drivers/net/wireless/ti/wl12xx/main.c
49541@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
49542 sizeof(wl->conf.mem));
49543
49544 /* read data preparation is only needed by wl127x */
49545- wl->ops->prepare_read = wl127x_prepare_read;
49546+ pax_open_kernel();
49547+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
49548+ pax_close_kernel();
49549
49550 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
49551 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
49552@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
49553 sizeof(wl->conf.mem));
49554
49555 /* read data preparation is only needed by wl127x */
49556- wl->ops->prepare_read = wl127x_prepare_read;
49557+ pax_open_kernel();
49558+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
49559+ pax_close_kernel();
49560
49561 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
49562 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
49563diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
49564index 7af1936..128bb35 100644
49565--- a/drivers/net/wireless/ti/wl18xx/main.c
49566+++ b/drivers/net/wireless/ti/wl18xx/main.c
49567@@ -1916,8 +1916,10 @@ static int wl18xx_setup(struct wl1271 *wl)
49568 }
49569
49570 if (!checksum_param) {
49571- wl18xx_ops.set_rx_csum = NULL;
49572- wl18xx_ops.init_vif = NULL;
49573+ pax_open_kernel();
49574+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
49575+ *(void **)&wl18xx_ops.init_vif = NULL;
49576+ pax_close_kernel();
49577 }
49578
49579 /* Enable 11a Band only if we have 5G antennas */
49580diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
49581index a912dc0..a8225ba 100644
49582--- a/drivers/net/wireless/zd1211rw/zd_usb.c
49583+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
49584@@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
49585 {
49586 struct zd_usb *usb = urb->context;
49587 struct zd_usb_interrupt *intr = &usb->intr;
49588- int len;
49589+ unsigned int len;
49590 u16 int_num;
49591
49592 ZD_ASSERT(in_interrupt());
49593diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
49594index 683671a..4519fc2 100644
49595--- a/drivers/nfc/nfcwilink.c
49596+++ b/drivers/nfc/nfcwilink.c
49597@@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
49598
49599 static int nfcwilink_probe(struct platform_device *pdev)
49600 {
49601- static struct nfcwilink *drv;
49602+ struct nfcwilink *drv;
49603 int rc;
49604 __u32 protocols;
49605
49606diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
49607index d93b2b6..ae50401 100644
49608--- a/drivers/oprofile/buffer_sync.c
49609+++ b/drivers/oprofile/buffer_sync.c
49610@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
49611 if (cookie == NO_COOKIE)
49612 offset = pc;
49613 if (cookie == INVALID_COOKIE) {
49614- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
49615+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
49616 offset = pc;
49617 }
49618 if (cookie != last_cookie) {
49619@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
49620 /* add userspace sample */
49621
49622 if (!mm) {
49623- atomic_inc(&oprofile_stats.sample_lost_no_mm);
49624+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
49625 return 0;
49626 }
49627
49628 cookie = lookup_dcookie(mm, s->eip, &offset);
49629
49630 if (cookie == INVALID_COOKIE) {
49631- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
49632+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
49633 return 0;
49634 }
49635
49636@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
49637 /* ignore backtraces if failed to add a sample */
49638 if (state == sb_bt_start) {
49639 state = sb_bt_ignore;
49640- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
49641+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
49642 }
49643 }
49644 release_mm(mm);
49645diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
49646index c0cc4e7..44d4e54 100644
49647--- a/drivers/oprofile/event_buffer.c
49648+++ b/drivers/oprofile/event_buffer.c
49649@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
49650 }
49651
49652 if (buffer_pos == buffer_size) {
49653- atomic_inc(&oprofile_stats.event_lost_overflow);
49654+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
49655 return;
49656 }
49657
49658diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
49659index ed2c3ec..deda85a 100644
49660--- a/drivers/oprofile/oprof.c
49661+++ b/drivers/oprofile/oprof.c
49662@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
49663 if (oprofile_ops.switch_events())
49664 return;
49665
49666- atomic_inc(&oprofile_stats.multiplex_counter);
49667+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
49668 start_switch_worker();
49669 }
49670
49671diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
49672index ee2cfce..7f8f699 100644
49673--- a/drivers/oprofile/oprofile_files.c
49674+++ b/drivers/oprofile/oprofile_files.c
49675@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
49676
49677 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
49678
49679-static ssize_t timeout_read(struct file *file, char __user *buf,
49680+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
49681 size_t count, loff_t *offset)
49682 {
49683 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
49684diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
49685index 59659ce..6c860a0 100644
49686--- a/drivers/oprofile/oprofile_stats.c
49687+++ b/drivers/oprofile/oprofile_stats.c
49688@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
49689 cpu_buf->sample_invalid_eip = 0;
49690 }
49691
49692- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
49693- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
49694- atomic_set(&oprofile_stats.event_lost_overflow, 0);
49695- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
49696- atomic_set(&oprofile_stats.multiplex_counter, 0);
49697+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
49698+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
49699+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
49700+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
49701+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
49702 }
49703
49704
49705diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
49706index 1fc622b..8c48fc3 100644
49707--- a/drivers/oprofile/oprofile_stats.h
49708+++ b/drivers/oprofile/oprofile_stats.h
49709@@ -13,11 +13,11 @@
49710 #include <linux/atomic.h>
49711
49712 struct oprofile_stat_struct {
49713- atomic_t sample_lost_no_mm;
49714- atomic_t sample_lost_no_mapping;
49715- atomic_t bt_lost_no_mapping;
49716- atomic_t event_lost_overflow;
49717- atomic_t multiplex_counter;
49718+ atomic_unchecked_t sample_lost_no_mm;
49719+ atomic_unchecked_t sample_lost_no_mapping;
49720+ atomic_unchecked_t bt_lost_no_mapping;
49721+ atomic_unchecked_t event_lost_overflow;
49722+ atomic_unchecked_t multiplex_counter;
49723 };
49724
49725 extern struct oprofile_stat_struct oprofile_stats;
49726diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
49727index 3f49345..c750d0b 100644
49728--- a/drivers/oprofile/oprofilefs.c
49729+++ b/drivers/oprofile/oprofilefs.c
49730@@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
49731
49732 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
49733 {
49734- atomic_t *val = file->private_data;
49735- return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
49736+ atomic_unchecked_t *val = file->private_data;
49737+ return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
49738 }
49739
49740
49741@@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
49742
49743
49744 int oprofilefs_create_ro_atomic(struct dentry *root,
49745- char const *name, atomic_t *val)
49746+ char const *name, atomic_unchecked_t *val)
49747 {
49748 return __oprofilefs_create_file(root, name,
49749 &atomic_ro_fops, 0444, val);
49750diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
49751index bdef916..88c7dee 100644
49752--- a/drivers/oprofile/timer_int.c
49753+++ b/drivers/oprofile/timer_int.c
49754@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
49755 return NOTIFY_OK;
49756 }
49757
49758-static struct notifier_block __refdata oprofile_cpu_notifier = {
49759+static struct notifier_block oprofile_cpu_notifier = {
49760 .notifier_call = oprofile_cpu_notify,
49761 };
49762
49763diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
49764index 3b47080..6cd05dd 100644
49765--- a/drivers/parport/procfs.c
49766+++ b/drivers/parport/procfs.c
49767@@ -64,7 +64,7 @@ static int do_active_device(struct ctl_table *table, int write,
49768
49769 *ppos += len;
49770
49771- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
49772+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
49773 }
49774
49775 #ifdef CONFIG_PARPORT_1284
49776@@ -106,7 +106,7 @@ static int do_autoprobe(struct ctl_table *table, int write,
49777
49778 *ppos += len;
49779
49780- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
49781+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
49782 }
49783 #endif /* IEEE1284.3 support. */
49784
49785diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
49786index 6ca2399..68d866b 100644
49787--- a/drivers/pci/hotplug/acpiphp_ibm.c
49788+++ b/drivers/pci/hotplug/acpiphp_ibm.c
49789@@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
49790 goto init_cleanup;
49791 }
49792
49793- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
49794+ pax_open_kernel();
49795+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
49796+ pax_close_kernel();
49797 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
49798
49799 return retval;
49800diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
49801index 66b7bbe..26bee78 100644
49802--- a/drivers/pci/hotplug/cpcihp_generic.c
49803+++ b/drivers/pci/hotplug/cpcihp_generic.c
49804@@ -73,7 +73,6 @@ static u16 port;
49805 static unsigned int enum_bit;
49806 static u8 enum_mask;
49807
49808-static struct cpci_hp_controller_ops generic_hpc_ops;
49809 static struct cpci_hp_controller generic_hpc;
49810
49811 static int __init validate_parameters(void)
49812@@ -139,6 +138,10 @@ static int query_enum(void)
49813 return ((value & enum_mask) == enum_mask);
49814 }
49815
49816+static struct cpci_hp_controller_ops generic_hpc_ops = {
49817+ .query_enum = query_enum,
49818+};
49819+
49820 static int __init cpcihp_generic_init(void)
49821 {
49822 int status;
49823@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
49824 pci_dev_put(dev);
49825
49826 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
49827- generic_hpc_ops.query_enum = query_enum;
49828 generic_hpc.ops = &generic_hpc_ops;
49829
49830 status = cpci_hp_register_controller(&generic_hpc);
49831diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
49832index 7ecf34e..effed62 100644
49833--- a/drivers/pci/hotplug/cpcihp_zt5550.c
49834+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
49835@@ -59,7 +59,6 @@
49836 /* local variables */
49837 static bool debug;
49838 static bool poll;
49839-static struct cpci_hp_controller_ops zt5550_hpc_ops;
49840 static struct cpci_hp_controller zt5550_hpc;
49841
49842 /* Primary cPCI bus bridge device */
49843@@ -204,6 +203,10 @@ static int zt5550_hc_disable_irq(void)
49844 return 0;
49845 }
49846
49847+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
49848+ .query_enum = zt5550_hc_query_enum,
49849+};
49850+
49851 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
49852 {
49853 int status;
49854@@ -215,16 +218,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
49855 dbg("returned from zt5550_hc_config");
49856
49857 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
49858- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
49859 zt5550_hpc.ops = &zt5550_hpc_ops;
49860 if (!poll) {
49861 zt5550_hpc.irq = hc_dev->irq;
49862 zt5550_hpc.irq_flags = IRQF_SHARED;
49863 zt5550_hpc.dev_id = hc_dev;
49864
49865- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
49866- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
49867- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
49868+ pax_open_kernel();
49869+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
49870+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
49871+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
49872+ pax_open_kernel();
49873 } else {
49874 info("using ENUM# polling mode");
49875 }
49876diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
49877index 1e08ff8c..3cd145f 100644
49878--- a/drivers/pci/hotplug/cpqphp_nvram.c
49879+++ b/drivers/pci/hotplug/cpqphp_nvram.c
49880@@ -425,8 +425,10 @@ static u32 store_HRT (void __iomem *rom_start)
49881
49882 void compaq_nvram_init (void __iomem *rom_start)
49883 {
49884+#ifndef CONFIG_PAX_KERNEXEC
49885 if (rom_start)
49886 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
49887+#endif
49888
49889 dbg("int15 entry = %p\n", compaq_int15_entry_point);
49890
49891diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
49892index 56d8486..f26113f 100644
49893--- a/drivers/pci/hotplug/pci_hotplug_core.c
49894+++ b/drivers/pci/hotplug/pci_hotplug_core.c
49895@@ -436,8 +436,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
49896 return -EINVAL;
49897 }
49898
49899- slot->ops->owner = owner;
49900- slot->ops->mod_name = mod_name;
49901+ pax_open_kernel();
49902+ *(struct module **)&slot->ops->owner = owner;
49903+ *(const char **)&slot->ops->mod_name = mod_name;
49904+ pax_close_kernel();
49905
49906 mutex_lock(&pci_hp_mutex);
49907 /*
49908diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
49909index 07aa722..84514b4 100644
49910--- a/drivers/pci/hotplug/pciehp_core.c
49911+++ b/drivers/pci/hotplug/pciehp_core.c
49912@@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
49913 struct slot *slot = ctrl->slot;
49914 struct hotplug_slot *hotplug = NULL;
49915 struct hotplug_slot_info *info = NULL;
49916- struct hotplug_slot_ops *ops = NULL;
49917+ hotplug_slot_ops_no_const *ops = NULL;
49918 char name[SLOT_NAME_SIZE];
49919 int retval = -ENOMEM;
49920
49921diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
49922index 084587d..4a8f9df 100644
49923--- a/drivers/pci/msi.c
49924+++ b/drivers/pci/msi.c
49925@@ -488,8 +488,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
49926 {
49927 struct attribute **msi_attrs;
49928 struct attribute *msi_attr;
49929- struct device_attribute *msi_dev_attr;
49930- struct attribute_group *msi_irq_group;
49931+ device_attribute_no_const *msi_dev_attr;
49932+ attribute_group_no_const *msi_irq_group;
49933 const struct attribute_group **msi_irq_groups;
49934 struct msi_desc *entry;
49935 int ret = -ENOMEM;
49936@@ -549,7 +549,7 @@ error_attrs:
49937 count = 0;
49938 msi_attr = msi_attrs[count];
49939 while (msi_attr) {
49940- msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
49941+ msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
49942 kfree(msi_attr->name);
49943 kfree(msi_dev_attr);
49944 ++count;
49945diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
49946index 2c6643f..3a6d8e0 100644
49947--- a/drivers/pci/pci-sysfs.c
49948+++ b/drivers/pci/pci-sysfs.c
49949@@ -1133,7 +1133,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
49950 {
49951 /* allocate attribute structure, piggyback attribute name */
49952 int name_len = write_combine ? 13 : 10;
49953- struct bin_attribute *res_attr;
49954+ bin_attribute_no_const *res_attr;
49955 int retval;
49956
49957 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
49958@@ -1310,7 +1310,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
49959 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
49960 {
49961 int retval;
49962- struct bin_attribute *attr;
49963+ bin_attribute_no_const *attr;
49964
49965 /* If the device has VPD, try to expose it in sysfs. */
49966 if (dev->vpd) {
49967@@ -1357,7 +1357,7 @@ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev)
49968 {
49969 int retval;
49970 int rom_size = 0;
49971- struct bin_attribute *attr;
49972+ bin_attribute_no_const *attr;
49973
49974 if (!sysfs_initialized)
49975 return -EACCES;
49976diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
49977index 4a3902d..7f1fc42 100644
49978--- a/drivers/pci/pci.h
49979+++ b/drivers/pci/pci.h
49980@@ -93,7 +93,7 @@ struct pci_vpd_ops {
49981 struct pci_vpd {
49982 unsigned int len;
49983 const struct pci_vpd_ops *ops;
49984- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
49985+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
49986 };
49987
49988 int pci_vpd_pci22_init(struct pci_dev *dev);
49989diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
49990index e1e7026..d28dd33 100644
49991--- a/drivers/pci/pcie/aspm.c
49992+++ b/drivers/pci/pcie/aspm.c
49993@@ -27,9 +27,9 @@
49994 #define MODULE_PARAM_PREFIX "pcie_aspm."
49995
49996 /* Note: those are not register definitions */
49997-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
49998-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
49999-#define ASPM_STATE_L1 (4) /* L1 state */
50000+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
50001+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
50002+#define ASPM_STATE_L1 (4U) /* L1 state */
50003 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
50004 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
50005
50006diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
50007index c8ca98c..b1bc005 100644
50008--- a/drivers/pci/probe.c
50009+++ b/drivers/pci/probe.c
50010@@ -177,7 +177,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
50011 struct pci_bus_region region, inverted_region;
50012 bool bar_too_big = false, bar_too_high = false, bar_invalid = false;
50013
50014- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
50015+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
50016
50017 /* No printks while decoding is disabled! */
50018 if (!dev->mmio_always_on) {
50019diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
50020index 3f155e7..0f4b1f0 100644
50021--- a/drivers/pci/proc.c
50022+++ b/drivers/pci/proc.c
50023@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
50024 static int __init pci_proc_init(void)
50025 {
50026 struct pci_dev *dev = NULL;
50027+
50028+#ifdef CONFIG_GRKERNSEC_PROC_ADD
50029+#ifdef CONFIG_GRKERNSEC_PROC_USER
50030+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
50031+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50032+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
50033+#endif
50034+#else
50035 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
50036+#endif
50037 proc_create("devices", 0, proc_bus_pci_dir,
50038 &proc_bus_pci_dev_operations);
50039 proc_initialized = 1;
50040diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
50041index d866db8..c827d1f 100644
50042--- a/drivers/platform/chrome/chromeos_laptop.c
50043+++ b/drivers/platform/chrome/chromeos_laptop.c
50044@@ -479,7 +479,7 @@ static struct chromeos_laptop cr48 = {
50045 .callback = chromeos_laptop_dmi_matched, \
50046 .driver_data = (void *)&board_
50047
50048-static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
50049+static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
50050 {
50051 .ident = "Samsung Series 5 550",
50052 .matches = {
50053diff --git a/drivers/platform/x86/alienware-wmi.c b/drivers/platform/x86/alienware-wmi.c
50054index c5af23b..3d62d5e 100644
50055--- a/drivers/platform/x86/alienware-wmi.c
50056+++ b/drivers/platform/x86/alienware-wmi.c
50057@@ -150,7 +150,7 @@ struct wmax_led_args {
50058 } __packed;
50059
50060 static struct platform_device *platform_device;
50061-static struct device_attribute *zone_dev_attrs;
50062+static device_attribute_no_const *zone_dev_attrs;
50063 static struct attribute **zone_attrs;
50064 static struct platform_zone *zone_data;
50065
50066@@ -161,7 +161,7 @@ static struct platform_driver platform_driver = {
50067 }
50068 };
50069
50070-static struct attribute_group zone_attribute_group = {
50071+static attribute_group_no_const zone_attribute_group = {
50072 .name = "rgb_zones",
50073 };
50074
50075diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
50076index 21fc932..ee9394a 100644
50077--- a/drivers/platform/x86/asus-wmi.c
50078+++ b/drivers/platform/x86/asus-wmi.c
50079@@ -1590,6 +1590,10 @@ static int show_dsts(struct seq_file *m, void *data)
50080 int err;
50081 u32 retval = -1;
50082
50083+#ifdef CONFIG_GRKERNSEC_KMEM
50084+ return -EPERM;
50085+#endif
50086+
50087 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
50088
50089 if (err < 0)
50090@@ -1606,6 +1610,10 @@ static int show_devs(struct seq_file *m, void *data)
50091 int err;
50092 u32 retval = -1;
50093
50094+#ifdef CONFIG_GRKERNSEC_KMEM
50095+ return -EPERM;
50096+#endif
50097+
50098 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
50099 &retval);
50100
50101@@ -1630,6 +1638,10 @@ static int show_call(struct seq_file *m, void *data)
50102 union acpi_object *obj;
50103 acpi_status status;
50104
50105+#ifdef CONFIG_GRKERNSEC_KMEM
50106+ return -EPERM;
50107+#endif
50108+
50109 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
50110 1, asus->debug.method_id,
50111 &input, &output);
50112diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
50113index 62f8030..c7f2a45 100644
50114--- a/drivers/platform/x86/msi-laptop.c
50115+++ b/drivers/platform/x86/msi-laptop.c
50116@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
50117
50118 if (!quirks->ec_read_only) {
50119 /* allow userland write sysfs file */
50120- dev_attr_bluetooth.store = store_bluetooth;
50121- dev_attr_wlan.store = store_wlan;
50122- dev_attr_threeg.store = store_threeg;
50123- dev_attr_bluetooth.attr.mode |= S_IWUSR;
50124- dev_attr_wlan.attr.mode |= S_IWUSR;
50125- dev_attr_threeg.attr.mode |= S_IWUSR;
50126+ pax_open_kernel();
50127+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
50128+ *(void **)&dev_attr_wlan.store = store_wlan;
50129+ *(void **)&dev_attr_threeg.store = store_threeg;
50130+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
50131+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
50132+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
50133+ pax_close_kernel();
50134 }
50135
50136 /* disable hardware control by fn key */
50137diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
50138index 70222f2..8c8ce66 100644
50139--- a/drivers/platform/x86/msi-wmi.c
50140+++ b/drivers/platform/x86/msi-wmi.c
50141@@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
50142 static void msi_wmi_notify(u32 value, void *context)
50143 {
50144 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
50145- static struct key_entry *key;
50146+ struct key_entry *key;
50147 union acpi_object *obj;
50148 acpi_status status;
50149
50150diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
50151index 26ad9ff..7c52909 100644
50152--- a/drivers/platform/x86/sony-laptop.c
50153+++ b/drivers/platform/x86/sony-laptop.c
50154@@ -2527,7 +2527,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
50155 }
50156
50157 /* High speed charging function */
50158-static struct device_attribute *hsc_handle;
50159+static device_attribute_no_const *hsc_handle;
50160
50161 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
50162 struct device_attribute *attr,
50163@@ -2601,7 +2601,7 @@ static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd)
50164 }
50165
50166 /* low battery function */
50167-static struct device_attribute *lowbatt_handle;
50168+static device_attribute_no_const *lowbatt_handle;
50169
50170 static ssize_t sony_nc_lowbatt_store(struct device *dev,
50171 struct device_attribute *attr,
50172@@ -2667,7 +2667,7 @@ static void sony_nc_lowbatt_cleanup(struct platform_device *pd)
50173 }
50174
50175 /* fan speed function */
50176-static struct device_attribute *fan_handle, *hsf_handle;
50177+static device_attribute_no_const *fan_handle, *hsf_handle;
50178
50179 static ssize_t sony_nc_hsfan_store(struct device *dev,
50180 struct device_attribute *attr,
50181@@ -2774,7 +2774,7 @@ static void sony_nc_fanspeed_cleanup(struct platform_device *pd)
50182 }
50183
50184 /* USB charge function */
50185-static struct device_attribute *uc_handle;
50186+static device_attribute_no_const *uc_handle;
50187
50188 static ssize_t sony_nc_usb_charge_store(struct device *dev,
50189 struct device_attribute *attr,
50190@@ -2848,7 +2848,7 @@ static void sony_nc_usb_charge_cleanup(struct platform_device *pd)
50191 }
50192
50193 /* Panel ID function */
50194-static struct device_attribute *panel_handle;
50195+static device_attribute_no_const *panel_handle;
50196
50197 static ssize_t sony_nc_panelid_show(struct device *dev,
50198 struct device_attribute *attr, char *buffer)
50199@@ -2895,7 +2895,7 @@ static void sony_nc_panelid_cleanup(struct platform_device *pd)
50200 }
50201
50202 /* smart connect function */
50203-static struct device_attribute *sc_handle;
50204+static device_attribute_no_const *sc_handle;
50205
50206 static ssize_t sony_nc_smart_conn_store(struct device *dev,
50207 struct device_attribute *attr,
50208diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
50209index cf0f893..5955997 100644
50210--- a/drivers/platform/x86/thinkpad_acpi.c
50211+++ b/drivers/platform/x86/thinkpad_acpi.c
50212@@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
50213 return 0;
50214 }
50215
50216-void static hotkey_mask_warn_incomplete_mask(void)
50217+static void hotkey_mask_warn_incomplete_mask(void)
50218 {
50219 /* log only what the user can fix... */
50220 const u32 wantedmask = hotkey_driver_mask &
50221@@ -2438,10 +2438,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
50222 && !tp_features.bright_unkfw)
50223 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
50224 }
50225+}
50226
50227 #undef TPACPI_COMPARE_KEY
50228 #undef TPACPI_MAY_SEND_KEY
50229-}
50230
50231 /*
50232 * Polling driver
50233diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
50234index 438d4c7..ca8a2fb 100644
50235--- a/drivers/pnp/pnpbios/bioscalls.c
50236+++ b/drivers/pnp/pnpbios/bioscalls.c
50237@@ -59,7 +59,7 @@ do { \
50238 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
50239 } while(0)
50240
50241-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
50242+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
50243 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
50244
50245 /*
50246@@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
50247
50248 cpu = get_cpu();
50249 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
50250+
50251+ pax_open_kernel();
50252 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
50253+ pax_close_kernel();
50254
50255 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
50256 spin_lock_irqsave(&pnp_bios_lock, flags);
50257@@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
50258 :"memory");
50259 spin_unlock_irqrestore(&pnp_bios_lock, flags);
50260
50261+ pax_open_kernel();
50262 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
50263+ pax_close_kernel();
50264+
50265 put_cpu();
50266
50267 /* If we get here and this is set then the PnP BIOS faulted on us. */
50268@@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
50269 return status;
50270 }
50271
50272-void pnpbios_calls_init(union pnp_bios_install_struct *header)
50273+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
50274 {
50275 int i;
50276
50277@@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
50278 pnp_bios_callpoint.offset = header->fields.pm16offset;
50279 pnp_bios_callpoint.segment = PNP_CS16;
50280
50281+ pax_open_kernel();
50282+
50283 for_each_possible_cpu(i) {
50284 struct desc_struct *gdt = get_cpu_gdt_table(i);
50285 if (!gdt)
50286@@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
50287 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
50288 (unsigned long)__va(header->fields.pm16dseg));
50289 }
50290+
50291+ pax_close_kernel();
50292 }
50293diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
50294index 0c52e2a..3421ab7 100644
50295--- a/drivers/power/pda_power.c
50296+++ b/drivers/power/pda_power.c
50297@@ -37,7 +37,11 @@ static int polling;
50298
50299 #if IS_ENABLED(CONFIG_USB_PHY)
50300 static struct usb_phy *transceiver;
50301-static struct notifier_block otg_nb;
50302+static int otg_handle_notification(struct notifier_block *nb,
50303+ unsigned long event, void *unused);
50304+static struct notifier_block otg_nb = {
50305+ .notifier_call = otg_handle_notification
50306+};
50307 #endif
50308
50309 static struct regulator *ac_draw;
50310@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
50311
50312 #if IS_ENABLED(CONFIG_USB_PHY)
50313 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
50314- otg_nb.notifier_call = otg_handle_notification;
50315 ret = usb_register_notifier(transceiver, &otg_nb);
50316 if (ret) {
50317 dev_err(dev, "failure to register otg notifier\n");
50318diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
50319index cc439fd..8fa30df 100644
50320--- a/drivers/power/power_supply.h
50321+++ b/drivers/power/power_supply.h
50322@@ -16,12 +16,12 @@ struct power_supply;
50323
50324 #ifdef CONFIG_SYSFS
50325
50326-extern void power_supply_init_attrs(struct device_type *dev_type);
50327+extern void power_supply_init_attrs(void);
50328 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
50329
50330 #else
50331
50332-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
50333+static inline void power_supply_init_attrs(void) {}
50334 #define power_supply_uevent NULL
50335
50336 #endif /* CONFIG_SYSFS */
50337diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
50338index 694e8cd..9f03483 100644
50339--- a/drivers/power/power_supply_core.c
50340+++ b/drivers/power/power_supply_core.c
50341@@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
50342 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
50343 EXPORT_SYMBOL_GPL(power_supply_notifier);
50344
50345-static struct device_type power_supply_dev_type;
50346+extern const struct attribute_group *power_supply_attr_groups[];
50347+static struct device_type power_supply_dev_type = {
50348+ .groups = power_supply_attr_groups,
50349+};
50350
50351 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
50352 struct power_supply *supply)
50353@@ -637,7 +640,7 @@ static int __init power_supply_class_init(void)
50354 return PTR_ERR(power_supply_class);
50355
50356 power_supply_class->dev_uevent = power_supply_uevent;
50357- power_supply_init_attrs(&power_supply_dev_type);
50358+ power_supply_init_attrs();
50359
50360 return 0;
50361 }
50362diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
50363index 62653f5..d0bb485 100644
50364--- a/drivers/power/power_supply_sysfs.c
50365+++ b/drivers/power/power_supply_sysfs.c
50366@@ -238,17 +238,15 @@ static struct attribute_group power_supply_attr_group = {
50367 .is_visible = power_supply_attr_is_visible,
50368 };
50369
50370-static const struct attribute_group *power_supply_attr_groups[] = {
50371+const struct attribute_group *power_supply_attr_groups[] = {
50372 &power_supply_attr_group,
50373 NULL,
50374 };
50375
50376-void power_supply_init_attrs(struct device_type *dev_type)
50377+void power_supply_init_attrs(void)
50378 {
50379 int i;
50380
50381- dev_type->groups = power_supply_attr_groups;
50382-
50383 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
50384 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
50385 }
50386diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
50387index 84419af..268ede8 100644
50388--- a/drivers/powercap/powercap_sys.c
50389+++ b/drivers/powercap/powercap_sys.c
50390@@ -154,8 +154,77 @@ struct powercap_constraint_attr {
50391 struct device_attribute name_attr;
50392 };
50393
50394+static ssize_t show_constraint_name(struct device *dev,
50395+ struct device_attribute *dev_attr,
50396+ char *buf);
50397+
50398 static struct powercap_constraint_attr
50399- constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
50400+ constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
50401+ [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
50402+ .power_limit_attr = {
50403+ .attr = {
50404+ .name = NULL,
50405+ .mode = S_IWUSR | S_IRUGO
50406+ },
50407+ .show = show_constraint_power_limit_uw,
50408+ .store = store_constraint_power_limit_uw
50409+ },
50410+
50411+ .time_window_attr = {
50412+ .attr = {
50413+ .name = NULL,
50414+ .mode = S_IWUSR | S_IRUGO
50415+ },
50416+ .show = show_constraint_time_window_us,
50417+ .store = store_constraint_time_window_us
50418+ },
50419+
50420+ .max_power_attr = {
50421+ .attr = {
50422+ .name = NULL,
50423+ .mode = S_IRUGO
50424+ },
50425+ .show = show_constraint_max_power_uw,
50426+ .store = NULL
50427+ },
50428+
50429+ .min_power_attr = {
50430+ .attr = {
50431+ .name = NULL,
50432+ .mode = S_IRUGO
50433+ },
50434+ .show = show_constraint_min_power_uw,
50435+ .store = NULL
50436+ },
50437+
50438+ .max_time_window_attr = {
50439+ .attr = {
50440+ .name = NULL,
50441+ .mode = S_IRUGO
50442+ },
50443+ .show = show_constraint_max_time_window_us,
50444+ .store = NULL
50445+ },
50446+
50447+ .min_time_window_attr = {
50448+ .attr = {
50449+ .name = NULL,
50450+ .mode = S_IRUGO
50451+ },
50452+ .show = show_constraint_min_time_window_us,
50453+ .store = NULL
50454+ },
50455+
50456+ .name_attr = {
50457+ .attr = {
50458+ .name = NULL,
50459+ .mode = S_IRUGO
50460+ },
50461+ .show = show_constraint_name,
50462+ .store = NULL
50463+ }
50464+ }
50465+};
50466
50467 /* A list of powercap control_types */
50468 static LIST_HEAD(powercap_cntrl_list);
50469@@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
50470 }
50471
50472 static int create_constraint_attribute(int id, const char *name,
50473- int mode,
50474- struct device_attribute *dev_attr,
50475- ssize_t (*show)(struct device *,
50476- struct device_attribute *, char *),
50477- ssize_t (*store)(struct device *,
50478- struct device_attribute *,
50479- const char *, size_t)
50480- )
50481+ struct device_attribute *dev_attr)
50482 {
50483+ name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
50484
50485- dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
50486- id, name);
50487- if (!dev_attr->attr.name)
50488+ if (!name)
50489 return -ENOMEM;
50490- dev_attr->attr.mode = mode;
50491- dev_attr->show = show;
50492- dev_attr->store = store;
50493+
50494+ pax_open_kernel();
50495+ *(const char **)&dev_attr->attr.name = name;
50496+ pax_close_kernel();
50497
50498 return 0;
50499 }
50500@@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
50501
50502 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
50503 ret = create_constraint_attribute(i, "power_limit_uw",
50504- S_IWUSR | S_IRUGO,
50505- &constraint_attrs[i].power_limit_attr,
50506- show_constraint_power_limit_uw,
50507- store_constraint_power_limit_uw);
50508+ &constraint_attrs[i].power_limit_attr);
50509 if (ret)
50510 goto err_alloc;
50511 ret = create_constraint_attribute(i, "time_window_us",
50512- S_IWUSR | S_IRUGO,
50513- &constraint_attrs[i].time_window_attr,
50514- show_constraint_time_window_us,
50515- store_constraint_time_window_us);
50516+ &constraint_attrs[i].time_window_attr);
50517 if (ret)
50518 goto err_alloc;
50519- ret = create_constraint_attribute(i, "name", S_IRUGO,
50520- &constraint_attrs[i].name_attr,
50521- show_constraint_name,
50522- NULL);
50523+ ret = create_constraint_attribute(i, "name",
50524+ &constraint_attrs[i].name_attr);
50525 if (ret)
50526 goto err_alloc;
50527- ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
50528- &constraint_attrs[i].max_power_attr,
50529- show_constraint_max_power_uw,
50530- NULL);
50531+ ret = create_constraint_attribute(i, "max_power_uw",
50532+ &constraint_attrs[i].max_power_attr);
50533 if (ret)
50534 goto err_alloc;
50535- ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
50536- &constraint_attrs[i].min_power_attr,
50537- show_constraint_min_power_uw,
50538- NULL);
50539+ ret = create_constraint_attribute(i, "min_power_uw",
50540+ &constraint_attrs[i].min_power_attr);
50541 if (ret)
50542 goto err_alloc;
50543 ret = create_constraint_attribute(i, "max_time_window_us",
50544- S_IRUGO,
50545- &constraint_attrs[i].max_time_window_attr,
50546- show_constraint_max_time_window_us,
50547- NULL);
50548+ &constraint_attrs[i].max_time_window_attr);
50549 if (ret)
50550 goto err_alloc;
50551 ret = create_constraint_attribute(i, "min_time_window_us",
50552- S_IRUGO,
50553- &constraint_attrs[i].min_time_window_attr,
50554- show_constraint_min_time_window_us,
50555- NULL);
50556+ &constraint_attrs[i].min_time_window_attr);
50557 if (ret)
50558 goto err_alloc;
50559
50560@@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
50561 power_zone->zone_dev_attrs[count++] =
50562 &dev_attr_max_energy_range_uj.attr;
50563 if (power_zone->ops->get_energy_uj) {
50564+ pax_open_kernel();
50565 if (power_zone->ops->reset_energy_uj)
50566- dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
50567+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
50568 else
50569- dev_attr_energy_uj.attr.mode = S_IRUGO;
50570+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
50571+ pax_close_kernel();
50572 power_zone->zone_dev_attrs[count++] =
50573 &dev_attr_energy_uj.attr;
50574 }
50575diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
50576index 9c5d414..c7900ce 100644
50577--- a/drivers/ptp/ptp_private.h
50578+++ b/drivers/ptp/ptp_private.h
50579@@ -51,7 +51,7 @@ struct ptp_clock {
50580 struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
50581 wait_queue_head_t tsev_wq;
50582 int defunct; /* tells readers to go away when clock is being removed */
50583- struct device_attribute *pin_dev_attr;
50584+ device_attribute_no_const *pin_dev_attr;
50585 struct attribute **pin_attr;
50586 struct attribute_group pin_attr_group;
50587 };
50588diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
50589index 302e626..12579af 100644
50590--- a/drivers/ptp/ptp_sysfs.c
50591+++ b/drivers/ptp/ptp_sysfs.c
50592@@ -280,7 +280,7 @@ static int ptp_populate_pins(struct ptp_clock *ptp)
50593 goto no_pin_attr;
50594
50595 for (i = 0; i < n_pins; i++) {
50596- struct device_attribute *da = &ptp->pin_dev_attr[i];
50597+ device_attribute_no_const *da = &ptp->pin_dev_attr[i];
50598 sysfs_attr_init(&da->attr);
50599 da->attr.name = info->pin_config[i].name;
50600 da->attr.mode = 0644;
50601diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
50602index cd87c0c..715ecbe 100644
50603--- a/drivers/regulator/core.c
50604+++ b/drivers/regulator/core.c
50605@@ -3567,7 +3567,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
50606 {
50607 const struct regulation_constraints *constraints = NULL;
50608 const struct regulator_init_data *init_data;
50609- static atomic_t regulator_no = ATOMIC_INIT(0);
50610+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
50611 struct regulator_dev *rdev;
50612 struct device *dev;
50613 int ret, i;
50614@@ -3641,7 +3641,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
50615 rdev->dev.class = &regulator_class;
50616 rdev->dev.parent = dev;
50617 dev_set_name(&rdev->dev, "regulator.%d",
50618- atomic_inc_return(&regulator_no) - 1);
50619+ atomic_inc_return_unchecked(&regulator_no) - 1);
50620 ret = device_register(&rdev->dev);
50621 if (ret != 0) {
50622 put_device(&rdev->dev);
50623diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
50624index 7eee2ca..4024513 100644
50625--- a/drivers/regulator/max8660.c
50626+++ b/drivers/regulator/max8660.c
50627@@ -424,8 +424,10 @@ static int max8660_probe(struct i2c_client *client,
50628 max8660->shadow_regs[MAX8660_OVER1] = 5;
50629 } else {
50630 /* Otherwise devices can be toggled via software */
50631- max8660_dcdc_ops.enable = max8660_dcdc_enable;
50632- max8660_dcdc_ops.disable = max8660_dcdc_disable;
50633+ pax_open_kernel();
50634+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
50635+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
50636+ pax_close_kernel();
50637 }
50638
50639 /*
50640diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
50641index dbedf17..18ff6b7 100644
50642--- a/drivers/regulator/max8973-regulator.c
50643+++ b/drivers/regulator/max8973-regulator.c
50644@@ -403,9 +403,11 @@ static int max8973_probe(struct i2c_client *client,
50645 if (!pdata || !pdata->enable_ext_control) {
50646 max->desc.enable_reg = MAX8973_VOUT;
50647 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
50648- max->ops.enable = regulator_enable_regmap;
50649- max->ops.disable = regulator_disable_regmap;
50650- max->ops.is_enabled = regulator_is_enabled_regmap;
50651+ pax_open_kernel();
50652+ *(void **)&max->ops.enable = regulator_enable_regmap;
50653+ *(void **)&max->ops.disable = regulator_disable_regmap;
50654+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
50655+ pax_close_kernel();
50656 }
50657
50658 if (pdata) {
50659diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
50660index 793b662..85f74cd 100644
50661--- a/drivers/regulator/mc13892-regulator.c
50662+++ b/drivers/regulator/mc13892-regulator.c
50663@@ -584,10 +584,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
50664 mc13xxx_unlock(mc13892);
50665
50666 /* update mc13892_vcam ops */
50667+ pax_open_kernel();
50668 memcpy(&mc13892_vcam_ops, mc13892_regulators[MC13892_VCAM].desc.ops,
50669 sizeof(struct regulator_ops));
50670- mc13892_vcam_ops.set_mode = mc13892_vcam_set_mode,
50671- mc13892_vcam_ops.get_mode = mc13892_vcam_get_mode,
50672+ *(void **)&mc13892_vcam_ops.set_mode = mc13892_vcam_set_mode,
50673+ *(void **)&mc13892_vcam_ops.get_mode = mc13892_vcam_get_mode,
50674+ pax_close_kernel();
50675 mc13892_regulators[MC13892_VCAM].desc.ops = &mc13892_vcam_ops;
50676
50677 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
50678diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
50679index 5b2e761..c8c8a4a 100644
50680--- a/drivers/rtc/rtc-cmos.c
50681+++ b/drivers/rtc/rtc-cmos.c
50682@@ -789,7 +789,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
50683 hpet_rtc_timer_init();
50684
50685 /* export at least the first block of NVRAM */
50686- nvram.size = address_space - NVRAM_OFFSET;
50687+ pax_open_kernel();
50688+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
50689+ pax_close_kernel();
50690 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
50691 if (retval < 0) {
50692 dev_dbg(dev, "can't create nvram file? %d\n", retval);
50693diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
50694index d049393..bb20be0 100644
50695--- a/drivers/rtc/rtc-dev.c
50696+++ b/drivers/rtc/rtc-dev.c
50697@@ -16,6 +16,7 @@
50698 #include <linux/module.h>
50699 #include <linux/rtc.h>
50700 #include <linux/sched.h>
50701+#include <linux/grsecurity.h>
50702 #include "rtc-core.h"
50703
50704 static dev_t rtc_devt;
50705@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
50706 if (copy_from_user(&tm, uarg, sizeof(tm)))
50707 return -EFAULT;
50708
50709+ gr_log_timechange();
50710+
50711 return rtc_set_time(rtc, &tm);
50712
50713 case RTC_PIE_ON:
50714diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
50715index bb43cf7..ee4d274 100644
50716--- a/drivers/rtc/rtc-ds1307.c
50717+++ b/drivers/rtc/rtc-ds1307.c
50718@@ -107,7 +107,7 @@ struct ds1307 {
50719 u8 offset; /* register's offset */
50720 u8 regs[11];
50721 u16 nvram_offset;
50722- struct bin_attribute *nvram;
50723+ bin_attribute_no_const *nvram;
50724 enum ds_type type;
50725 unsigned long flags;
50726 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
50727diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
50728index 11880c1..b823aa4 100644
50729--- a/drivers/rtc/rtc-m48t59.c
50730+++ b/drivers/rtc/rtc-m48t59.c
50731@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
50732 if (IS_ERR(m48t59->rtc))
50733 return PTR_ERR(m48t59->rtc);
50734
50735- m48t59_nvram_attr.size = pdata->offset;
50736+ pax_open_kernel();
50737+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
50738+ pax_close_kernel();
50739
50740 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
50741 if (ret)
50742diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
50743index e693af6..2e525b6 100644
50744--- a/drivers/scsi/bfa/bfa_fcpim.h
50745+++ b/drivers/scsi/bfa/bfa_fcpim.h
50746@@ -36,7 +36,7 @@ struct bfa_iotag_s {
50747
50748 struct bfa_itn_s {
50749 bfa_isr_func_t isr;
50750-};
50751+} __no_const;
50752
50753 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
50754 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
50755diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
50756index 0f19455..ef7adb5 100644
50757--- a/drivers/scsi/bfa/bfa_fcs.c
50758+++ b/drivers/scsi/bfa/bfa_fcs.c
50759@@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
50760 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
50761
50762 static struct bfa_fcs_mod_s fcs_modules[] = {
50763- { bfa_fcs_port_attach, NULL, NULL },
50764- { bfa_fcs_uf_attach, NULL, NULL },
50765- { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
50766- bfa_fcs_fabric_modexit },
50767+ {
50768+ .attach = bfa_fcs_port_attach,
50769+ .modinit = NULL,
50770+ .modexit = NULL
50771+ },
50772+ {
50773+ .attach = bfa_fcs_uf_attach,
50774+ .modinit = NULL,
50775+ .modexit = NULL
50776+ },
50777+ {
50778+ .attach = bfa_fcs_fabric_attach,
50779+ .modinit = bfa_fcs_fabric_modinit,
50780+ .modexit = bfa_fcs_fabric_modexit
50781+ },
50782 };
50783
50784 /*
50785diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
50786index ff75ef8..2dfe00a 100644
50787--- a/drivers/scsi/bfa/bfa_fcs_lport.c
50788+++ b/drivers/scsi/bfa/bfa_fcs_lport.c
50789@@ -89,15 +89,26 @@ static struct {
50790 void (*offline) (struct bfa_fcs_lport_s *port);
50791 } __port_action[] = {
50792 {
50793- bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
50794- bfa_fcs_lport_unknown_offline}, {
50795- bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
50796- bfa_fcs_lport_fab_offline}, {
50797- bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
50798- bfa_fcs_lport_n2n_offline}, {
50799- bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
50800- bfa_fcs_lport_loop_offline},
50801- };
50802+ .init = bfa_fcs_lport_unknown_init,
50803+ .online = bfa_fcs_lport_unknown_online,
50804+ .offline = bfa_fcs_lport_unknown_offline
50805+ },
50806+ {
50807+ .init = bfa_fcs_lport_fab_init,
50808+ .online = bfa_fcs_lport_fab_online,
50809+ .offline = bfa_fcs_lport_fab_offline
50810+ },
50811+ {
50812+ .init = bfa_fcs_lport_n2n_init,
50813+ .online = bfa_fcs_lport_n2n_online,
50814+ .offline = bfa_fcs_lport_n2n_offline
50815+ },
50816+ {
50817+ .init = bfa_fcs_lport_loop_init,
50818+ .online = bfa_fcs_lport_loop_online,
50819+ .offline = bfa_fcs_lport_loop_offline
50820+ },
50821+};
50822
50823 /*
50824 * fcs_port_sm FCS logical port state machine
50825diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
50826index a38aafa0..fe8f03b 100644
50827--- a/drivers/scsi/bfa/bfa_ioc.h
50828+++ b/drivers/scsi/bfa/bfa_ioc.h
50829@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
50830 bfa_ioc_disable_cbfn_t disable_cbfn;
50831 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
50832 bfa_ioc_reset_cbfn_t reset_cbfn;
50833-};
50834+} __no_const;
50835
50836 /*
50837 * IOC event notification mechanism.
50838@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
50839 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
50840 enum bfi_ioc_state fwstate);
50841 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
50842-};
50843+} __no_const;
50844
50845 /*
50846 * Queue element to wait for room in request queue. FIFO order is
50847diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
50848index a14c784..6de6790 100644
50849--- a/drivers/scsi/bfa/bfa_modules.h
50850+++ b/drivers/scsi/bfa/bfa_modules.h
50851@@ -78,12 +78,12 @@ enum {
50852 \
50853 extern struct bfa_module_s hal_mod_ ## __mod; \
50854 struct bfa_module_s hal_mod_ ## __mod = { \
50855- bfa_ ## __mod ## _meminfo, \
50856- bfa_ ## __mod ## _attach, \
50857- bfa_ ## __mod ## _detach, \
50858- bfa_ ## __mod ## _start, \
50859- bfa_ ## __mod ## _stop, \
50860- bfa_ ## __mod ## _iocdisable, \
50861+ .meminfo = bfa_ ## __mod ## _meminfo, \
50862+ .attach = bfa_ ## __mod ## _attach, \
50863+ .detach = bfa_ ## __mod ## _detach, \
50864+ .start = bfa_ ## __mod ## _start, \
50865+ .stop = bfa_ ## __mod ## _stop, \
50866+ .iocdisable = bfa_ ## __mod ## _iocdisable, \
50867 }
50868
50869 #define BFA_CACHELINE_SZ (256)
50870diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
50871index 045c4e1..13de803 100644
50872--- a/drivers/scsi/fcoe/fcoe_sysfs.c
50873+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
50874@@ -33,8 +33,8 @@
50875 */
50876 #include "libfcoe.h"
50877
50878-static atomic_t ctlr_num;
50879-static atomic_t fcf_num;
50880+static atomic_unchecked_t ctlr_num;
50881+static atomic_unchecked_t fcf_num;
50882
50883 /*
50884 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
50885@@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
50886 if (!ctlr)
50887 goto out;
50888
50889- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
50890+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
50891 ctlr->f = f;
50892 ctlr->mode = FIP_CONN_TYPE_FABRIC;
50893 INIT_LIST_HEAD(&ctlr->fcfs);
50894@@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
50895 fcf->dev.parent = &ctlr->dev;
50896 fcf->dev.bus = &fcoe_bus_type;
50897 fcf->dev.type = &fcoe_fcf_device_type;
50898- fcf->id = atomic_inc_return(&fcf_num) - 1;
50899+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
50900 fcf->state = FCOE_FCF_STATE_UNKNOWN;
50901
50902 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
50903@@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
50904 {
50905 int error;
50906
50907- atomic_set(&ctlr_num, 0);
50908- atomic_set(&fcf_num, 0);
50909+ atomic_set_unchecked(&ctlr_num, 0);
50910+ atomic_set_unchecked(&fcf_num, 0);
50911
50912 error = bus_register(&fcoe_bus_type);
50913 if (error)
50914diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
50915index 6de80e3..a11e0ac 100644
50916--- a/drivers/scsi/hosts.c
50917+++ b/drivers/scsi/hosts.c
50918@@ -42,7 +42,7 @@
50919 #include "scsi_logging.h"
50920
50921
50922-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
50923+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
50924
50925
50926 static void scsi_host_cls_release(struct device *dev)
50927@@ -392,7 +392,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
50928 * subtract one because we increment first then return, but we need to
50929 * know what the next host number was before increment
50930 */
50931- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
50932+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
50933 shost->dma_channel = 0xff;
50934
50935 /* These three are default values which can be overridden */
50936diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
50937index cef5d49..01e280e 100644
50938--- a/drivers/scsi/hpsa.c
50939+++ b/drivers/scsi/hpsa.c
50940@@ -701,10 +701,10 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
50941 unsigned long flags;
50942
50943 if (h->transMethod & CFGTBL_Trans_io_accel1)
50944- return h->access.command_completed(h, q);
50945+ return h->access->command_completed(h, q);
50946
50947 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
50948- return h->access.command_completed(h, q);
50949+ return h->access->command_completed(h, q);
50950
50951 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
50952 a = rq->head[rq->current_entry];
50953@@ -5454,7 +5454,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
50954 while (!list_empty(&h->reqQ)) {
50955 c = list_entry(h->reqQ.next, struct CommandList, list);
50956 /* can't do anything if fifo is full */
50957- if ((h->access.fifo_full(h))) {
50958+ if ((h->access->fifo_full(h))) {
50959 h->fifo_recently_full = 1;
50960 dev_warn(&h->pdev->dev, "fifo full\n");
50961 break;
50962@@ -5476,7 +5476,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
50963
50964 /* Tell the controller execute command */
50965 spin_unlock_irqrestore(&h->lock, *flags);
50966- h->access.submit_command(h, c);
50967+ h->access->submit_command(h, c);
50968 spin_lock_irqsave(&h->lock, *flags);
50969 }
50970 }
50971@@ -5492,17 +5492,17 @@ static void lock_and_start_io(struct ctlr_info *h)
50972
50973 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
50974 {
50975- return h->access.command_completed(h, q);
50976+ return h->access->command_completed(h, q);
50977 }
50978
50979 static inline bool interrupt_pending(struct ctlr_info *h)
50980 {
50981- return h->access.intr_pending(h);
50982+ return h->access->intr_pending(h);
50983 }
50984
50985 static inline long interrupt_not_for_us(struct ctlr_info *h)
50986 {
50987- return (h->access.intr_pending(h) == 0) ||
50988+ return (h->access->intr_pending(h) == 0) ||
50989 (h->interrupts_enabled == 0);
50990 }
50991
50992@@ -6445,7 +6445,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
50993 if (prod_index < 0)
50994 return -ENODEV;
50995 h->product_name = products[prod_index].product_name;
50996- h->access = *(products[prod_index].access);
50997+ h->access = products[prod_index].access;
50998
50999 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
51000 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
51001@@ -6790,7 +6790,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
51002 unsigned long flags;
51003 u32 lockup_detected;
51004
51005- h->access.set_intr_mask(h, HPSA_INTR_OFF);
51006+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
51007 spin_lock_irqsave(&h->lock, flags);
51008 lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
51009 if (!lockup_detected) {
51010@@ -7037,7 +7037,7 @@ reinit_after_soft_reset:
51011 }
51012
51013 /* make sure the board interrupts are off */
51014- h->access.set_intr_mask(h, HPSA_INTR_OFF);
51015+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
51016
51017 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
51018 goto clean2;
51019@@ -7072,7 +7072,7 @@ reinit_after_soft_reset:
51020 * fake ones to scoop up any residual completions.
51021 */
51022 spin_lock_irqsave(&h->lock, flags);
51023- h->access.set_intr_mask(h, HPSA_INTR_OFF);
51024+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
51025 spin_unlock_irqrestore(&h->lock, flags);
51026 free_irqs(h);
51027 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
51028@@ -7091,9 +7091,9 @@ reinit_after_soft_reset:
51029 dev_info(&h->pdev->dev, "Board READY.\n");
51030 dev_info(&h->pdev->dev,
51031 "Waiting for stale completions to drain.\n");
51032- h->access.set_intr_mask(h, HPSA_INTR_ON);
51033+ h->access->set_intr_mask(h, HPSA_INTR_ON);
51034 msleep(10000);
51035- h->access.set_intr_mask(h, HPSA_INTR_OFF);
51036+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
51037
51038 rc = controller_reset_failed(h->cfgtable);
51039 if (rc)
51040@@ -7119,7 +7119,7 @@ reinit_after_soft_reset:
51041 h->drv_req_rescan = 0;
51042
51043 /* Turn the interrupts on so we can service requests */
51044- h->access.set_intr_mask(h, HPSA_INTR_ON);
51045+ h->access->set_intr_mask(h, HPSA_INTR_ON);
51046
51047 hpsa_hba_inquiry(h);
51048 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
51049@@ -7184,7 +7184,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
51050 * To write all data in the battery backed cache to disks
51051 */
51052 hpsa_flush_cache(h);
51053- h->access.set_intr_mask(h, HPSA_INTR_OFF);
51054+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
51055 hpsa_free_irqs_and_disable_msix(h);
51056 }
51057
51058@@ -7302,7 +7302,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51059 CFGTBL_Trans_enable_directed_msix |
51060 (trans_support & (CFGTBL_Trans_io_accel1 |
51061 CFGTBL_Trans_io_accel2));
51062- struct access_method access = SA5_performant_access;
51063+ struct access_method *access = &SA5_performant_access;
51064
51065 /* This is a bit complicated. There are 8 registers on
51066 * the controller which we write to to tell it 8 different
51067@@ -7344,7 +7344,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51068 * perform the superfluous readl() after each command submission.
51069 */
51070 if (trans_support & (CFGTBL_Trans_io_accel1 | CFGTBL_Trans_io_accel2))
51071- access = SA5_performant_access_no_read;
51072+ access = &SA5_performant_access_no_read;
51073
51074 /* Controller spec: zero out this buffer. */
51075 for (i = 0; i < h->nreply_queues; i++)
51076@@ -7374,12 +7374,12 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51077 * enable outbound interrupt coalescing in accelerator mode;
51078 */
51079 if (trans_support & CFGTBL_Trans_io_accel1) {
51080- access = SA5_ioaccel_mode1_access;
51081+ access = &SA5_ioaccel_mode1_access;
51082 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
51083 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
51084 } else {
51085 if (trans_support & CFGTBL_Trans_io_accel2) {
51086- access = SA5_ioaccel_mode2_access;
51087+ access = &SA5_ioaccel_mode2_access;
51088 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
51089 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
51090 }
51091diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
51092index 24472ce..8782caf 100644
51093--- a/drivers/scsi/hpsa.h
51094+++ b/drivers/scsi/hpsa.h
51095@@ -127,7 +127,7 @@ struct ctlr_info {
51096 unsigned int msix_vector;
51097 unsigned int msi_vector;
51098 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
51099- struct access_method access;
51100+ struct access_method *access;
51101 char hba_mode_enabled;
51102
51103 /* queue and queue Info */
51104@@ -536,43 +536,43 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
51105 }
51106
51107 static struct access_method SA5_access = {
51108- SA5_submit_command,
51109- SA5_intr_mask,
51110- SA5_fifo_full,
51111- SA5_intr_pending,
51112- SA5_completed,
51113+ .submit_command = SA5_submit_command,
51114+ .set_intr_mask = SA5_intr_mask,
51115+ .fifo_full = SA5_fifo_full,
51116+ .intr_pending = SA5_intr_pending,
51117+ .command_completed = SA5_completed,
51118 };
51119
51120 static struct access_method SA5_ioaccel_mode1_access = {
51121- SA5_submit_command,
51122- SA5_performant_intr_mask,
51123- SA5_fifo_full,
51124- SA5_ioaccel_mode1_intr_pending,
51125- SA5_ioaccel_mode1_completed,
51126+ .submit_command = SA5_submit_command,
51127+ .set_intr_mask = SA5_performant_intr_mask,
51128+ .fifo_full = SA5_fifo_full,
51129+ .intr_pending = SA5_ioaccel_mode1_intr_pending,
51130+ .command_completed = SA5_ioaccel_mode1_completed,
51131 };
51132
51133 static struct access_method SA5_ioaccel_mode2_access = {
51134- SA5_submit_command_ioaccel2,
51135- SA5_performant_intr_mask,
51136- SA5_fifo_full,
51137- SA5_performant_intr_pending,
51138- SA5_performant_completed,
51139+ .submit_command = SA5_submit_command_ioaccel2,
51140+ .set_intr_mask = SA5_performant_intr_mask,
51141+ .fifo_full = SA5_fifo_full,
51142+ .intr_pending = SA5_performant_intr_pending,
51143+ .command_completed = SA5_performant_completed,
51144 };
51145
51146 static struct access_method SA5_performant_access = {
51147- SA5_submit_command,
51148- SA5_performant_intr_mask,
51149- SA5_fifo_full,
51150- SA5_performant_intr_pending,
51151- SA5_performant_completed,
51152+ .submit_command = SA5_submit_command,
51153+ .set_intr_mask = SA5_performant_intr_mask,
51154+ .fifo_full = SA5_fifo_full,
51155+ .intr_pending = SA5_performant_intr_pending,
51156+ .command_completed = SA5_performant_completed,
51157 };
51158
51159 static struct access_method SA5_performant_access_no_read = {
51160- SA5_submit_command_no_read,
51161- SA5_performant_intr_mask,
51162- SA5_fifo_full,
51163- SA5_performant_intr_pending,
51164- SA5_performant_completed,
51165+ .submit_command = SA5_submit_command_no_read,
51166+ .set_intr_mask = SA5_performant_intr_mask,
51167+ .fifo_full = SA5_fifo_full,
51168+ .intr_pending = SA5_performant_intr_pending,
51169+ .command_completed = SA5_performant_completed,
51170 };
51171
51172 struct board_type {
51173diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
51174index 1b3a094..068e683 100644
51175--- a/drivers/scsi/libfc/fc_exch.c
51176+++ b/drivers/scsi/libfc/fc_exch.c
51177@@ -101,12 +101,12 @@ struct fc_exch_mgr {
51178 u16 pool_max_index;
51179
51180 struct {
51181- atomic_t no_free_exch;
51182- atomic_t no_free_exch_xid;
51183- atomic_t xid_not_found;
51184- atomic_t xid_busy;
51185- atomic_t seq_not_found;
51186- atomic_t non_bls_resp;
51187+ atomic_unchecked_t no_free_exch;
51188+ atomic_unchecked_t no_free_exch_xid;
51189+ atomic_unchecked_t xid_not_found;
51190+ atomic_unchecked_t xid_busy;
51191+ atomic_unchecked_t seq_not_found;
51192+ atomic_unchecked_t non_bls_resp;
51193 } stats;
51194 };
51195
51196@@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
51197 /* allocate memory for exchange */
51198 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
51199 if (!ep) {
51200- atomic_inc(&mp->stats.no_free_exch);
51201+ atomic_inc_unchecked(&mp->stats.no_free_exch);
51202 goto out;
51203 }
51204 memset(ep, 0, sizeof(*ep));
51205@@ -874,7 +874,7 @@ out:
51206 return ep;
51207 err:
51208 spin_unlock_bh(&pool->lock);
51209- atomic_inc(&mp->stats.no_free_exch_xid);
51210+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
51211 mempool_free(ep, mp->ep_pool);
51212 return NULL;
51213 }
51214@@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51215 xid = ntohs(fh->fh_ox_id); /* we originated exch */
51216 ep = fc_exch_find(mp, xid);
51217 if (!ep) {
51218- atomic_inc(&mp->stats.xid_not_found);
51219+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51220 reject = FC_RJT_OX_ID;
51221 goto out;
51222 }
51223@@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51224 ep = fc_exch_find(mp, xid);
51225 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
51226 if (ep) {
51227- atomic_inc(&mp->stats.xid_busy);
51228+ atomic_inc_unchecked(&mp->stats.xid_busy);
51229 reject = FC_RJT_RX_ID;
51230 goto rel;
51231 }
51232@@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51233 }
51234 xid = ep->xid; /* get our XID */
51235 } else if (!ep) {
51236- atomic_inc(&mp->stats.xid_not_found);
51237+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51238 reject = FC_RJT_RX_ID; /* XID not found */
51239 goto out;
51240 }
51241@@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51242 } else {
51243 sp = &ep->seq;
51244 if (sp->id != fh->fh_seq_id) {
51245- atomic_inc(&mp->stats.seq_not_found);
51246+ atomic_inc_unchecked(&mp->stats.seq_not_found);
51247 if (f_ctl & FC_FC_END_SEQ) {
51248 /*
51249 * Update sequence_id based on incoming last
51250@@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51251
51252 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
51253 if (!ep) {
51254- atomic_inc(&mp->stats.xid_not_found);
51255+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51256 goto out;
51257 }
51258 if (ep->esb_stat & ESB_ST_COMPLETE) {
51259- atomic_inc(&mp->stats.xid_not_found);
51260+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51261 goto rel;
51262 }
51263 if (ep->rxid == FC_XID_UNKNOWN)
51264 ep->rxid = ntohs(fh->fh_rx_id);
51265 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
51266- atomic_inc(&mp->stats.xid_not_found);
51267+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51268 goto rel;
51269 }
51270 if (ep->did != ntoh24(fh->fh_s_id) &&
51271 ep->did != FC_FID_FLOGI) {
51272- atomic_inc(&mp->stats.xid_not_found);
51273+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51274 goto rel;
51275 }
51276 sof = fr_sof(fp);
51277@@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51278 sp->ssb_stat |= SSB_ST_RESP;
51279 sp->id = fh->fh_seq_id;
51280 } else if (sp->id != fh->fh_seq_id) {
51281- atomic_inc(&mp->stats.seq_not_found);
51282+ atomic_inc_unchecked(&mp->stats.seq_not_found);
51283 goto rel;
51284 }
51285
51286@@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51287 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
51288
51289 if (!sp)
51290- atomic_inc(&mp->stats.xid_not_found);
51291+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51292 else
51293- atomic_inc(&mp->stats.non_bls_resp);
51294+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
51295
51296 fc_frame_free(fp);
51297 }
51298@@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
51299
51300 list_for_each_entry(ema, &lport->ema_list, ema_list) {
51301 mp = ema->mp;
51302- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
51303+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
51304 st->fc_no_free_exch_xid +=
51305- atomic_read(&mp->stats.no_free_exch_xid);
51306- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
51307- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
51308- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
51309- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
51310+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
51311+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
51312+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
51313+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
51314+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
51315 }
51316 }
51317 EXPORT_SYMBOL(fc_exch_update_stats);
51318diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
51319index 766098a..1c6c971 100644
51320--- a/drivers/scsi/libsas/sas_ata.c
51321+++ b/drivers/scsi/libsas/sas_ata.c
51322@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
51323 .postreset = ata_std_postreset,
51324 .error_handler = ata_std_error_handler,
51325 .post_internal_cmd = sas_ata_post_internal,
51326- .qc_defer = ata_std_qc_defer,
51327+ .qc_defer = ata_std_qc_defer,
51328 .qc_prep = ata_noop_qc_prep,
51329 .qc_issue = sas_ata_qc_issue,
51330 .qc_fill_rtf = sas_ata_qc_fill_rtf,
51331diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
51332index 434e903..5a4a79b 100644
51333--- a/drivers/scsi/lpfc/lpfc.h
51334+++ b/drivers/scsi/lpfc/lpfc.h
51335@@ -430,7 +430,7 @@ struct lpfc_vport {
51336 struct dentry *debug_nodelist;
51337 struct dentry *vport_debugfs_root;
51338 struct lpfc_debugfs_trc *disc_trc;
51339- atomic_t disc_trc_cnt;
51340+ atomic_unchecked_t disc_trc_cnt;
51341 #endif
51342 uint8_t stat_data_enabled;
51343 uint8_t stat_data_blocked;
51344@@ -880,8 +880,8 @@ struct lpfc_hba {
51345 struct timer_list fabric_block_timer;
51346 unsigned long bit_flags;
51347 #define FABRIC_COMANDS_BLOCKED 0
51348- atomic_t num_rsrc_err;
51349- atomic_t num_cmd_success;
51350+ atomic_unchecked_t num_rsrc_err;
51351+ atomic_unchecked_t num_cmd_success;
51352 unsigned long last_rsrc_error_time;
51353 unsigned long last_ramp_down_time;
51354 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
51355@@ -916,7 +916,7 @@ struct lpfc_hba {
51356
51357 struct dentry *debug_slow_ring_trc;
51358 struct lpfc_debugfs_trc *slow_ring_trc;
51359- atomic_t slow_ring_trc_cnt;
51360+ atomic_unchecked_t slow_ring_trc_cnt;
51361 /* iDiag debugfs sub-directory */
51362 struct dentry *idiag_root;
51363 struct dentry *idiag_pci_cfg;
51364diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
51365index 786a2af..562c6a2 100644
51366--- a/drivers/scsi/lpfc/lpfc_debugfs.c
51367+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
51368@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
51369
51370 #include <linux/debugfs.h>
51371
51372-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
51373+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
51374 static unsigned long lpfc_debugfs_start_time = 0L;
51375
51376 /* iDiag */
51377@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
51378 lpfc_debugfs_enable = 0;
51379
51380 len = 0;
51381- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
51382+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
51383 (lpfc_debugfs_max_disc_trc - 1);
51384 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
51385 dtp = vport->disc_trc + i;
51386@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
51387 lpfc_debugfs_enable = 0;
51388
51389 len = 0;
51390- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
51391+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
51392 (lpfc_debugfs_max_slow_ring_trc - 1);
51393 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
51394 dtp = phba->slow_ring_trc + i;
51395@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
51396 !vport || !vport->disc_trc)
51397 return;
51398
51399- index = atomic_inc_return(&vport->disc_trc_cnt) &
51400+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
51401 (lpfc_debugfs_max_disc_trc - 1);
51402 dtp = vport->disc_trc + index;
51403 dtp->fmt = fmt;
51404 dtp->data1 = data1;
51405 dtp->data2 = data2;
51406 dtp->data3 = data3;
51407- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
51408+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
51409 dtp->jif = jiffies;
51410 #endif
51411 return;
51412@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
51413 !phba || !phba->slow_ring_trc)
51414 return;
51415
51416- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
51417+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
51418 (lpfc_debugfs_max_slow_ring_trc - 1);
51419 dtp = phba->slow_ring_trc + index;
51420 dtp->fmt = fmt;
51421 dtp->data1 = data1;
51422 dtp->data2 = data2;
51423 dtp->data3 = data3;
51424- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
51425+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
51426 dtp->jif = jiffies;
51427 #endif
51428 return;
51429@@ -4268,7 +4268,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
51430 "slow_ring buffer\n");
51431 goto debug_failed;
51432 }
51433- atomic_set(&phba->slow_ring_trc_cnt, 0);
51434+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
51435 memset(phba->slow_ring_trc, 0,
51436 (sizeof(struct lpfc_debugfs_trc) *
51437 lpfc_debugfs_max_slow_ring_trc));
51438@@ -4314,7 +4314,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
51439 "buffer\n");
51440 goto debug_failed;
51441 }
51442- atomic_set(&vport->disc_trc_cnt, 0);
51443+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
51444
51445 snprintf(name, sizeof(name), "discovery_trace");
51446 vport->debug_disc_trc =
51447diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
51448index 0b2c53a..aec2b45 100644
51449--- a/drivers/scsi/lpfc/lpfc_init.c
51450+++ b/drivers/scsi/lpfc/lpfc_init.c
51451@@ -11290,8 +11290,10 @@ lpfc_init(void)
51452 "misc_register returned with status %d", error);
51453
51454 if (lpfc_enable_npiv) {
51455- lpfc_transport_functions.vport_create = lpfc_vport_create;
51456- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
51457+ pax_open_kernel();
51458+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
51459+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
51460+ pax_close_kernel();
51461 }
51462 lpfc_transport_template =
51463 fc_attach_transport(&lpfc_transport_functions);
51464diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
51465index b99399f..d29dc75 100644
51466--- a/drivers/scsi/lpfc/lpfc_scsi.c
51467+++ b/drivers/scsi/lpfc/lpfc_scsi.c
51468@@ -383,7 +383,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
51469 unsigned long expires;
51470
51471 spin_lock_irqsave(&phba->hbalock, flags);
51472- atomic_inc(&phba->num_rsrc_err);
51473+ atomic_inc_unchecked(&phba->num_rsrc_err);
51474 phba->last_rsrc_error_time = jiffies;
51475
51476 expires = phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL;
51477@@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
51478 unsigned long num_rsrc_err, num_cmd_success;
51479 int i;
51480
51481- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
51482- num_cmd_success = atomic_read(&phba->num_cmd_success);
51483+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
51484+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
51485
51486 /*
51487 * The error and success command counters are global per
51488@@ -454,8 +454,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
51489 }
51490 }
51491 lpfc_destroy_vport_work_array(phba, vports);
51492- atomic_set(&phba->num_rsrc_err, 0);
51493- atomic_set(&phba->num_cmd_success, 0);
51494+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
51495+ atomic_set_unchecked(&phba->num_cmd_success, 0);
51496 }
51497
51498 /**
51499diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51500index c80ed04..e674f01 100644
51501--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51502+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51503@@ -1561,7 +1561,7 @@ _scsih_get_resync(struct device *dev)
51504 {
51505 struct scsi_device *sdev = to_scsi_device(dev);
51506 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
51507- static struct _raid_device *raid_device;
51508+ struct _raid_device *raid_device;
51509 unsigned long flags;
51510 Mpi2RaidVolPage0_t vol_pg0;
51511 Mpi2ConfigReply_t mpi_reply;
51512@@ -1613,7 +1613,7 @@ _scsih_get_state(struct device *dev)
51513 {
51514 struct scsi_device *sdev = to_scsi_device(dev);
51515 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
51516- static struct _raid_device *raid_device;
51517+ struct _raid_device *raid_device;
51518 unsigned long flags;
51519 Mpi2RaidVolPage0_t vol_pg0;
51520 Mpi2ConfigReply_t mpi_reply;
51521@@ -6663,7 +6663,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
51522 Mpi2EventDataIrOperationStatus_t *event_data =
51523 (Mpi2EventDataIrOperationStatus_t *)
51524 fw_event->event_data;
51525- static struct _raid_device *raid_device;
51526+ struct _raid_device *raid_device;
51527 unsigned long flags;
51528 u16 handle;
51529
51530@@ -7134,7 +7134,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
51531 u64 sas_address;
51532 struct _sas_device *sas_device;
51533 struct _sas_node *expander_device;
51534- static struct _raid_device *raid_device;
51535+ struct _raid_device *raid_device;
51536 u8 retry_count;
51537 unsigned long flags;
51538
51539diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
51540index bcb64eb..f08cf71 100644
51541--- a/drivers/scsi/pmcraid.c
51542+++ b/drivers/scsi/pmcraid.c
51543@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
51544 res->scsi_dev = scsi_dev;
51545 scsi_dev->hostdata = res;
51546 res->change_detected = 0;
51547- atomic_set(&res->read_failures, 0);
51548- atomic_set(&res->write_failures, 0);
51549+ atomic_set_unchecked(&res->read_failures, 0);
51550+ atomic_set_unchecked(&res->write_failures, 0);
51551 rc = 0;
51552 }
51553 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
51554@@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
51555
51556 /* If this was a SCSI read/write command keep count of errors */
51557 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
51558- atomic_inc(&res->read_failures);
51559+ atomic_inc_unchecked(&res->read_failures);
51560 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
51561- atomic_inc(&res->write_failures);
51562+ atomic_inc_unchecked(&res->write_failures);
51563
51564 if (!RES_IS_GSCSI(res->cfg_entry) &&
51565 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
51566@@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
51567 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
51568 * hrrq_id assigned here in queuecommand
51569 */
51570- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
51571+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
51572 pinstance->num_hrrq;
51573 cmd->cmd_done = pmcraid_io_done;
51574
51575@@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
51576 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
51577 * hrrq_id assigned here in queuecommand
51578 */
51579- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
51580+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
51581 pinstance->num_hrrq;
51582
51583 if (request_size) {
51584@@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
51585
51586 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
51587 /* add resources only after host is added into system */
51588- if (!atomic_read(&pinstance->expose_resources))
51589+ if (!atomic_read_unchecked(&pinstance->expose_resources))
51590 return;
51591
51592 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
51593@@ -5312,8 +5312,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
51594 init_waitqueue_head(&pinstance->reset_wait_q);
51595
51596 atomic_set(&pinstance->outstanding_cmds, 0);
51597- atomic_set(&pinstance->last_message_id, 0);
51598- atomic_set(&pinstance->expose_resources, 0);
51599+ atomic_set_unchecked(&pinstance->last_message_id, 0);
51600+ atomic_set_unchecked(&pinstance->expose_resources, 0);
51601
51602 INIT_LIST_HEAD(&pinstance->free_res_q);
51603 INIT_LIST_HEAD(&pinstance->used_res_q);
51604@@ -6026,7 +6026,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
51605 /* Schedule worker thread to handle CCN and take care of adding and
51606 * removing devices to OS
51607 */
51608- atomic_set(&pinstance->expose_resources, 1);
51609+ atomic_set_unchecked(&pinstance->expose_resources, 1);
51610 schedule_work(&pinstance->worker_q);
51611 return rc;
51612
51613diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
51614index e1d150f..6c6df44 100644
51615--- a/drivers/scsi/pmcraid.h
51616+++ b/drivers/scsi/pmcraid.h
51617@@ -748,7 +748,7 @@ struct pmcraid_instance {
51618 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
51619
51620 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
51621- atomic_t last_message_id;
51622+ atomic_unchecked_t last_message_id;
51623
51624 /* configuration table */
51625 struct pmcraid_config_table *cfg_table;
51626@@ -777,7 +777,7 @@ struct pmcraid_instance {
51627 atomic_t outstanding_cmds;
51628
51629 /* should add/delete resources to mid-layer now ?*/
51630- atomic_t expose_resources;
51631+ atomic_unchecked_t expose_resources;
51632
51633
51634
51635@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
51636 struct pmcraid_config_table_entry_ext cfg_entry_ext;
51637 };
51638 struct scsi_device *scsi_dev; /* Link scsi_device structure */
51639- atomic_t read_failures; /* count of failed READ commands */
51640- atomic_t write_failures; /* count of failed WRITE commands */
51641+ atomic_unchecked_t read_failures; /* count of failed READ commands */
51642+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
51643
51644 /* To indicate add/delete/modify during CCN */
51645 u8 change_detected;
51646diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
51647index 82b92c4..3178171 100644
51648--- a/drivers/scsi/qla2xxx/qla_attr.c
51649+++ b/drivers/scsi/qla2xxx/qla_attr.c
51650@@ -2192,7 +2192,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
51651 return 0;
51652 }
51653
51654-struct fc_function_template qla2xxx_transport_functions = {
51655+fc_function_template_no_const qla2xxx_transport_functions = {
51656
51657 .show_host_node_name = 1,
51658 .show_host_port_name = 1,
51659@@ -2240,7 +2240,7 @@ struct fc_function_template qla2xxx_transport_functions = {
51660 .bsg_timeout = qla24xx_bsg_timeout,
51661 };
51662
51663-struct fc_function_template qla2xxx_transport_vport_functions = {
51664+fc_function_template_no_const qla2xxx_transport_vport_functions = {
51665
51666 .show_host_node_name = 1,
51667 .show_host_port_name = 1,
51668diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
51669index b1865a7..a7723d3 100644
51670--- a/drivers/scsi/qla2xxx/qla_gbl.h
51671+++ b/drivers/scsi/qla2xxx/qla_gbl.h
51672@@ -571,8 +571,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *, size_t);
51673 struct device_attribute;
51674 extern struct device_attribute *qla2x00_host_attrs[];
51675 struct fc_function_template;
51676-extern struct fc_function_template qla2xxx_transport_functions;
51677-extern struct fc_function_template qla2xxx_transport_vport_functions;
51678+extern fc_function_template_no_const qla2xxx_transport_functions;
51679+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
51680 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
51681 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
51682 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
51683diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
51684index db3dbd9..2492392 100644
51685--- a/drivers/scsi/qla2xxx/qla_os.c
51686+++ b/drivers/scsi/qla2xxx/qla_os.c
51687@@ -1507,8 +1507,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
51688 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
51689 /* Ok, a 64bit DMA mask is applicable. */
51690 ha->flags.enable_64bit_addressing = 1;
51691- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
51692- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
51693+ pax_open_kernel();
51694+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
51695+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
51696+ pax_close_kernel();
51697 return;
51698 }
51699 }
51700diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
51701index 8f6d0fb..1b21097 100644
51702--- a/drivers/scsi/qla4xxx/ql4_def.h
51703+++ b/drivers/scsi/qla4xxx/ql4_def.h
51704@@ -305,7 +305,7 @@ struct ddb_entry {
51705 * (4000 only) */
51706 atomic_t relogin_timer; /* Max Time to wait for
51707 * relogin to complete */
51708- atomic_t relogin_retry_count; /* Num of times relogin has been
51709+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
51710 * retried */
51711 uint32_t default_time2wait; /* Default Min time between
51712 * relogins (+aens) */
51713diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
51714index 199fcf7..3c3a918 100644
51715--- a/drivers/scsi/qla4xxx/ql4_os.c
51716+++ b/drivers/scsi/qla4xxx/ql4_os.c
51717@@ -4496,12 +4496,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
51718 */
51719 if (!iscsi_is_session_online(cls_sess)) {
51720 /* Reset retry relogin timer */
51721- atomic_inc(&ddb_entry->relogin_retry_count);
51722+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
51723 DEBUG2(ql4_printk(KERN_INFO, ha,
51724 "%s: index[%d] relogin timed out-retrying"
51725 " relogin (%d), retry (%d)\n", __func__,
51726 ddb_entry->fw_ddb_index,
51727- atomic_read(&ddb_entry->relogin_retry_count),
51728+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
51729 ddb_entry->default_time2wait + 4));
51730 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
51731 atomic_set(&ddb_entry->retry_relogin_timer,
51732@@ -6609,7 +6609,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
51733
51734 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
51735 atomic_set(&ddb_entry->relogin_timer, 0);
51736- atomic_set(&ddb_entry->relogin_retry_count, 0);
51737+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
51738 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
51739 ddb_entry->default_relogin_timeout =
51740 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
51741diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
51742index 79c77b4..ef6ec0b 100644
51743--- a/drivers/scsi/scsi.c
51744+++ b/drivers/scsi/scsi.c
51745@@ -645,7 +645,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
51746 struct Scsi_Host *host = cmd->device->host;
51747 int rtn = 0;
51748
51749- atomic_inc(&cmd->device->iorequest_cnt);
51750+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
51751
51752 /* check if the device is still usable */
51753 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
51754diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
51755index 50a6e1a..de5252e 100644
51756--- a/drivers/scsi/scsi_lib.c
51757+++ b/drivers/scsi/scsi_lib.c
51758@@ -1583,7 +1583,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
51759 shost = sdev->host;
51760 scsi_init_cmd_errh(cmd);
51761 cmd->result = DID_NO_CONNECT << 16;
51762- atomic_inc(&cmd->device->iorequest_cnt);
51763+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
51764
51765 /*
51766 * SCSI request completion path will do scsi_device_unbusy(),
51767@@ -1606,9 +1606,9 @@ static void scsi_softirq_done(struct request *rq)
51768
51769 INIT_LIST_HEAD(&cmd->eh_entry);
51770
51771- atomic_inc(&cmd->device->iodone_cnt);
51772+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
51773 if (cmd->result)
51774- atomic_inc(&cmd->device->ioerr_cnt);
51775+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
51776
51777 disposition = scsi_decide_disposition(cmd);
51778 if (disposition != SUCCESS &&
51779diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
51780index f4cb7b3..dfa79c4 100644
51781--- a/drivers/scsi/scsi_sysfs.c
51782+++ b/drivers/scsi/scsi_sysfs.c
51783@@ -805,7 +805,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
51784 char *buf) \
51785 { \
51786 struct scsi_device *sdev = to_scsi_device(dev); \
51787- unsigned long long count = atomic_read(&sdev->field); \
51788+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
51789 return snprintf(buf, 20, "0x%llx\n", count); \
51790 } \
51791 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
51792diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
51793index 5d6f348..18778a6b 100644
51794--- a/drivers/scsi/scsi_transport_fc.c
51795+++ b/drivers/scsi/scsi_transport_fc.c
51796@@ -501,7 +501,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
51797 * Netlink Infrastructure
51798 */
51799
51800-static atomic_t fc_event_seq;
51801+static atomic_unchecked_t fc_event_seq;
51802
51803 /**
51804 * fc_get_event_number - Obtain the next sequential FC event number
51805@@ -514,7 +514,7 @@ static atomic_t fc_event_seq;
51806 u32
51807 fc_get_event_number(void)
51808 {
51809- return atomic_add_return(1, &fc_event_seq);
51810+ return atomic_add_return_unchecked(1, &fc_event_seq);
51811 }
51812 EXPORT_SYMBOL(fc_get_event_number);
51813
51814@@ -658,7 +658,7 @@ static __init int fc_transport_init(void)
51815 {
51816 int error;
51817
51818- atomic_set(&fc_event_seq, 0);
51819+ atomic_set_unchecked(&fc_event_seq, 0);
51820
51821 error = transport_class_register(&fc_host_class);
51822 if (error)
51823@@ -848,7 +848,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
51824 char *cp;
51825
51826 *val = simple_strtoul(buf, &cp, 0);
51827- if ((*cp && (*cp != '\n')) || (*val < 0))
51828+ if (*cp && (*cp != '\n'))
51829 return -EINVAL;
51830 /*
51831 * Check for overflow; dev_loss_tmo is u32
51832diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
51833index 67d43e3..8cee73c 100644
51834--- a/drivers/scsi/scsi_transport_iscsi.c
51835+++ b/drivers/scsi/scsi_transport_iscsi.c
51836@@ -79,7 +79,7 @@ struct iscsi_internal {
51837 struct transport_container session_cont;
51838 };
51839
51840-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
51841+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
51842 static struct workqueue_struct *iscsi_eh_timer_workq;
51843
51844 static DEFINE_IDA(iscsi_sess_ida);
51845@@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
51846 int err;
51847
51848 ihost = shost->shost_data;
51849- session->sid = atomic_add_return(1, &iscsi_session_nr);
51850+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
51851
51852 if (target_id == ISCSI_MAX_TARGET) {
51853 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
51854@@ -4515,7 +4515,7 @@ static __init int iscsi_transport_init(void)
51855 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
51856 ISCSI_TRANSPORT_VERSION);
51857
51858- atomic_set(&iscsi_session_nr, 0);
51859+ atomic_set_unchecked(&iscsi_session_nr, 0);
51860
51861 err = class_register(&iscsi_transport_class);
51862 if (err)
51863diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
51864index ae45bd9..c32a586 100644
51865--- a/drivers/scsi/scsi_transport_srp.c
51866+++ b/drivers/scsi/scsi_transport_srp.c
51867@@ -35,7 +35,7 @@
51868 #include "scsi_priv.h"
51869
51870 struct srp_host_attrs {
51871- atomic_t next_port_id;
51872+ atomic_unchecked_t next_port_id;
51873 };
51874 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
51875
51876@@ -100,7 +100,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
51877 struct Scsi_Host *shost = dev_to_shost(dev);
51878 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
51879
51880- atomic_set(&srp_host->next_port_id, 0);
51881+ atomic_set_unchecked(&srp_host->next_port_id, 0);
51882 return 0;
51883 }
51884
51885@@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
51886 rport_fast_io_fail_timedout);
51887 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
51888
51889- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
51890+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
51891 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
51892
51893 transport_setup_device(&rport->dev);
51894diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
51895index cfba74c..415f09b 100644
51896--- a/drivers/scsi/sd.c
51897+++ b/drivers/scsi/sd.c
51898@@ -3022,7 +3022,7 @@ static int sd_probe(struct device *dev)
51899 sdkp->disk = gd;
51900 sdkp->index = index;
51901 atomic_set(&sdkp->openers, 0);
51902- atomic_set(&sdkp->device->ioerr_cnt, 0);
51903+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
51904
51905 if (!sdp->request_queue->rq_timeout) {
51906 if (sdp->type != TYPE_MOD)
51907diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
51908index 6035444..c82edd4 100644
51909--- a/drivers/scsi/sg.c
51910+++ b/drivers/scsi/sg.c
51911@@ -1138,7 +1138,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
51912 sdp->disk->disk_name,
51913 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
51914 NULL,
51915- (char *)arg);
51916+ (char __user *)arg);
51917 case BLKTRACESTART:
51918 return blk_trace_startstop(sdp->device->request_queue, 1);
51919 case BLKTRACESTOP:
51920diff --git a/drivers/soc/tegra/fuse/fuse-tegra.c b/drivers/soc/tegra/fuse/fuse-tegra.c
51921index 11a5043..e36f04c 100644
51922--- a/drivers/soc/tegra/fuse/fuse-tegra.c
51923+++ b/drivers/soc/tegra/fuse/fuse-tegra.c
51924@@ -70,7 +70,7 @@ static ssize_t fuse_read(struct file *fd, struct kobject *kobj,
51925 return i;
51926 }
51927
51928-static struct bin_attribute fuse_bin_attr = {
51929+static bin_attribute_no_const fuse_bin_attr = {
51930 .attr = { .name = "fuse", .mode = S_IRUGO, },
51931 .read = fuse_read,
51932 };
51933diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
51934index 50f20f2..6bd81e0 100644
51935--- a/drivers/spi/spi.c
51936+++ b/drivers/spi/spi.c
51937@@ -2224,7 +2224,7 @@ int spi_bus_unlock(struct spi_master *master)
51938 EXPORT_SYMBOL_GPL(spi_bus_unlock);
51939
51940 /* portable code must never pass more than 32 bytes */
51941-#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
51942+#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
51943
51944 static u8 *buf;
51945
51946diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
51947index b41429f..2de5373 100644
51948--- a/drivers/staging/android/timed_output.c
51949+++ b/drivers/staging/android/timed_output.c
51950@@ -25,7 +25,7 @@
51951 #include "timed_output.h"
51952
51953 static struct class *timed_output_class;
51954-static atomic_t device_count;
51955+static atomic_unchecked_t device_count;
51956
51957 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
51958 char *buf)
51959@@ -65,7 +65,7 @@ static int create_timed_output_class(void)
51960 timed_output_class = class_create(THIS_MODULE, "timed_output");
51961 if (IS_ERR(timed_output_class))
51962 return PTR_ERR(timed_output_class);
51963- atomic_set(&device_count, 0);
51964+ atomic_set_unchecked(&device_count, 0);
51965 timed_output_class->dev_groups = timed_output_groups;
51966 }
51967
51968@@ -83,7 +83,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
51969 if (ret < 0)
51970 return ret;
51971
51972- tdev->index = atomic_inc_return(&device_count);
51973+ tdev->index = atomic_inc_return_unchecked(&device_count);
51974 tdev->dev = device_create(timed_output_class, NULL,
51975 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
51976 if (IS_ERR(tdev->dev))
51977diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
51978index 001348c..cfaac8a 100644
51979--- a/drivers/staging/gdm724x/gdm_tty.c
51980+++ b/drivers/staging/gdm724x/gdm_tty.c
51981@@ -44,7 +44,7 @@
51982 #define gdm_tty_send_control(n, r, v, d, l) (\
51983 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
51984
51985-#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
51986+#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
51987
51988 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
51989 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
51990diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
51991index 9cb222e..8766f26 100644
51992--- a/drivers/staging/imx-drm/imx-drm-core.c
51993+++ b/drivers/staging/imx-drm/imx-drm-core.c
51994@@ -357,7 +357,7 @@ int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
51995 if (imxdrm->pipes >= MAX_CRTC)
51996 return -EINVAL;
51997
51998- if (imxdrm->drm->open_count)
51999+ if (local_read(&imxdrm->drm->open_count))
52000 return -EBUSY;
52001
52002 imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
52003diff --git a/drivers/staging/line6/driver.c b/drivers/staging/line6/driver.c
52004index 503b2d7..c918745 100644
52005--- a/drivers/staging/line6/driver.c
52006+++ b/drivers/staging/line6/driver.c
52007@@ -463,7 +463,7 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
52008 {
52009 struct usb_device *usbdev = line6->usbdev;
52010 int ret;
52011- unsigned char len;
52012+ unsigned char *plen;
52013
52014 /* query the serial number: */
52015 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
52016@@ -476,27 +476,34 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
52017 return ret;
52018 }
52019
52020+ plen = kmalloc(1, GFP_KERNEL);
52021+ if (plen == NULL)
52022+ return -ENOMEM;
52023+
52024 /* Wait for data length. We'll get 0xff until length arrives. */
52025 do {
52026 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
52027 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
52028 USB_DIR_IN,
52029- 0x0012, 0x0000, &len, 1,
52030+ 0x0012, 0x0000, plen, 1,
52031 LINE6_TIMEOUT * HZ);
52032 if (ret < 0) {
52033 dev_err(line6->ifcdev,
52034 "receive length failed (error %d)\n", ret);
52035+ kfree(plen);
52036 return ret;
52037 }
52038- } while (len == 0xff);
52039+ } while (*plen == 0xff);
52040
52041- if (len != datalen) {
52042+ if (*plen != datalen) {
52043 /* should be equal or something went wrong */
52044 dev_err(line6->ifcdev,
52045 "length mismatch (expected %d, got %d)\n",
52046- (int)datalen, (int)len);
52047+ (int)datalen, (int)*plen);
52048+ kfree(plen);
52049 return -EINVAL;
52050 }
52051+ kfree(plen);
52052
52053 /* receive the result: */
52054 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
52055diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
52056index a94f336..6a1924d 100644
52057--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
52058+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
52059@@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
52060 return 0;
52061 }
52062
52063-sfw_test_client_ops_t brw_test_client;
52064-void brw_init_test_client(void)
52065-{
52066- brw_test_client.tso_init = brw_client_init;
52067- brw_test_client.tso_fini = brw_client_fini;
52068- brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
52069- brw_test_client.tso_done_rpc = brw_client_done_rpc;
52070+sfw_test_client_ops_t brw_test_client = {
52071+ .tso_init = brw_client_init,
52072+ .tso_fini = brw_client_fini,
52073+ .tso_prep_rpc = brw_client_prep_rpc,
52074+ .tso_done_rpc = brw_client_done_rpc,
52075 };
52076
52077 srpc_service_t brw_test_service;
52078diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
52079index df04ab7..1deb1ac 100644
52080--- a/drivers/staging/lustre/lnet/selftest/framework.c
52081+++ b/drivers/staging/lustre/lnet/selftest/framework.c
52082@@ -1632,12 +1632,10 @@ static srpc_service_t sfw_services[] = {
52083
52084 extern sfw_test_client_ops_t ping_test_client;
52085 extern srpc_service_t ping_test_service;
52086-extern void ping_init_test_client(void);
52087 extern void ping_init_test_service(void);
52088
52089 extern sfw_test_client_ops_t brw_test_client;
52090 extern srpc_service_t brw_test_service;
52091-extern void brw_init_test_client(void);
52092 extern void brw_init_test_service(void);
52093
52094
52095@@ -1681,12 +1679,10 @@ sfw_startup (void)
52096 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
52097 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
52098
52099- brw_init_test_client();
52100 brw_init_test_service();
52101 rc = sfw_register_test(&brw_test_service, &brw_test_client);
52102 LASSERT (rc == 0);
52103
52104- ping_init_test_client();
52105 ping_init_test_service();
52106 rc = sfw_register_test(&ping_test_service, &ping_test_client);
52107 LASSERT (rc == 0);
52108diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
52109index 750cac4..e4d751f 100644
52110--- a/drivers/staging/lustre/lnet/selftest/ping_test.c
52111+++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
52112@@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
52113 return 0;
52114 }
52115
52116-sfw_test_client_ops_t ping_test_client;
52117-void ping_init_test_client(void)
52118-{
52119- ping_test_client.tso_init = ping_client_init;
52120- ping_test_client.tso_fini = ping_client_fini;
52121- ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
52122- ping_test_client.tso_done_rpc = ping_client_done_rpc;
52123-}
52124+sfw_test_client_ops_t ping_test_client = {
52125+ .tso_init = ping_client_init,
52126+ .tso_fini = ping_client_fini,
52127+ .tso_prep_rpc = ping_client_prep_rpc,
52128+ .tso_done_rpc = ping_client_done_rpc,
52129+};
52130
52131 srpc_service_t ping_test_service;
52132 void ping_init_test_service(void)
52133diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
52134index 14ac46f..eca2c16 100644
52135--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
52136+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
52137@@ -1139,7 +1139,7 @@ struct ldlm_callback_suite {
52138 ldlm_completion_callback lcs_completion;
52139 ldlm_blocking_callback lcs_blocking;
52140 ldlm_glimpse_callback lcs_glimpse;
52141-};
52142+} __no_const;
52143
52144 /* ldlm_lockd.c */
52145 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
52146diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
52147index 2a88b80..62e7e5f 100644
52148--- a/drivers/staging/lustre/lustre/include/obd.h
52149+++ b/drivers/staging/lustre/lustre/include/obd.h
52150@@ -1362,7 +1362,7 @@ struct md_ops {
52151 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
52152 * wrapper function in include/linux/obd_class.h.
52153 */
52154-};
52155+} __no_const;
52156
52157 struct lsm_operations {
52158 void (*lsm_free)(struct lov_stripe_md *);
52159diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52160index b798daa..b28ca8f 100644
52161--- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52162+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52163@@ -258,7 +258,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
52164 int added = (mode == LCK_NL);
52165 int overlaps = 0;
52166 int splitted = 0;
52167- const struct ldlm_callback_suite null_cbs = { NULL };
52168+ const struct ldlm_callback_suite null_cbs = { };
52169
52170 CDEBUG(D_DLMTRACE, "flags %#llx owner %llu pid %u mode %u start %llu end %llu\n",
52171 *flags, new->l_policy_data.l_flock.owner,
52172diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52173index bbe2c68..c6b4275 100644
52174--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52175+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52176@@ -236,7 +236,7 @@ int proc_console_max_delay_cs(struct ctl_table *table, int write,
52177 void __user *buffer, size_t *lenp, loff_t *ppos)
52178 {
52179 int rc, max_delay_cs;
52180- struct ctl_table dummy = *table;
52181+ ctl_table_no_const dummy = *table;
52182 long d;
52183
52184 dummy.data = &max_delay_cs;
52185@@ -268,7 +268,7 @@ int proc_console_min_delay_cs(struct ctl_table *table, int write,
52186 void __user *buffer, size_t *lenp, loff_t *ppos)
52187 {
52188 int rc, min_delay_cs;
52189- struct ctl_table dummy = *table;
52190+ ctl_table_no_const dummy = *table;
52191 long d;
52192
52193 dummy.data = &min_delay_cs;
52194@@ -300,7 +300,7 @@ int proc_console_backoff(struct ctl_table *table, int write,
52195 void __user *buffer, size_t *lenp, loff_t *ppos)
52196 {
52197 int rc, backoff;
52198- struct ctl_table dummy = *table;
52199+ ctl_table_no_const dummy = *table;
52200
52201 dummy.data = &backoff;
52202 dummy.proc_handler = &proc_dointvec;
52203diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
52204index 2c4fc74..b04ca79 100644
52205--- a/drivers/staging/lustre/lustre/libcfs/module.c
52206+++ b/drivers/staging/lustre/lustre/libcfs/module.c
52207@@ -315,11 +315,11 @@ out:
52208
52209
52210 struct cfs_psdev_ops libcfs_psdev_ops = {
52211- libcfs_psdev_open,
52212- libcfs_psdev_release,
52213- NULL,
52214- NULL,
52215- libcfs_ioctl
52216+ .p_open = libcfs_psdev_open,
52217+ .p_close = libcfs_psdev_release,
52218+ .p_read = NULL,
52219+ .p_write = NULL,
52220+ .p_ioctl = libcfs_ioctl
52221 };
52222
52223 extern int insert_proc(void);
52224diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
52225index b0bb709..0117c96 100644
52226--- a/drivers/staging/lustre/lustre/llite/dir.c
52227+++ b/drivers/staging/lustre/lustre/llite/dir.c
52228@@ -661,7 +661,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
52229 int mode;
52230 int err;
52231
52232- mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
52233+ mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
52234 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
52235 strlen(filename), mode, LUSTRE_OPC_MKDIR,
52236 lump);
52237diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
52238index b2b6c3c..302e4e4 100644
52239--- a/drivers/staging/octeon/ethernet-rx.c
52240+++ b/drivers/staging/octeon/ethernet-rx.c
52241@@ -416,11 +416,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
52242 /* Increment RX stats for virtual ports */
52243 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
52244 #ifdef CONFIG_64BIT
52245- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
52246- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
52247+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
52248+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
52249 #else
52250- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
52251- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
52252+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
52253+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
52254 #endif
52255 }
52256 netif_receive_skb(skb);
52257@@ -431,9 +431,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
52258 dev->name);
52259 */
52260 #ifdef CONFIG_64BIT
52261- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
52262+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
52263 #else
52264- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
52265+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
52266 #endif
52267 dev_kfree_skb_irq(skb);
52268 }
52269diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
52270index 8f9e3fb..d283fb9 100644
52271--- a/drivers/staging/octeon/ethernet.c
52272+++ b/drivers/staging/octeon/ethernet.c
52273@@ -247,11 +247,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
52274 * since the RX tasklet also increments it.
52275 */
52276 #ifdef CONFIG_64BIT
52277- atomic64_add(rx_status.dropped_packets,
52278- (atomic64_t *)&priv->stats.rx_dropped);
52279+ atomic64_add_unchecked(rx_status.dropped_packets,
52280+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
52281 #else
52282- atomic_add(rx_status.dropped_packets,
52283- (atomic_t *)&priv->stats.rx_dropped);
52284+ atomic_add_unchecked(rx_status.dropped_packets,
52285+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
52286 #endif
52287 }
52288
52289diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
52290index 9191993..30e9817 100644
52291--- a/drivers/staging/rtl8188eu/include/hal_intf.h
52292+++ b/drivers/staging/rtl8188eu/include/hal_intf.h
52293@@ -225,7 +225,7 @@ struct hal_ops {
52294
52295 void (*hal_notch_filter)(struct adapter *adapter, bool enable);
52296 void (*hal_reset_security_engine)(struct adapter *adapter);
52297-};
52298+} __no_const;
52299
52300 enum rt_eeprom_type {
52301 EEPROM_93C46,
52302diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
52303index 070cc03..6806e37 100644
52304--- a/drivers/staging/rtl8712/rtl871x_io.h
52305+++ b/drivers/staging/rtl8712/rtl871x_io.h
52306@@ -108,7 +108,7 @@ struct _io_ops {
52307 u8 *pmem);
52308 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
52309 u8 *pmem);
52310-};
52311+} __no_const;
52312
52313 struct io_req {
52314 struct list_head list;
52315diff --git a/drivers/staging/unisys/visorchipset/visorchipset.h b/drivers/staging/unisys/visorchipset/visorchipset.h
52316index 2bf2e2f..84421c9 100644
52317--- a/drivers/staging/unisys/visorchipset/visorchipset.h
52318+++ b/drivers/staging/unisys/visorchipset/visorchipset.h
52319@@ -228,7 +228,7 @@ typedef struct {
52320 void (*device_resume)(ulong busNo, ulong devNo);
52321 int (*get_channel_info)(uuid_le typeGuid, ulong *minSize,
52322 ulong *maxSize);
52323-} VISORCHIPSET_BUSDEV_NOTIFIERS;
52324+} __no_const VISORCHIPSET_BUSDEV_NOTIFIERS;
52325
52326 /* These functions live inside visorchipset, and will be called to indicate
52327 * responses to specific events (by code outside of visorchipset).
52328@@ -243,7 +243,7 @@ typedef struct {
52329 void (*device_destroy)(ulong busNo, ulong devNo, int response);
52330 void (*device_pause)(ulong busNo, ulong devNo, int response);
52331 void (*device_resume)(ulong busNo, ulong devNo, int response);
52332-} VISORCHIPSET_BUSDEV_RESPONDERS;
52333+} __no_const VISORCHIPSET_BUSDEV_RESPONDERS;
52334
52335 /** Register functions (in the bus driver) to get called by visorchipset
52336 * whenever a bus or device appears for which this service partition is
52337diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
52338index ae0dade..803d53a 100644
52339--- a/drivers/staging/vt6655/hostap.c
52340+++ b/drivers/staging/vt6655/hostap.c
52341@@ -65,14 +65,13 @@
52342 *
52343 */
52344
52345+static net_device_ops_no_const apdev_netdev_ops;
52346+
52347 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
52348 {
52349 struct vnt_private *apdev_priv;
52350 struct net_device *dev = pDevice->dev;
52351 int ret;
52352- const struct net_device_ops apdev_netdev_ops = {
52353- .ndo_start_xmit = pDevice->tx_80211,
52354- };
52355
52356 pr_debug("%s: Enabling hostapd mode\n", dev->name);
52357
52358@@ -84,6 +83,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
52359 *apdev_priv = *pDevice;
52360 eth_hw_addr_inherit(pDevice->apdev, dev);
52361
52362+ /* only half broken now */
52363+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
52364 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
52365
52366 pDevice->apdev->type = ARPHRD_IEEE80211;
52367diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
52368index e7e9372..161f530 100644
52369--- a/drivers/target/sbp/sbp_target.c
52370+++ b/drivers/target/sbp/sbp_target.c
52371@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
52372
52373 #define SESSION_MAINTENANCE_INTERVAL HZ
52374
52375-static atomic_t login_id = ATOMIC_INIT(0);
52376+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
52377
52378 static void session_maintenance_work(struct work_struct *);
52379 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
52380@@ -444,7 +444,7 @@ static void sbp_management_request_login(
52381 login->lun = se_lun;
52382 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
52383 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
52384- login->login_id = atomic_inc_return(&login_id);
52385+ login->login_id = atomic_inc_return_unchecked(&login_id);
52386
52387 login->tgt_agt = sbp_target_agent_register(login);
52388 if (IS_ERR(login->tgt_agt)) {
52389diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
52390index c45f9e9..00e85f0 100644
52391--- a/drivers/target/target_core_device.c
52392+++ b/drivers/target/target_core_device.c
52393@@ -1532,7 +1532,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
52394 spin_lock_init(&dev->se_tmr_lock);
52395 spin_lock_init(&dev->qf_cmd_lock);
52396 sema_init(&dev->caw_sem, 1);
52397- atomic_set(&dev->dev_ordered_id, 0);
52398+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
52399 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
52400 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
52401 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
52402diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
52403index be877bf..7be9cd4 100644
52404--- a/drivers/target/target_core_transport.c
52405+++ b/drivers/target/target_core_transport.c
52406@@ -1168,7 +1168,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
52407 * Used to determine when ORDERED commands should go from
52408 * Dormant to Active status.
52409 */
52410- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
52411+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
52412 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
52413 cmd->se_ordered_id, cmd->sam_task_attr,
52414 dev->transport->name);
52415diff --git a/drivers/thermal/int340x_thermal/int3400_thermal.c b/drivers/thermal/int340x_thermal/int3400_thermal.c
52416index edc1cce..769e4cb 100644
52417--- a/drivers/thermal/int340x_thermal/int3400_thermal.c
52418+++ b/drivers/thermal/int340x_thermal/int3400_thermal.c
52419@@ -209,8 +209,10 @@ static int int3400_thermal_probe(struct platform_device *pdev)
52420 platform_set_drvdata(pdev, priv);
52421
52422 if (priv->uuid_bitmap & 1 << INT3400_THERMAL_PASSIVE_1) {
52423- int3400_thermal_ops.get_mode = int3400_thermal_get_mode;
52424- int3400_thermal_ops.set_mode = int3400_thermal_set_mode;
52425+ pax_open_kernel();
52426+ *(void **)&int3400_thermal_ops.get_mode = int3400_thermal_get_mode;
52427+ *(void **)&int3400_thermal_ops.set_mode = int3400_thermal_set_mode;
52428+ pax_close_kernel();
52429 }
52430 priv->thermal = thermal_zone_device_register("INT3400 Thermal", 0, 0,
52431 priv, &int3400_thermal_ops,
52432diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
52433index 62143ba..ae21165 100644
52434--- a/drivers/thermal/of-thermal.c
52435+++ b/drivers/thermal/of-thermal.c
52436@@ -30,6 +30,7 @@
52437 #include <linux/err.h>
52438 #include <linux/export.h>
52439 #include <linux/string.h>
52440+#include <linux/mm.h>
52441
52442 #include "thermal_core.h"
52443
52444@@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
52445 tz->get_trend = get_trend;
52446 tz->sensor_data = data;
52447
52448- tzd->ops->get_temp = of_thermal_get_temp;
52449- tzd->ops->get_trend = of_thermal_get_trend;
52450+ pax_open_kernel();
52451+ *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
52452+ *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
52453+ pax_close_kernel();
52454 mutex_unlock(&tzd->lock);
52455
52456 return tzd;
52457@@ -473,8 +476,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
52458 return;
52459
52460 mutex_lock(&tzd->lock);
52461- tzd->ops->get_temp = NULL;
52462- tzd->ops->get_trend = NULL;
52463+ pax_open_kernel();
52464+ *(void **)&tzd->ops->get_temp = NULL;
52465+ *(void **)&tzd->ops->get_trend = NULL;
52466+ pax_close_kernel();
52467
52468 tz->get_temp = NULL;
52469 tz->get_trend = NULL;
52470diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
52471index fd66f57..48e6376 100644
52472--- a/drivers/tty/cyclades.c
52473+++ b/drivers/tty/cyclades.c
52474@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
52475 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
52476 info->port.count);
52477 #endif
52478- info->port.count++;
52479+ atomic_inc(&info->port.count);
52480 #ifdef CY_DEBUG_COUNT
52481 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
52482- current->pid, info->port.count);
52483+ current->pid, atomic_read(&info->port.count));
52484 #endif
52485
52486 /*
52487@@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
52488 for (j = 0; j < cy_card[i].nports; j++) {
52489 info = &cy_card[i].ports[j];
52490
52491- if (info->port.count) {
52492+ if (atomic_read(&info->port.count)) {
52493 /* XXX is the ldisc num worth this? */
52494 struct tty_struct *tty;
52495 struct tty_ldisc *ld;
52496diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
52497index 4fcec1d..5a036f7 100644
52498--- a/drivers/tty/hvc/hvc_console.c
52499+++ b/drivers/tty/hvc/hvc_console.c
52500@@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
52501
52502 spin_lock_irqsave(&hp->port.lock, flags);
52503 /* Check and then increment for fast path open. */
52504- if (hp->port.count++ > 0) {
52505+ if (atomic_inc_return(&hp->port.count) > 1) {
52506 spin_unlock_irqrestore(&hp->port.lock, flags);
52507 hvc_kick();
52508 return 0;
52509@@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
52510
52511 spin_lock_irqsave(&hp->port.lock, flags);
52512
52513- if (--hp->port.count == 0) {
52514+ if (atomic_dec_return(&hp->port.count) == 0) {
52515 spin_unlock_irqrestore(&hp->port.lock, flags);
52516 /* We are done with the tty pointer now. */
52517 tty_port_tty_set(&hp->port, NULL);
52518@@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
52519 */
52520 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
52521 } else {
52522- if (hp->port.count < 0)
52523+ if (atomic_read(&hp->port.count) < 0)
52524 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
52525- hp->vtermno, hp->port.count);
52526+ hp->vtermno, atomic_read(&hp->port.count));
52527 spin_unlock_irqrestore(&hp->port.lock, flags);
52528 }
52529 }
52530@@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
52531 * open->hangup case this can be called after the final close so prevent
52532 * that from happening for now.
52533 */
52534- if (hp->port.count <= 0) {
52535+ if (atomic_read(&hp->port.count) <= 0) {
52536 spin_unlock_irqrestore(&hp->port.lock, flags);
52537 return;
52538 }
52539
52540- hp->port.count = 0;
52541+ atomic_set(&hp->port.count, 0);
52542 spin_unlock_irqrestore(&hp->port.lock, flags);
52543 tty_port_tty_set(&hp->port, NULL);
52544
52545@@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
52546 return -EPIPE;
52547
52548 /* FIXME what's this (unprotected) check for? */
52549- if (hp->port.count <= 0)
52550+ if (atomic_read(&hp->port.count) <= 0)
52551 return -EIO;
52552
52553 spin_lock_irqsave(&hp->lock, flags);
52554diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
52555index 81e939e..95ead10 100644
52556--- a/drivers/tty/hvc/hvcs.c
52557+++ b/drivers/tty/hvc/hvcs.c
52558@@ -83,6 +83,7 @@
52559 #include <asm/hvcserver.h>
52560 #include <asm/uaccess.h>
52561 #include <asm/vio.h>
52562+#include <asm/local.h>
52563
52564 /*
52565 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
52566@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
52567
52568 spin_lock_irqsave(&hvcsd->lock, flags);
52569
52570- if (hvcsd->port.count > 0) {
52571+ if (atomic_read(&hvcsd->port.count) > 0) {
52572 spin_unlock_irqrestore(&hvcsd->lock, flags);
52573 printk(KERN_INFO "HVCS: vterm state unchanged. "
52574 "The hvcs device node is still in use.\n");
52575@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
52576 }
52577 }
52578
52579- hvcsd->port.count = 0;
52580+ atomic_set(&hvcsd->port.count, 0);
52581 hvcsd->port.tty = tty;
52582 tty->driver_data = hvcsd;
52583
52584@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
52585 unsigned long flags;
52586
52587 spin_lock_irqsave(&hvcsd->lock, flags);
52588- hvcsd->port.count++;
52589+ atomic_inc(&hvcsd->port.count);
52590 hvcsd->todo_mask |= HVCS_SCHED_READ;
52591 spin_unlock_irqrestore(&hvcsd->lock, flags);
52592
52593@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
52594 hvcsd = tty->driver_data;
52595
52596 spin_lock_irqsave(&hvcsd->lock, flags);
52597- if (--hvcsd->port.count == 0) {
52598+ if (atomic_dec_and_test(&hvcsd->port.count)) {
52599
52600 vio_disable_interrupts(hvcsd->vdev);
52601
52602@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
52603
52604 free_irq(irq, hvcsd);
52605 return;
52606- } else if (hvcsd->port.count < 0) {
52607+ } else if (atomic_read(&hvcsd->port.count) < 0) {
52608 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
52609 " is missmanaged.\n",
52610- hvcsd->vdev->unit_address, hvcsd->port.count);
52611+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
52612 }
52613
52614 spin_unlock_irqrestore(&hvcsd->lock, flags);
52615@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
52616
52617 spin_lock_irqsave(&hvcsd->lock, flags);
52618 /* Preserve this so that we know how many kref refs to put */
52619- temp_open_count = hvcsd->port.count;
52620+ temp_open_count = atomic_read(&hvcsd->port.count);
52621
52622 /*
52623 * Don't kref put inside the spinlock because the destruction
52624@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
52625 tty->driver_data = NULL;
52626 hvcsd->port.tty = NULL;
52627
52628- hvcsd->port.count = 0;
52629+ atomic_set(&hvcsd->port.count, 0);
52630
52631 /* This will drop any buffered data on the floor which is OK in a hangup
52632 * scenario. */
52633@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
52634 * the middle of a write operation? This is a crummy place to do this
52635 * but we want to keep it all in the spinlock.
52636 */
52637- if (hvcsd->port.count <= 0) {
52638+ if (atomic_read(&hvcsd->port.count) <= 0) {
52639 spin_unlock_irqrestore(&hvcsd->lock, flags);
52640 return -ENODEV;
52641 }
52642@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
52643 {
52644 struct hvcs_struct *hvcsd = tty->driver_data;
52645
52646- if (!hvcsd || hvcsd->port.count <= 0)
52647+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
52648 return 0;
52649
52650 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
52651diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
52652index 4190199..06d5bfa 100644
52653--- a/drivers/tty/hvc/hvsi.c
52654+++ b/drivers/tty/hvc/hvsi.c
52655@@ -85,7 +85,7 @@ struct hvsi_struct {
52656 int n_outbuf;
52657 uint32_t vtermno;
52658 uint32_t virq;
52659- atomic_t seqno; /* HVSI packet sequence number */
52660+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
52661 uint16_t mctrl;
52662 uint8_t state; /* HVSI protocol state */
52663 uint8_t flags;
52664@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
52665
52666 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
52667 packet.hdr.len = sizeof(struct hvsi_query_response);
52668- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52669+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52670 packet.verb = VSV_SEND_VERSION_NUMBER;
52671 packet.u.version = HVSI_VERSION;
52672 packet.query_seqno = query_seqno+1;
52673@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
52674
52675 packet.hdr.type = VS_QUERY_PACKET_HEADER;
52676 packet.hdr.len = sizeof(struct hvsi_query);
52677- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52678+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52679 packet.verb = verb;
52680
52681 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
52682@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
52683 int wrote;
52684
52685 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
52686- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52687+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52688 packet.hdr.len = sizeof(struct hvsi_control);
52689 packet.verb = VSV_SET_MODEM_CTL;
52690 packet.mask = HVSI_TSDTR;
52691@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
52692 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
52693
52694 packet.hdr.type = VS_DATA_PACKET_HEADER;
52695- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52696+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52697 packet.hdr.len = count + sizeof(struct hvsi_header);
52698 memcpy(&packet.data, buf, count);
52699
52700@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
52701 struct hvsi_control packet __ALIGNED__;
52702
52703 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
52704- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
52705+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
52706 packet.hdr.len = 6;
52707 packet.verb = VSV_CLOSE_PROTOCOL;
52708
52709@@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
52710
52711 tty_port_tty_set(&hp->port, tty);
52712 spin_lock_irqsave(&hp->lock, flags);
52713- hp->port.count++;
52714+ atomic_inc(&hp->port.count);
52715 atomic_set(&hp->seqno, 0);
52716 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
52717 spin_unlock_irqrestore(&hp->lock, flags);
52718@@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
52719
52720 spin_lock_irqsave(&hp->lock, flags);
52721
52722- if (--hp->port.count == 0) {
52723+ if (atomic_dec_return(&hp->port.count) == 0) {
52724 tty_port_tty_set(&hp->port, NULL);
52725 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
52726
52727@@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
52728
52729 spin_lock_irqsave(&hp->lock, flags);
52730 }
52731- } else if (hp->port.count < 0)
52732+ } else if (atomic_read(&hp->port.count) < 0)
52733 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
52734- hp - hvsi_ports, hp->port.count);
52735+ hp - hvsi_ports, atomic_read(&hp->port.count));
52736
52737 spin_unlock_irqrestore(&hp->lock, flags);
52738 }
52739@@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
52740 tty_port_tty_set(&hp->port, NULL);
52741
52742 spin_lock_irqsave(&hp->lock, flags);
52743- hp->port.count = 0;
52744+ atomic_set(&hp->port.count, 0);
52745 hp->n_outbuf = 0;
52746 spin_unlock_irqrestore(&hp->lock, flags);
52747 }
52748diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
52749index 7ae6c29..05c6dba 100644
52750--- a/drivers/tty/hvc/hvsi_lib.c
52751+++ b/drivers/tty/hvc/hvsi_lib.c
52752@@ -8,7 +8,7 @@
52753
52754 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
52755 {
52756- packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
52757+ packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
52758
52759 /* Assumes that always succeeds, works in practice */
52760 return pv->put_chars(pv->termno, (char *)packet, packet->len);
52761@@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
52762
52763 /* Reset state */
52764 pv->established = 0;
52765- atomic_set(&pv->seqno, 0);
52766+ atomic_set_unchecked(&pv->seqno, 0);
52767
52768 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
52769
52770diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
52771index 345cebb..d5a1e9e 100644
52772--- a/drivers/tty/ipwireless/tty.c
52773+++ b/drivers/tty/ipwireless/tty.c
52774@@ -28,6 +28,7 @@
52775 #include <linux/tty_driver.h>
52776 #include <linux/tty_flip.h>
52777 #include <linux/uaccess.h>
52778+#include <asm/local.h>
52779
52780 #include "tty.h"
52781 #include "network.h"
52782@@ -93,10 +94,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
52783 return -ENODEV;
52784
52785 mutex_lock(&tty->ipw_tty_mutex);
52786- if (tty->port.count == 0)
52787+ if (atomic_read(&tty->port.count) == 0)
52788 tty->tx_bytes_queued = 0;
52789
52790- tty->port.count++;
52791+ atomic_inc(&tty->port.count);
52792
52793 tty->port.tty = linux_tty;
52794 linux_tty->driver_data = tty;
52795@@ -112,9 +113,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
52796
52797 static void do_ipw_close(struct ipw_tty *tty)
52798 {
52799- tty->port.count--;
52800-
52801- if (tty->port.count == 0) {
52802+ if (atomic_dec_return(&tty->port.count) == 0) {
52803 struct tty_struct *linux_tty = tty->port.tty;
52804
52805 if (linux_tty != NULL) {
52806@@ -135,7 +134,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
52807 return;
52808
52809 mutex_lock(&tty->ipw_tty_mutex);
52810- if (tty->port.count == 0) {
52811+ if (atomic_read(&tty->port.count) == 0) {
52812 mutex_unlock(&tty->ipw_tty_mutex);
52813 return;
52814 }
52815@@ -158,7 +157,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
52816
52817 mutex_lock(&tty->ipw_tty_mutex);
52818
52819- if (!tty->port.count) {
52820+ if (!atomic_read(&tty->port.count)) {
52821 mutex_unlock(&tty->ipw_tty_mutex);
52822 return;
52823 }
52824@@ -197,7 +196,7 @@ static int ipw_write(struct tty_struct *linux_tty,
52825 return -ENODEV;
52826
52827 mutex_lock(&tty->ipw_tty_mutex);
52828- if (!tty->port.count) {
52829+ if (!atomic_read(&tty->port.count)) {
52830 mutex_unlock(&tty->ipw_tty_mutex);
52831 return -EINVAL;
52832 }
52833@@ -237,7 +236,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
52834 if (!tty)
52835 return -ENODEV;
52836
52837- if (!tty->port.count)
52838+ if (!atomic_read(&tty->port.count))
52839 return -EINVAL;
52840
52841 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
52842@@ -279,7 +278,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
52843 if (!tty)
52844 return 0;
52845
52846- if (!tty->port.count)
52847+ if (!atomic_read(&tty->port.count))
52848 return 0;
52849
52850 return tty->tx_bytes_queued;
52851@@ -360,7 +359,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
52852 if (!tty)
52853 return -ENODEV;
52854
52855- if (!tty->port.count)
52856+ if (!atomic_read(&tty->port.count))
52857 return -EINVAL;
52858
52859 return get_control_lines(tty);
52860@@ -376,7 +375,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
52861 if (!tty)
52862 return -ENODEV;
52863
52864- if (!tty->port.count)
52865+ if (!atomic_read(&tty->port.count))
52866 return -EINVAL;
52867
52868 return set_control_lines(tty, set, clear);
52869@@ -390,7 +389,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
52870 if (!tty)
52871 return -ENODEV;
52872
52873- if (!tty->port.count)
52874+ if (!atomic_read(&tty->port.count))
52875 return -EINVAL;
52876
52877 /* FIXME: Exactly how is the tty object locked here .. */
52878@@ -546,7 +545,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
52879 * are gone */
52880 mutex_lock(&ttyj->ipw_tty_mutex);
52881 }
52882- while (ttyj->port.count)
52883+ while (atomic_read(&ttyj->port.count))
52884 do_ipw_close(ttyj);
52885 ipwireless_disassociate_network_ttys(network,
52886 ttyj->channel_idx);
52887diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
52888index 14c54e0..1efd4f2 100644
52889--- a/drivers/tty/moxa.c
52890+++ b/drivers/tty/moxa.c
52891@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
52892 }
52893
52894 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
52895- ch->port.count++;
52896+ atomic_inc(&ch->port.count);
52897 tty->driver_data = ch;
52898 tty_port_tty_set(&ch->port, tty);
52899 mutex_lock(&ch->port.mutex);
52900diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
52901index c434376..114ce13 100644
52902--- a/drivers/tty/n_gsm.c
52903+++ b/drivers/tty/n_gsm.c
52904@@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
52905 spin_lock_init(&dlci->lock);
52906 mutex_init(&dlci->mutex);
52907 dlci->fifo = &dlci->_fifo;
52908- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
52909+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
52910 kfree(dlci);
52911 return NULL;
52912 }
52913@@ -2958,7 +2958,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
52914 struct gsm_dlci *dlci = tty->driver_data;
52915 struct tty_port *port = &dlci->port;
52916
52917- port->count++;
52918+ atomic_inc(&port->count);
52919 tty_port_tty_set(port, tty);
52920
52921 dlci->modem_rx = 0;
52922diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
52923index 2e900a9..576d216 100644
52924--- a/drivers/tty/n_tty.c
52925+++ b/drivers/tty/n_tty.c
52926@@ -115,7 +115,7 @@ struct n_tty_data {
52927 int minimum_to_wake;
52928
52929 /* consumer-published */
52930- size_t read_tail;
52931+ size_t read_tail __intentional_overflow(-1);
52932 size_t line_start;
52933
52934 /* protected by output lock */
52935@@ -2522,6 +2522,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
52936 {
52937 *ops = tty_ldisc_N_TTY;
52938 ops->owner = NULL;
52939- ops->refcount = ops->flags = 0;
52940+ atomic_set(&ops->refcount, 0);
52941+ ops->flags = 0;
52942 }
52943 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
52944diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
52945index 7c4447a..70fbc1e 100644
52946--- a/drivers/tty/pty.c
52947+++ b/drivers/tty/pty.c
52948@@ -830,8 +830,10 @@ static void __init unix98_pty_init(void)
52949 panic("Couldn't register Unix98 pts driver");
52950
52951 /* Now create the /dev/ptmx special device */
52952+ pax_open_kernel();
52953 tty_default_fops(&ptmx_fops);
52954- ptmx_fops.open = ptmx_open;
52955+ *(void **)&ptmx_fops.open = ptmx_open;
52956+ pax_close_kernel();
52957
52958 cdev_init(&ptmx_cdev, &ptmx_fops);
52959 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
52960diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
52961index 383c4c7..d408e21 100644
52962--- a/drivers/tty/rocket.c
52963+++ b/drivers/tty/rocket.c
52964@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
52965 tty->driver_data = info;
52966 tty_port_tty_set(port, tty);
52967
52968- if (port->count++ == 0) {
52969+ if (atomic_inc_return(&port->count) == 1) {
52970 atomic_inc(&rp_num_ports_open);
52971
52972 #ifdef ROCKET_DEBUG_OPEN
52973@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
52974 #endif
52975 }
52976 #ifdef ROCKET_DEBUG_OPEN
52977- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
52978+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
52979 #endif
52980
52981 /*
52982@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
52983 spin_unlock_irqrestore(&info->port.lock, flags);
52984 return;
52985 }
52986- if (info->port.count)
52987+ if (atomic_read(&info->port.count))
52988 atomic_dec(&rp_num_ports_open);
52989 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
52990 spin_unlock_irqrestore(&info->port.lock, flags);
52991diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
52992index aa28209..e08fb85 100644
52993--- a/drivers/tty/serial/ioc4_serial.c
52994+++ b/drivers/tty/serial/ioc4_serial.c
52995@@ -437,7 +437,7 @@ struct ioc4_soft {
52996 } is_intr_info[MAX_IOC4_INTR_ENTS];
52997
52998 /* Number of entries active in the above array */
52999- atomic_t is_num_intrs;
53000+ atomic_unchecked_t is_num_intrs;
53001 } is_intr_type[IOC4_NUM_INTR_TYPES];
53002
53003 /* is_ir_lock must be held while
53004@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
53005 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
53006 || (type == IOC4_OTHER_INTR_TYPE)));
53007
53008- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
53009+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
53010 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
53011
53012 /* Save off the lower level interrupt handler */
53013@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
53014
53015 soft = arg;
53016 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
53017- num_intrs = (int)atomic_read(
53018+ num_intrs = (int)atomic_read_unchecked(
53019 &soft->is_intr_type[intr_type].is_num_intrs);
53020
53021 this_mir = this_ir = pending_intrs(soft, intr_type);
53022diff --git a/drivers/tty/serial/kgdb_nmi.c b/drivers/tty/serial/kgdb_nmi.c
53023index 129dc5b..1da5bb8 100644
53024--- a/drivers/tty/serial/kgdb_nmi.c
53025+++ b/drivers/tty/serial/kgdb_nmi.c
53026@@ -53,7 +53,9 @@ static int kgdb_nmi_console_setup(struct console *co, char *options)
53027 * I/O utilities that messages sent to the console will automatically
53028 * be displayed on the dbg_io.
53029 */
53030- dbg_io_ops->is_console = true;
53031+ pax_open_kernel();
53032+ *(int *)&dbg_io_ops->is_console = true;
53033+ pax_close_kernel();
53034
53035 return 0;
53036 }
53037diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
53038index a260cde..6b2b5ce 100644
53039--- a/drivers/tty/serial/kgdboc.c
53040+++ b/drivers/tty/serial/kgdboc.c
53041@@ -24,8 +24,9 @@
53042 #define MAX_CONFIG_LEN 40
53043
53044 static struct kgdb_io kgdboc_io_ops;
53045+static struct kgdb_io kgdboc_io_ops_console;
53046
53047-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
53048+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
53049 static int configured = -1;
53050
53051 static char config[MAX_CONFIG_LEN];
53052@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
53053 kgdboc_unregister_kbd();
53054 if (configured == 1)
53055 kgdb_unregister_io_module(&kgdboc_io_ops);
53056+ else if (configured == 2)
53057+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
53058 }
53059
53060 static int configure_kgdboc(void)
53061@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
53062 int err;
53063 char *cptr = config;
53064 struct console *cons;
53065+ int is_console = 0;
53066
53067 err = kgdboc_option_setup(config);
53068 if (err || !strlen(config) || isspace(config[0]))
53069 goto noconfig;
53070
53071 err = -ENODEV;
53072- kgdboc_io_ops.is_console = 0;
53073 kgdb_tty_driver = NULL;
53074
53075 kgdboc_use_kms = 0;
53076@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
53077 int idx;
53078 if (cons->device && cons->device(cons, &idx) == p &&
53079 idx == tty_line) {
53080- kgdboc_io_ops.is_console = 1;
53081+ is_console = 1;
53082 break;
53083 }
53084 cons = cons->next;
53085@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
53086 kgdb_tty_line = tty_line;
53087
53088 do_register:
53089- err = kgdb_register_io_module(&kgdboc_io_ops);
53090+ if (is_console) {
53091+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
53092+ configured = 2;
53093+ } else {
53094+ err = kgdb_register_io_module(&kgdboc_io_ops);
53095+ configured = 1;
53096+ }
53097 if (err)
53098 goto noconfig;
53099
53100@@ -205,8 +214,6 @@ do_register:
53101 if (err)
53102 goto nmi_con_failed;
53103
53104- configured = 1;
53105-
53106 return 0;
53107
53108 nmi_con_failed:
53109@@ -223,7 +230,7 @@ noconfig:
53110 static int __init init_kgdboc(void)
53111 {
53112 /* Already configured? */
53113- if (configured == 1)
53114+ if (configured >= 1)
53115 return 0;
53116
53117 return configure_kgdboc();
53118@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
53119 if (config[len - 1] == '\n')
53120 config[len - 1] = '\0';
53121
53122- if (configured == 1)
53123+ if (configured >= 1)
53124 cleanup_kgdboc();
53125
53126 /* Go and configure with the new params. */
53127@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
53128 .post_exception = kgdboc_post_exp_handler,
53129 };
53130
53131+static struct kgdb_io kgdboc_io_ops_console = {
53132+ .name = "kgdboc",
53133+ .read_char = kgdboc_get_char,
53134+ .write_char = kgdboc_put_char,
53135+ .pre_exception = kgdboc_pre_exp_handler,
53136+ .post_exception = kgdboc_post_exp_handler,
53137+ .is_console = 1
53138+};
53139+
53140 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
53141 /* This is only available if kgdboc is a built in for early debugging */
53142 static int __init kgdboc_early_init(char *opt)
53143diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
53144index 4b6c783..9a19db3 100644
53145--- a/drivers/tty/serial/msm_serial.c
53146+++ b/drivers/tty/serial/msm_serial.c
53147@@ -1028,7 +1028,7 @@ static struct uart_driver msm_uart_driver = {
53148 .cons = MSM_CONSOLE,
53149 };
53150
53151-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
53152+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
53153
53154 static const struct of_device_id msm_uartdm_table[] = {
53155 { .compatible = "qcom,msm-uartdm-v1.1", .data = (void *)UARTDM_1P1 },
53156@@ -1047,7 +1047,7 @@ static int msm_serial_probe(struct platform_device *pdev)
53157 int irq;
53158
53159 if (pdev->id == -1)
53160- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
53161+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
53162
53163 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
53164 return -ENXIO;
53165diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
53166index c78f43a..22b1dab 100644
53167--- a/drivers/tty/serial/samsung.c
53168+++ b/drivers/tty/serial/samsung.c
53169@@ -478,11 +478,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
53170 }
53171 }
53172
53173+static int s3c64xx_serial_startup(struct uart_port *port);
53174 static int s3c24xx_serial_startup(struct uart_port *port)
53175 {
53176 struct s3c24xx_uart_port *ourport = to_ourport(port);
53177 int ret;
53178
53179+ /* Startup sequence is different for s3c64xx and higher SoC's */
53180+ if (s3c24xx_serial_has_interrupt_mask(port))
53181+ return s3c64xx_serial_startup(port);
53182+
53183 dbg("s3c24xx_serial_startup: port=%p (%08llx,%p)\n",
53184 port, (unsigned long long)port->mapbase, port->membase);
53185
53186@@ -1155,10 +1160,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
53187 /* setup info for port */
53188 port->dev = &platdev->dev;
53189
53190- /* Startup sequence is different for s3c64xx and higher SoC's */
53191- if (s3c24xx_serial_has_interrupt_mask(port))
53192- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
53193-
53194 port->uartclk = 1;
53195
53196 if (cfg->uart_flags & UPF_CONS_FLOW) {
53197diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
53198index eaeb9a0..01a238c 100644
53199--- a/drivers/tty/serial/serial_core.c
53200+++ b/drivers/tty/serial/serial_core.c
53201@@ -1339,7 +1339,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
53202
53203 pr_debug("uart_close(%d) called\n", uport ? uport->line : -1);
53204
53205- if (!port->count || tty_port_close_start(port, tty, filp) == 0)
53206+ if (!atomic_read(&port->count) || tty_port_close_start(port, tty, filp) == 0)
53207 return;
53208
53209 /*
53210@@ -1466,7 +1466,7 @@ static void uart_hangup(struct tty_struct *tty)
53211 uart_flush_buffer(tty);
53212 uart_shutdown(tty, state);
53213 spin_lock_irqsave(&port->lock, flags);
53214- port->count = 0;
53215+ atomic_set(&port->count, 0);
53216 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
53217 spin_unlock_irqrestore(&port->lock, flags);
53218 tty_port_tty_set(port, NULL);
53219@@ -1564,7 +1564,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
53220 goto end;
53221 }
53222
53223- port->count++;
53224+ atomic_inc(&port->count);
53225 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
53226 retval = -ENXIO;
53227 goto err_dec_count;
53228@@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
53229 end:
53230 return retval;
53231 err_dec_count:
53232- port->count--;
53233+ atomic_dec(&port->count);
53234 mutex_unlock(&port->mutex);
53235 goto end;
53236 }
53237diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
53238index b799170..87dafd5 100644
53239--- a/drivers/tty/synclink.c
53240+++ b/drivers/tty/synclink.c
53241@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
53242
53243 if (debug_level >= DEBUG_LEVEL_INFO)
53244 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
53245- __FILE__,__LINE__, info->device_name, info->port.count);
53246+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
53247
53248 if (tty_port_close_start(&info->port, tty, filp) == 0)
53249 goto cleanup;
53250@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
53251 cleanup:
53252 if (debug_level >= DEBUG_LEVEL_INFO)
53253 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
53254- tty->driver->name, info->port.count);
53255+ tty->driver->name, atomic_read(&info->port.count));
53256
53257 } /* end of mgsl_close() */
53258
53259@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
53260
53261 mgsl_flush_buffer(tty);
53262 shutdown(info);
53263-
53264- info->port.count = 0;
53265+
53266+ atomic_set(&info->port.count, 0);
53267 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53268 info->port.tty = NULL;
53269
53270@@ -3296,10 +3296,10 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53271
53272 if (debug_level >= DEBUG_LEVEL_INFO)
53273 printk("%s(%d):block_til_ready before block on %s count=%d\n",
53274- __FILE__,__LINE__, tty->driver->name, port->count );
53275+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53276
53277 spin_lock_irqsave(&info->irq_spinlock, flags);
53278- port->count--;
53279+ atomic_dec(&port->count);
53280 spin_unlock_irqrestore(&info->irq_spinlock, flags);
53281 port->blocked_open++;
53282
53283@@ -3327,7 +3327,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53284
53285 if (debug_level >= DEBUG_LEVEL_INFO)
53286 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
53287- __FILE__,__LINE__, tty->driver->name, port->count );
53288+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53289
53290 tty_unlock(tty);
53291 schedule();
53292@@ -3339,12 +3339,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53293
53294 /* FIXME: Racy on hangup during close wait */
53295 if (!tty_hung_up_p(filp))
53296- port->count++;
53297+ atomic_inc(&port->count);
53298 port->blocked_open--;
53299
53300 if (debug_level >= DEBUG_LEVEL_INFO)
53301 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
53302- __FILE__,__LINE__, tty->driver->name, port->count );
53303+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53304
53305 if (!retval)
53306 port->flags |= ASYNC_NORMAL_ACTIVE;
53307@@ -3396,7 +3396,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
53308
53309 if (debug_level >= DEBUG_LEVEL_INFO)
53310 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
53311- __FILE__,__LINE__,tty->driver->name, info->port.count);
53312+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
53313
53314 /* If port is closing, signal caller to try again */
53315 if (info->port.flags & ASYNC_CLOSING){
53316@@ -3415,10 +3415,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
53317 spin_unlock_irqrestore(&info->netlock, flags);
53318 goto cleanup;
53319 }
53320- info->port.count++;
53321+ atomic_inc(&info->port.count);
53322 spin_unlock_irqrestore(&info->netlock, flags);
53323
53324- if (info->port.count == 1) {
53325+ if (atomic_read(&info->port.count) == 1) {
53326 /* 1st open on this device, init hardware */
53327 retval = startup(info);
53328 if (retval < 0)
53329@@ -3442,8 +3442,8 @@ cleanup:
53330 if (retval) {
53331 if (tty->count == 1)
53332 info->port.tty = NULL; /* tty layer will release tty struct */
53333- if(info->port.count)
53334- info->port.count--;
53335+ if (atomic_read(&info->port.count))
53336+ atomic_dec(&info->port.count);
53337 }
53338
53339 return retval;
53340@@ -7661,7 +7661,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53341 unsigned short new_crctype;
53342
53343 /* return error if TTY interface open */
53344- if (info->port.count)
53345+ if (atomic_read(&info->port.count))
53346 return -EBUSY;
53347
53348 switch (encoding)
53349@@ -7756,7 +7756,7 @@ static int hdlcdev_open(struct net_device *dev)
53350
53351 /* arbitrate between network and tty opens */
53352 spin_lock_irqsave(&info->netlock, flags);
53353- if (info->port.count != 0 || info->netcount != 0) {
53354+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53355 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
53356 spin_unlock_irqrestore(&info->netlock, flags);
53357 return -EBUSY;
53358@@ -7842,7 +7842,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53359 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
53360
53361 /* return error if TTY interface open */
53362- if (info->port.count)
53363+ if (atomic_read(&info->port.count))
53364 return -EBUSY;
53365
53366 if (cmd != SIOCWANDEV)
53367diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
53368index 0e8c39b..e0cb171 100644
53369--- a/drivers/tty/synclink_gt.c
53370+++ b/drivers/tty/synclink_gt.c
53371@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
53372 tty->driver_data = info;
53373 info->port.tty = tty;
53374
53375- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
53376+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
53377
53378 /* If port is closing, signal caller to try again */
53379 if (info->port.flags & ASYNC_CLOSING){
53380@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
53381 mutex_unlock(&info->port.mutex);
53382 goto cleanup;
53383 }
53384- info->port.count++;
53385+ atomic_inc(&info->port.count);
53386 spin_unlock_irqrestore(&info->netlock, flags);
53387
53388- if (info->port.count == 1) {
53389+ if (atomic_read(&info->port.count) == 1) {
53390 /* 1st open on this device, init hardware */
53391 retval = startup(info);
53392 if (retval < 0) {
53393@@ -715,8 +715,8 @@ cleanup:
53394 if (retval) {
53395 if (tty->count == 1)
53396 info->port.tty = NULL; /* tty layer will release tty struct */
53397- if(info->port.count)
53398- info->port.count--;
53399+ if(atomic_read(&info->port.count))
53400+ atomic_dec(&info->port.count);
53401 }
53402
53403 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
53404@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53405
53406 if (sanity_check(info, tty->name, "close"))
53407 return;
53408- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
53409+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
53410
53411 if (tty_port_close_start(&info->port, tty, filp) == 0)
53412 goto cleanup;
53413@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53414 tty_port_close_end(&info->port, tty);
53415 info->port.tty = NULL;
53416 cleanup:
53417- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
53418+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
53419 }
53420
53421 static void hangup(struct tty_struct *tty)
53422@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
53423 shutdown(info);
53424
53425 spin_lock_irqsave(&info->port.lock, flags);
53426- info->port.count = 0;
53427+ atomic_set(&info->port.count, 0);
53428 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53429 info->port.tty = NULL;
53430 spin_unlock_irqrestore(&info->port.lock, flags);
53431@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53432 unsigned short new_crctype;
53433
53434 /* return error if TTY interface open */
53435- if (info->port.count)
53436+ if (atomic_read(&info->port.count))
53437 return -EBUSY;
53438
53439 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
53440@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
53441
53442 /* arbitrate between network and tty opens */
53443 spin_lock_irqsave(&info->netlock, flags);
53444- if (info->port.count != 0 || info->netcount != 0) {
53445+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53446 DBGINFO(("%s hdlc_open busy\n", dev->name));
53447 spin_unlock_irqrestore(&info->netlock, flags);
53448 return -EBUSY;
53449@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53450 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
53451
53452 /* return error if TTY interface open */
53453- if (info->port.count)
53454+ if (atomic_read(&info->port.count))
53455 return -EBUSY;
53456
53457 if (cmd != SIOCWANDEV)
53458@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
53459 if (port == NULL)
53460 continue;
53461 spin_lock(&port->lock);
53462- if ((port->port.count || port->netcount) &&
53463+ if ((atomic_read(&port->port.count) || port->netcount) &&
53464 port->pending_bh && !port->bh_running &&
53465 !port->bh_requested) {
53466 DBGISR(("%s bh queued\n", port->device_name));
53467@@ -3299,7 +3299,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53468 add_wait_queue(&port->open_wait, &wait);
53469
53470 spin_lock_irqsave(&info->lock, flags);
53471- port->count--;
53472+ atomic_dec(&port->count);
53473 spin_unlock_irqrestore(&info->lock, flags);
53474 port->blocked_open++;
53475
53476@@ -3335,7 +3335,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53477 remove_wait_queue(&port->open_wait, &wait);
53478
53479 if (!tty_hung_up_p(filp))
53480- port->count++;
53481+ atomic_inc(&port->count);
53482 port->blocked_open--;
53483
53484 if (!retval)
53485diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
53486index c3f9091..abe4601 100644
53487--- a/drivers/tty/synclinkmp.c
53488+++ b/drivers/tty/synclinkmp.c
53489@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
53490
53491 if (debug_level >= DEBUG_LEVEL_INFO)
53492 printk("%s(%d):%s open(), old ref count = %d\n",
53493- __FILE__,__LINE__,tty->driver->name, info->port.count);
53494+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
53495
53496 /* If port is closing, signal caller to try again */
53497 if (info->port.flags & ASYNC_CLOSING){
53498@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
53499 spin_unlock_irqrestore(&info->netlock, flags);
53500 goto cleanup;
53501 }
53502- info->port.count++;
53503+ atomic_inc(&info->port.count);
53504 spin_unlock_irqrestore(&info->netlock, flags);
53505
53506- if (info->port.count == 1) {
53507+ if (atomic_read(&info->port.count) == 1) {
53508 /* 1st open on this device, init hardware */
53509 retval = startup(info);
53510 if (retval < 0)
53511@@ -796,8 +796,8 @@ cleanup:
53512 if (retval) {
53513 if (tty->count == 1)
53514 info->port.tty = NULL; /* tty layer will release tty struct */
53515- if(info->port.count)
53516- info->port.count--;
53517+ if(atomic_read(&info->port.count))
53518+ atomic_dec(&info->port.count);
53519 }
53520
53521 return retval;
53522@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53523
53524 if (debug_level >= DEBUG_LEVEL_INFO)
53525 printk("%s(%d):%s close() entry, count=%d\n",
53526- __FILE__,__LINE__, info->device_name, info->port.count);
53527+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
53528
53529 if (tty_port_close_start(&info->port, tty, filp) == 0)
53530 goto cleanup;
53531@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53532 cleanup:
53533 if (debug_level >= DEBUG_LEVEL_INFO)
53534 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
53535- tty->driver->name, info->port.count);
53536+ tty->driver->name, atomic_read(&info->port.count));
53537 }
53538
53539 /* Called by tty_hangup() when a hangup is signaled.
53540@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
53541 shutdown(info);
53542
53543 spin_lock_irqsave(&info->port.lock, flags);
53544- info->port.count = 0;
53545+ atomic_set(&info->port.count, 0);
53546 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53547 info->port.tty = NULL;
53548 spin_unlock_irqrestore(&info->port.lock, flags);
53549@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53550 unsigned short new_crctype;
53551
53552 /* return error if TTY interface open */
53553- if (info->port.count)
53554+ if (atomic_read(&info->port.count))
53555 return -EBUSY;
53556
53557 switch (encoding)
53558@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
53559
53560 /* arbitrate between network and tty opens */
53561 spin_lock_irqsave(&info->netlock, flags);
53562- if (info->port.count != 0 || info->netcount != 0) {
53563+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53564 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
53565 spin_unlock_irqrestore(&info->netlock, flags);
53566 return -EBUSY;
53567@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53568 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
53569
53570 /* return error if TTY interface open */
53571- if (info->port.count)
53572+ if (atomic_read(&info->port.count))
53573 return -EBUSY;
53574
53575 if (cmd != SIOCWANDEV)
53576@@ -2621,7 +2621,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
53577 * do not request bottom half processing if the
53578 * device is not open in a normal mode.
53579 */
53580- if ( port && (port->port.count || port->netcount) &&
53581+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
53582 port->pending_bh && !port->bh_running &&
53583 !port->bh_requested ) {
53584 if ( debug_level >= DEBUG_LEVEL_ISR )
53585@@ -3318,10 +3318,10 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53586
53587 if (debug_level >= DEBUG_LEVEL_INFO)
53588 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
53589- __FILE__,__LINE__, tty->driver->name, port->count );
53590+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53591
53592 spin_lock_irqsave(&info->lock, flags);
53593- port->count--;
53594+ atomic_dec(&port->count);
53595 spin_unlock_irqrestore(&info->lock, flags);
53596 port->blocked_open++;
53597
53598@@ -3349,7 +3349,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53599
53600 if (debug_level >= DEBUG_LEVEL_INFO)
53601 printk("%s(%d):%s block_til_ready() count=%d\n",
53602- __FILE__,__LINE__, tty->driver->name, port->count );
53603+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53604
53605 tty_unlock(tty);
53606 schedule();
53607@@ -3359,12 +3359,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53608 set_current_state(TASK_RUNNING);
53609 remove_wait_queue(&port->open_wait, &wait);
53610 if (!tty_hung_up_p(filp))
53611- port->count++;
53612+ atomic_inc(&port->count);
53613 port->blocked_open--;
53614
53615 if (debug_level >= DEBUG_LEVEL_INFO)
53616 printk("%s(%d):%s block_til_ready() after, count=%d\n",
53617- __FILE__,__LINE__, tty->driver->name, port->count );
53618+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53619
53620 if (!retval)
53621 port->flags |= ASYNC_NORMAL_ACTIVE;
53622diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
53623index 42bad18..447d7a2 100644
53624--- a/drivers/tty/sysrq.c
53625+++ b/drivers/tty/sysrq.c
53626@@ -1084,7 +1084,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
53627 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
53628 size_t count, loff_t *ppos)
53629 {
53630- if (count) {
53631+ if (count && capable(CAP_SYS_ADMIN)) {
53632 char c;
53633
53634 if (get_user(c, buf))
53635diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
53636index 0508a1d..b610592 100644
53637--- a/drivers/tty/tty_io.c
53638+++ b/drivers/tty/tty_io.c
53639@@ -3498,7 +3498,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
53640
53641 void tty_default_fops(struct file_operations *fops)
53642 {
53643- *fops = tty_fops;
53644+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
53645 }
53646
53647 /*
53648diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
53649index 2d822aa..a566234 100644
53650--- a/drivers/tty/tty_ldisc.c
53651+++ b/drivers/tty/tty_ldisc.c
53652@@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
53653 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53654 tty_ldiscs[disc] = new_ldisc;
53655 new_ldisc->num = disc;
53656- new_ldisc->refcount = 0;
53657+ atomic_set(&new_ldisc->refcount, 0);
53658 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
53659
53660 return ret;
53661@@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
53662 return -EINVAL;
53663
53664 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53665- if (tty_ldiscs[disc]->refcount)
53666+ if (atomic_read(&tty_ldiscs[disc]->refcount))
53667 ret = -EBUSY;
53668 else
53669 tty_ldiscs[disc] = NULL;
53670@@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
53671 if (ldops) {
53672 ret = ERR_PTR(-EAGAIN);
53673 if (try_module_get(ldops->owner)) {
53674- ldops->refcount++;
53675+ atomic_inc(&ldops->refcount);
53676 ret = ldops;
53677 }
53678 }
53679@@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
53680 unsigned long flags;
53681
53682 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
53683- ldops->refcount--;
53684+ atomic_dec(&ldops->refcount);
53685 module_put(ldops->owner);
53686 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
53687 }
53688diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
53689index 1b93357..ea9f82c 100644
53690--- a/drivers/tty/tty_port.c
53691+++ b/drivers/tty/tty_port.c
53692@@ -237,7 +237,7 @@ void tty_port_hangup(struct tty_port *port)
53693 unsigned long flags;
53694
53695 spin_lock_irqsave(&port->lock, flags);
53696- port->count = 0;
53697+ atomic_set(&port->count, 0);
53698 port->flags &= ~ASYNC_NORMAL_ACTIVE;
53699 tty = port->tty;
53700 if (tty)
53701@@ -399,7 +399,7 @@ int tty_port_block_til_ready(struct tty_port *port,
53702
53703 /* The port lock protects the port counts */
53704 spin_lock_irqsave(&port->lock, flags);
53705- port->count--;
53706+ atomic_dec(&port->count);
53707 port->blocked_open++;
53708 spin_unlock_irqrestore(&port->lock, flags);
53709
53710@@ -441,7 +441,7 @@ int tty_port_block_til_ready(struct tty_port *port,
53711 we must not mess that up further */
53712 spin_lock_irqsave(&port->lock, flags);
53713 if (!tty_hung_up_p(filp))
53714- port->count++;
53715+ atomic_inc(&port->count);
53716 port->blocked_open--;
53717 if (retval == 0)
53718 port->flags |= ASYNC_NORMAL_ACTIVE;
53719@@ -479,19 +479,19 @@ int tty_port_close_start(struct tty_port *port,
53720 return 0;
53721 }
53722
53723- if (tty->count == 1 && port->count != 1) {
53724+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
53725 printk(KERN_WARNING
53726 "tty_port_close_start: tty->count = 1 port count = %d.\n",
53727- port->count);
53728- port->count = 1;
53729+ atomic_read(&port->count));
53730+ atomic_set(&port->count, 1);
53731 }
53732- if (--port->count < 0) {
53733+ if (atomic_dec_return(&port->count) < 0) {
53734 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
53735- port->count);
53736- port->count = 0;
53737+ atomic_read(&port->count));
53738+ atomic_set(&port->count, 0);
53739 }
53740
53741- if (port->count) {
53742+ if (atomic_read(&port->count)) {
53743 spin_unlock_irqrestore(&port->lock, flags);
53744 return 0;
53745 }
53746@@ -592,7 +592,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
53747 struct file *filp)
53748 {
53749 spin_lock_irq(&port->lock);
53750- ++port->count;
53751+ atomic_inc(&port->count);
53752 spin_unlock_irq(&port->lock);
53753 tty_port_tty_set(port, tty);
53754
53755diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
53756index c039cfe..0b463b0 100644
53757--- a/drivers/tty/vt/keyboard.c
53758+++ b/drivers/tty/vt/keyboard.c
53759@@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
53760 kbd->kbdmode == VC_OFF) &&
53761 value != KVAL(K_SAK))
53762 return; /* SAK is allowed even in raw mode */
53763+
53764+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
53765+ {
53766+ void *func = fn_handler[value];
53767+ if (func == fn_show_state || func == fn_show_ptregs ||
53768+ func == fn_show_mem)
53769+ return;
53770+ }
53771+#endif
53772+
53773 fn_handler[value](vc);
53774 }
53775
53776@@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
53777 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
53778 return -EFAULT;
53779
53780- if (!capable(CAP_SYS_TTY_CONFIG))
53781- perm = 0;
53782-
53783 switch (cmd) {
53784 case KDGKBENT:
53785 /* Ensure another thread doesn't free it under us */
53786@@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
53787 spin_unlock_irqrestore(&kbd_event_lock, flags);
53788 return put_user(val, &user_kbe->kb_value);
53789 case KDSKBENT:
53790+ if (!capable(CAP_SYS_TTY_CONFIG))
53791+ perm = 0;
53792+
53793 if (!perm)
53794 return -EPERM;
53795 if (!i && v == K_NOSUCHMAP) {
53796@@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
53797 int i, j, k;
53798 int ret;
53799
53800- if (!capable(CAP_SYS_TTY_CONFIG))
53801- perm = 0;
53802-
53803 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
53804 if (!kbs) {
53805 ret = -ENOMEM;
53806@@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
53807 kfree(kbs);
53808 return ((p && *p) ? -EOVERFLOW : 0);
53809 case KDSKBSENT:
53810+ if (!capable(CAP_SYS_TTY_CONFIG))
53811+ perm = 0;
53812+
53813 if (!perm) {
53814 ret = -EPERM;
53815 goto reterr;
53816diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
53817index 60fa627..7214965 100644
53818--- a/drivers/uio/uio.c
53819+++ b/drivers/uio/uio.c
53820@@ -25,6 +25,7 @@
53821 #include <linux/kobject.h>
53822 #include <linux/cdev.h>
53823 #include <linux/uio_driver.h>
53824+#include <asm/local.h>
53825
53826 #define UIO_MAX_DEVICES (1U << MINORBITS)
53827
53828@@ -231,7 +232,7 @@ static ssize_t event_show(struct device *dev,
53829 struct device_attribute *attr, char *buf)
53830 {
53831 struct uio_device *idev = dev_get_drvdata(dev);
53832- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
53833+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
53834 }
53835 static DEVICE_ATTR_RO(event);
53836
53837@@ -393,7 +394,7 @@ void uio_event_notify(struct uio_info *info)
53838 {
53839 struct uio_device *idev = info->uio_dev;
53840
53841- atomic_inc(&idev->event);
53842+ atomic_inc_unchecked(&idev->event);
53843 wake_up_interruptible(&idev->wait);
53844 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
53845 }
53846@@ -446,7 +447,7 @@ static int uio_open(struct inode *inode, struct file *filep)
53847 }
53848
53849 listener->dev = idev;
53850- listener->event_count = atomic_read(&idev->event);
53851+ listener->event_count = atomic_read_unchecked(&idev->event);
53852 filep->private_data = listener;
53853
53854 if (idev->info->open) {
53855@@ -497,7 +498,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
53856 return -EIO;
53857
53858 poll_wait(filep, &idev->wait, wait);
53859- if (listener->event_count != atomic_read(&idev->event))
53860+ if (listener->event_count != atomic_read_unchecked(&idev->event))
53861 return POLLIN | POLLRDNORM;
53862 return 0;
53863 }
53864@@ -522,7 +523,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
53865 do {
53866 set_current_state(TASK_INTERRUPTIBLE);
53867
53868- event_count = atomic_read(&idev->event);
53869+ event_count = atomic_read_unchecked(&idev->event);
53870 if (event_count != listener->event_count) {
53871 if (copy_to_user(buf, &event_count, count))
53872 retval = -EFAULT;
53873@@ -579,9 +580,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
53874 static int uio_find_mem_index(struct vm_area_struct *vma)
53875 {
53876 struct uio_device *idev = vma->vm_private_data;
53877+ unsigned long size;
53878
53879 if (vma->vm_pgoff < MAX_UIO_MAPS) {
53880- if (idev->info->mem[vma->vm_pgoff].size == 0)
53881+ size = idev->info->mem[vma->vm_pgoff].size;
53882+ if (size == 0)
53883+ return -1;
53884+ if (vma->vm_end - vma->vm_start > size)
53885 return -1;
53886 return (int)vma->vm_pgoff;
53887 }
53888@@ -813,7 +818,7 @@ int __uio_register_device(struct module *owner,
53889 idev->owner = owner;
53890 idev->info = info;
53891 init_waitqueue_head(&idev->wait);
53892- atomic_set(&idev->event, 0);
53893+ atomic_set_unchecked(&idev->event, 0);
53894
53895 ret = uio_get_minor(idev);
53896 if (ret)
53897diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
53898index 813d4d3..a71934f 100644
53899--- a/drivers/usb/atm/cxacru.c
53900+++ b/drivers/usb/atm/cxacru.c
53901@@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
53902 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
53903 if (ret < 2)
53904 return -EINVAL;
53905- if (index < 0 || index > 0x7f)
53906+ if (index > 0x7f)
53907 return -EINVAL;
53908 pos += tmp;
53909
53910diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
53911index dada014..1d0d517 100644
53912--- a/drivers/usb/atm/usbatm.c
53913+++ b/drivers/usb/atm/usbatm.c
53914@@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
53915 if (printk_ratelimit())
53916 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
53917 __func__, vpi, vci);
53918- atomic_inc(&vcc->stats->rx_err);
53919+ atomic_inc_unchecked(&vcc->stats->rx_err);
53920 return;
53921 }
53922
53923@@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
53924 if (length > ATM_MAX_AAL5_PDU) {
53925 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
53926 __func__, length, vcc);
53927- atomic_inc(&vcc->stats->rx_err);
53928+ atomic_inc_unchecked(&vcc->stats->rx_err);
53929 goto out;
53930 }
53931
53932@@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
53933 if (sarb->len < pdu_length) {
53934 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
53935 __func__, pdu_length, sarb->len, vcc);
53936- atomic_inc(&vcc->stats->rx_err);
53937+ atomic_inc_unchecked(&vcc->stats->rx_err);
53938 goto out;
53939 }
53940
53941 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
53942 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
53943 __func__, vcc);
53944- atomic_inc(&vcc->stats->rx_err);
53945+ atomic_inc_unchecked(&vcc->stats->rx_err);
53946 goto out;
53947 }
53948
53949@@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
53950 if (printk_ratelimit())
53951 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
53952 __func__, length);
53953- atomic_inc(&vcc->stats->rx_drop);
53954+ atomic_inc_unchecked(&vcc->stats->rx_drop);
53955 goto out;
53956 }
53957
53958@@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
53959
53960 vcc->push(vcc, skb);
53961
53962- atomic_inc(&vcc->stats->rx);
53963+ atomic_inc_unchecked(&vcc->stats->rx);
53964 out:
53965 skb_trim(sarb, 0);
53966 }
53967@@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
53968 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
53969
53970 usbatm_pop(vcc, skb);
53971- atomic_inc(&vcc->stats->tx);
53972+ atomic_inc_unchecked(&vcc->stats->tx);
53973
53974 skb = skb_dequeue(&instance->sndqueue);
53975 }
53976@@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
53977 if (!left--)
53978 return sprintf(page,
53979 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
53980- atomic_read(&atm_dev->stats.aal5.tx),
53981- atomic_read(&atm_dev->stats.aal5.tx_err),
53982- atomic_read(&atm_dev->stats.aal5.rx),
53983- atomic_read(&atm_dev->stats.aal5.rx_err),
53984- atomic_read(&atm_dev->stats.aal5.rx_drop));
53985+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
53986+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
53987+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
53988+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
53989+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
53990
53991 if (!left--) {
53992 if (instance->disconnected)
53993diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
53994index 2a3bbdf..91d72cf 100644
53995--- a/drivers/usb/core/devices.c
53996+++ b/drivers/usb/core/devices.c
53997@@ -126,7 +126,7 @@ static const char format_endpt[] =
53998 * time it gets called.
53999 */
54000 static struct device_connect_event {
54001- atomic_t count;
54002+ atomic_unchecked_t count;
54003 wait_queue_head_t wait;
54004 } device_event = {
54005 .count = ATOMIC_INIT(1),
54006@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
54007
54008 void usbfs_conn_disc_event(void)
54009 {
54010- atomic_add(2, &device_event.count);
54011+ atomic_add_unchecked(2, &device_event.count);
54012 wake_up(&device_event.wait);
54013 }
54014
54015@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
54016
54017 poll_wait(file, &device_event.wait, wait);
54018
54019- event_count = atomic_read(&device_event.count);
54020+ event_count = atomic_read_unchecked(&device_event.count);
54021 if (file->f_version != event_count) {
54022 file->f_version = event_count;
54023 return POLLIN | POLLRDNORM;
54024diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
54025index 0b59731..46ee7d1 100644
54026--- a/drivers/usb/core/devio.c
54027+++ b/drivers/usb/core/devio.c
54028@@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
54029 struct usb_dev_state *ps = file->private_data;
54030 struct usb_device *dev = ps->dev;
54031 ssize_t ret = 0;
54032- unsigned len;
54033+ size_t len;
54034 loff_t pos;
54035 int i;
54036
54037@@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
54038 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
54039 struct usb_config_descriptor *config =
54040 (struct usb_config_descriptor *)dev->rawdescriptors[i];
54041- unsigned int length = le16_to_cpu(config->wTotalLength);
54042+ size_t length = le16_to_cpu(config->wTotalLength);
54043
54044 if (*ppos < pos + length) {
54045
54046 /* The descriptor may claim to be longer than it
54047 * really is. Here is the actual allocated length. */
54048- unsigned alloclen =
54049+ size_t alloclen =
54050 le16_to_cpu(dev->config[i].desc.wTotalLength);
54051
54052- len = length - (*ppos - pos);
54053+ len = length + pos - *ppos;
54054 if (len > nbytes)
54055 len = nbytes;
54056
54057 /* Simply don't write (skip over) unallocated parts */
54058 if (alloclen > (*ppos - pos)) {
54059- alloclen -= (*ppos - pos);
54060+ alloclen = alloclen + pos - *ppos;
54061 if (copy_to_user(buf,
54062 dev->rawdescriptors[i] + (*ppos - pos),
54063 min(len, alloclen))) {
54064diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
54065index a6efb41..6f72549b 100644
54066--- a/drivers/usb/core/hcd.c
54067+++ b/drivers/usb/core/hcd.c
54068@@ -1551,7 +1551,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
54069 */
54070 usb_get_urb(urb);
54071 atomic_inc(&urb->use_count);
54072- atomic_inc(&urb->dev->urbnum);
54073+ atomic_inc_unchecked(&urb->dev->urbnum);
54074 usbmon_urb_submit(&hcd->self, urb);
54075
54076 /* NOTE requirements on root-hub callers (usbfs and the hub
54077@@ -1578,7 +1578,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
54078 urb->hcpriv = NULL;
54079 INIT_LIST_HEAD(&urb->urb_list);
54080 atomic_dec(&urb->use_count);
54081- atomic_dec(&urb->dev->urbnum);
54082+ atomic_dec_unchecked(&urb->dev->urbnum);
54083 if (atomic_read(&urb->reject))
54084 wake_up(&usb_kill_urb_queue);
54085 usb_put_urb(urb);
54086diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
54087index b649fef..c7107a0 100644
54088--- a/drivers/usb/core/hub.c
54089+++ b/drivers/usb/core/hub.c
54090@@ -26,6 +26,7 @@
54091 #include <linux/mutex.h>
54092 #include <linux/random.h>
54093 #include <linux/pm_qos.h>
54094+#include <linux/grsecurity.h>
54095
54096 #include <asm/uaccess.h>
54097 #include <asm/byteorder.h>
54098@@ -4666,6 +4667,10 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
54099 goto done;
54100 return;
54101 }
54102+
54103+ if (gr_handle_new_usb())
54104+ goto done;
54105+
54106 if (hub_is_superspeed(hub->hdev))
54107 unit_load = 150;
54108 else
54109diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
54110index f7b7713..23d07ec 100644
54111--- a/drivers/usb/core/message.c
54112+++ b/drivers/usb/core/message.c
54113@@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
54114 * Return: If successful, the number of bytes transferred. Otherwise, a negative
54115 * error number.
54116 */
54117-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
54118+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
54119 __u8 requesttype, __u16 value, __u16 index, void *data,
54120 __u16 size, int timeout)
54121 {
54122@@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
54123 * If successful, 0. Otherwise a negative error number. The number of actual
54124 * bytes transferred will be stored in the @actual_length parameter.
54125 */
54126-int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
54127+int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
54128 void *data, int len, int *actual_length, int timeout)
54129 {
54130 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
54131@@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
54132 * bytes transferred will be stored in the @actual_length parameter.
54133 *
54134 */
54135-int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
54136+int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
54137 void *data, int len, int *actual_length, int timeout)
54138 {
54139 struct urb *urb;
54140diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
54141index 1236c60..d47a51c 100644
54142--- a/drivers/usb/core/sysfs.c
54143+++ b/drivers/usb/core/sysfs.c
54144@@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
54145 struct usb_device *udev;
54146
54147 udev = to_usb_device(dev);
54148- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
54149+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
54150 }
54151 static DEVICE_ATTR_RO(urbnum);
54152
54153diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
54154index 2dd2362..1135437 100644
54155--- a/drivers/usb/core/usb.c
54156+++ b/drivers/usb/core/usb.c
54157@@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
54158 set_dev_node(&dev->dev, dev_to_node(bus->controller));
54159 dev->state = USB_STATE_ATTACHED;
54160 dev->lpm_disable_count = 1;
54161- atomic_set(&dev->urbnum, 0);
54162+ atomic_set_unchecked(&dev->urbnum, 0);
54163
54164 INIT_LIST_HEAD(&dev->ep0.urb_list);
54165 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
54166diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
54167index 8cfc319..4868255 100644
54168--- a/drivers/usb/early/ehci-dbgp.c
54169+++ b/drivers/usb/early/ehci-dbgp.c
54170@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
54171
54172 #ifdef CONFIG_KGDB
54173 static struct kgdb_io kgdbdbgp_io_ops;
54174-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
54175+static struct kgdb_io kgdbdbgp_io_ops_console;
54176+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
54177 #else
54178 #define dbgp_kgdb_mode (0)
54179 #endif
54180@@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
54181 .write_char = kgdbdbgp_write_char,
54182 };
54183
54184+static struct kgdb_io kgdbdbgp_io_ops_console = {
54185+ .name = "kgdbdbgp",
54186+ .read_char = kgdbdbgp_read_char,
54187+ .write_char = kgdbdbgp_write_char,
54188+ .is_console = 1
54189+};
54190+
54191 static int kgdbdbgp_wait_time;
54192
54193 static int __init kgdbdbgp_parse_config(char *str)
54194@@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
54195 ptr++;
54196 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
54197 }
54198- kgdb_register_io_module(&kgdbdbgp_io_ops);
54199- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
54200+ if (early_dbgp_console.index != -1)
54201+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
54202+ else
54203+ kgdb_register_io_module(&kgdbdbgp_io_ops);
54204
54205 return 0;
54206 }
54207diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c
54208index f7b2032..fbb340c 100644
54209--- a/drivers/usb/gadget/function/f_uac1.c
54210+++ b/drivers/usb/gadget/function/f_uac1.c
54211@@ -14,6 +14,7 @@
54212 #include <linux/module.h>
54213 #include <linux/device.h>
54214 #include <linux/atomic.h>
54215+#include <linux/module.h>
54216
54217 #include "u_uac1.h"
54218
54219diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
54220index 491082a..dfd7d17 100644
54221--- a/drivers/usb/gadget/function/u_serial.c
54222+++ b/drivers/usb/gadget/function/u_serial.c
54223@@ -729,9 +729,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
54224 spin_lock_irq(&port->port_lock);
54225
54226 /* already open? Great. */
54227- if (port->port.count) {
54228+ if (atomic_read(&port->port.count)) {
54229 status = 0;
54230- port->port.count++;
54231+ atomic_inc(&port->port.count);
54232
54233 /* currently opening/closing? wait ... */
54234 } else if (port->openclose) {
54235@@ -790,7 +790,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
54236 tty->driver_data = port;
54237 port->port.tty = tty;
54238
54239- port->port.count = 1;
54240+ atomic_set(&port->port.count, 1);
54241 port->openclose = false;
54242
54243 /* if connected, start the I/O stream */
54244@@ -832,11 +832,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
54245
54246 spin_lock_irq(&port->port_lock);
54247
54248- if (port->port.count != 1) {
54249- if (port->port.count == 0)
54250+ if (atomic_read(&port->port.count) != 1) {
54251+ if (atomic_read(&port->port.count) == 0)
54252 WARN_ON(1);
54253 else
54254- --port->port.count;
54255+ atomic_dec(&port->port.count);
54256 goto exit;
54257 }
54258
54259@@ -846,7 +846,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
54260 * and sleep if necessary
54261 */
54262 port->openclose = true;
54263- port->port.count = 0;
54264+ atomic_set(&port->port.count, 0);
54265
54266 gser = port->port_usb;
54267 if (gser && gser->disconnect)
54268@@ -1062,7 +1062,7 @@ static int gs_closed(struct gs_port *port)
54269 int cond;
54270
54271 spin_lock_irq(&port->port_lock);
54272- cond = (port->port.count == 0) && !port->openclose;
54273+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
54274 spin_unlock_irq(&port->port_lock);
54275 return cond;
54276 }
54277@@ -1205,7 +1205,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
54278 /* if it's already open, start I/O ... and notify the serial
54279 * protocol about open/close status (connect/disconnect).
54280 */
54281- if (port->port.count) {
54282+ if (atomic_read(&port->port.count)) {
54283 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
54284 gs_start_io(port);
54285 if (gser->connect)
54286@@ -1252,7 +1252,7 @@ void gserial_disconnect(struct gserial *gser)
54287
54288 port->port_usb = NULL;
54289 gser->ioport = NULL;
54290- if (port->port.count > 0 || port->openclose) {
54291+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
54292 wake_up_interruptible(&port->drain_wait);
54293 if (port->port.tty)
54294 tty_hangup(port->port.tty);
54295@@ -1268,7 +1268,7 @@ void gserial_disconnect(struct gserial *gser)
54296
54297 /* finally, free any unused/unusable I/O buffers */
54298 spin_lock_irqsave(&port->port_lock, flags);
54299- if (port->port.count == 0 && !port->openclose)
54300+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
54301 gs_buf_free(&port->port_write_buf);
54302 gs_free_requests(gser->out, &port->read_pool, NULL);
54303 gs_free_requests(gser->out, &port->read_queue, NULL);
54304diff --git a/drivers/usb/gadget/function/u_uac1.c b/drivers/usb/gadget/function/u_uac1.c
54305index a44a07f..ecea924 100644
54306--- a/drivers/usb/gadget/function/u_uac1.c
54307+++ b/drivers/usb/gadget/function/u_uac1.c
54308@@ -17,6 +17,7 @@
54309 #include <linux/ctype.h>
54310 #include <linux/random.h>
54311 #include <linux/syscalls.h>
54312+#include <linux/module.h>
54313
54314 #include "u_uac1.h"
54315
54316diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
54317index 5728829..fefc6bf 100644
54318--- a/drivers/usb/host/ehci-hub.c
54319+++ b/drivers/usb/host/ehci-hub.c
54320@@ -771,7 +771,7 @@ static struct urb *request_single_step_set_feature_urb(
54321 urb->transfer_flags = URB_DIR_IN;
54322 usb_get_urb(urb);
54323 atomic_inc(&urb->use_count);
54324- atomic_inc(&urb->dev->urbnum);
54325+ atomic_inc_unchecked(&urb->dev->urbnum);
54326 urb->setup_dma = dma_map_single(
54327 hcd->self.controller,
54328 urb->setup_packet,
54329@@ -838,7 +838,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
54330 urb->status = -EINPROGRESS;
54331 usb_get_urb(urb);
54332 atomic_inc(&urb->use_count);
54333- atomic_inc(&urb->dev->urbnum);
54334+ atomic_inc_unchecked(&urb->dev->urbnum);
54335 retval = submit_single_step_set_feature(hcd, urb, 0);
54336 if (!retval && !wait_for_completion_timeout(&done,
54337 msecs_to_jiffies(2000))) {
54338diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
54339index 1db0626..4948782 100644
54340--- a/drivers/usb/host/hwa-hc.c
54341+++ b/drivers/usb/host/hwa-hc.c
54342@@ -337,7 +337,10 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
54343 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
54344 struct wahc *wa = &hwahc->wa;
54345 struct device *dev = &wa->usb_iface->dev;
54346- u8 mas_le[UWB_NUM_MAS/8];
54347+ u8 *mas_le = kmalloc(UWB_NUM_MAS/8, GFP_KERNEL);
54348+
54349+ if (mas_le == NULL)
54350+ return -ENOMEM;
54351
54352 /* Set the stream index */
54353 result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
54354@@ -356,10 +359,12 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
54355 WUSB_REQ_SET_WUSB_MAS,
54356 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
54357 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber,
54358- mas_le, 32, USB_CTRL_SET_TIMEOUT);
54359+ mas_le, UWB_NUM_MAS/8, USB_CTRL_SET_TIMEOUT);
54360 if (result < 0)
54361 dev_err(dev, "Cannot set WUSB MAS allocation: %d\n", result);
54362 out:
54363+ kfree(mas_le);
54364+
54365 return result;
54366 }
54367
54368diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
54369index b3d245e..99549ed 100644
54370--- a/drivers/usb/misc/appledisplay.c
54371+++ b/drivers/usb/misc/appledisplay.c
54372@@ -84,7 +84,7 @@ struct appledisplay {
54373 struct mutex sysfslock; /* concurrent read and write */
54374 };
54375
54376-static atomic_t count_displays = ATOMIC_INIT(0);
54377+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
54378 static struct workqueue_struct *wq;
54379
54380 static void appledisplay_complete(struct urb *urb)
54381@@ -288,7 +288,7 @@ static int appledisplay_probe(struct usb_interface *iface,
54382
54383 /* Register backlight device */
54384 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
54385- atomic_inc_return(&count_displays) - 1);
54386+ atomic_inc_return_unchecked(&count_displays) - 1);
54387 memset(&props, 0, sizeof(struct backlight_properties));
54388 props.type = BACKLIGHT_RAW;
54389 props.max_brightness = 0xff;
54390diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
54391index 8d7fc48..01c4986 100644
54392--- a/drivers/usb/serial/console.c
54393+++ b/drivers/usb/serial/console.c
54394@@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
54395
54396 info->port = port;
54397
54398- ++port->port.count;
54399+ atomic_inc(&port->port.count);
54400 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
54401 if (serial->type->set_termios) {
54402 /*
54403@@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
54404 }
54405 /* Now that any required fake tty operations are completed restore
54406 * the tty port count */
54407- --port->port.count;
54408+ atomic_dec(&port->port.count);
54409 /* The console is special in terms of closing the device so
54410 * indicate this port is now acting as a system console. */
54411 port->port.console = 1;
54412@@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
54413 free_tty:
54414 kfree(tty);
54415 reset_open_count:
54416- port->port.count = 0;
54417+ atomic_set(&port->port.count, 0);
54418 usb_autopm_put_interface(serial->interface);
54419 error_get_interface:
54420 usb_serial_put(serial);
54421@@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
54422 static void usb_console_write(struct console *co,
54423 const char *buf, unsigned count)
54424 {
54425- static struct usbcons_info *info = &usbcons_info;
54426+ struct usbcons_info *info = &usbcons_info;
54427 struct usb_serial_port *port = info->port;
54428 struct usb_serial *serial;
54429 int retval = -ENODEV;
54430diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
54431index 307e339..6aa97cb 100644
54432--- a/drivers/usb/storage/usb.h
54433+++ b/drivers/usb/storage/usb.h
54434@@ -63,7 +63,7 @@ struct us_unusual_dev {
54435 __u8 useProtocol;
54436 __u8 useTransport;
54437 int (*initFunction)(struct us_data *);
54438-};
54439+} __do_const;
54440
54441
54442 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
54443diff --git a/drivers/usb/usbip/vhci.h b/drivers/usb/usbip/vhci.h
54444index a863a98..d272795 100644
54445--- a/drivers/usb/usbip/vhci.h
54446+++ b/drivers/usb/usbip/vhci.h
54447@@ -83,7 +83,7 @@ struct vhci_hcd {
54448 unsigned resuming:1;
54449 unsigned long re_timeout;
54450
54451- atomic_t seqnum;
54452+ atomic_unchecked_t seqnum;
54453
54454 /*
54455 * NOTE:
54456diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
54457index c02374b..32d47a9 100644
54458--- a/drivers/usb/usbip/vhci_hcd.c
54459+++ b/drivers/usb/usbip/vhci_hcd.c
54460@@ -439,7 +439,7 @@ static void vhci_tx_urb(struct urb *urb)
54461
54462 spin_lock(&vdev->priv_lock);
54463
54464- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
54465+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
54466 if (priv->seqnum == 0xffff)
54467 dev_info(&urb->dev->dev, "seqnum max\n");
54468
54469@@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
54470 return -ENOMEM;
54471 }
54472
54473- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
54474+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
54475 if (unlink->seqnum == 0xffff)
54476 pr_info("seqnum max\n");
54477
54478@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
54479 vdev->rhport = rhport;
54480 }
54481
54482- atomic_set(&vhci->seqnum, 0);
54483+ atomic_set_unchecked(&vhci->seqnum, 0);
54484 spin_lock_init(&vhci->lock);
54485
54486 hcd->power_budget = 0; /* no limit */
54487diff --git a/drivers/usb/usbip/vhci_rx.c b/drivers/usb/usbip/vhci_rx.c
54488index 00e4a54..d676f85 100644
54489--- a/drivers/usb/usbip/vhci_rx.c
54490+++ b/drivers/usb/usbip/vhci_rx.c
54491@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
54492 if (!urb) {
54493 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
54494 pr_info("max seqnum %d\n",
54495- atomic_read(&the_controller->seqnum));
54496+ atomic_read_unchecked(&the_controller->seqnum));
54497 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
54498 return;
54499 }
54500diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
54501index edc7267..9f65ce2 100644
54502--- a/drivers/usb/wusbcore/wa-hc.h
54503+++ b/drivers/usb/wusbcore/wa-hc.h
54504@@ -240,7 +240,7 @@ struct wahc {
54505 spinlock_t xfer_list_lock;
54506 struct work_struct xfer_enqueue_work;
54507 struct work_struct xfer_error_work;
54508- atomic_t xfer_id_count;
54509+ atomic_unchecked_t xfer_id_count;
54510
54511 kernel_ulong_t quirks;
54512 };
54513@@ -305,7 +305,7 @@ static inline void wa_init(struct wahc *wa)
54514 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
54515 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
54516 wa->dto_in_use = 0;
54517- atomic_set(&wa->xfer_id_count, 1);
54518+ atomic_set_unchecked(&wa->xfer_id_count, 1);
54519 /* init the buf in URBs */
54520 for (index = 0; index < WA_MAX_BUF_IN_URBS; ++index)
54521 usb_init_urb(&(wa->buf_in_urbs[index]));
54522diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
54523index 69af4fd..da390d7 100644
54524--- a/drivers/usb/wusbcore/wa-xfer.c
54525+++ b/drivers/usb/wusbcore/wa-xfer.c
54526@@ -314,7 +314,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
54527 */
54528 static void wa_xfer_id_init(struct wa_xfer *xfer)
54529 {
54530- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
54531+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
54532 }
54533
54534 /* Return the xfer's ID. */
54535diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
54536index f018d8d..ccab63f 100644
54537--- a/drivers/vfio/vfio.c
54538+++ b/drivers/vfio/vfio.c
54539@@ -481,7 +481,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
54540 return 0;
54541
54542 /* TODO Prevent device auto probing */
54543- WARN("Device %s added to live group %d!\n", dev_name(dev),
54544+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
54545 iommu_group_id(group->iommu_group));
54546
54547 return 0;
54548diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
54549index 5174eba..451e6bc 100644
54550--- a/drivers/vhost/vringh.c
54551+++ b/drivers/vhost/vringh.c
54552@@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
54553 /* Userspace access helpers: in this case, addresses are really userspace. */
54554 static inline int getu16_user(u16 *val, const u16 *p)
54555 {
54556- return get_user(*val, (__force u16 __user *)p);
54557+ return get_user(*val, (u16 __force_user *)p);
54558 }
54559
54560 static inline int putu16_user(u16 *p, u16 val)
54561 {
54562- return put_user(val, (__force u16 __user *)p);
54563+ return put_user(val, (u16 __force_user *)p);
54564 }
54565
54566 static inline int copydesc_user(void *dst, const void *src, size_t len)
54567 {
54568- return copy_from_user(dst, (__force void __user *)src, len) ?
54569+ return copy_from_user(dst, (void __force_user *)src, len) ?
54570 -EFAULT : 0;
54571 }
54572
54573@@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
54574 const struct vring_used_elem *src,
54575 unsigned int num)
54576 {
54577- return copy_to_user((__force void __user *)dst, src,
54578+ return copy_to_user((void __force_user *)dst, src,
54579 sizeof(*dst) * num) ? -EFAULT : 0;
54580 }
54581
54582 static inline int xfer_from_user(void *src, void *dst, size_t len)
54583 {
54584- return copy_from_user(dst, (__force void __user *)src, len) ?
54585+ return copy_from_user(dst, (void __force_user *)src, len) ?
54586 -EFAULT : 0;
54587 }
54588
54589 static inline int xfer_to_user(void *dst, void *src, size_t len)
54590 {
54591- return copy_to_user((__force void __user *)dst, src, len) ?
54592+ return copy_to_user((void __force_user *)dst, src, len) ?
54593 -EFAULT : 0;
54594 }
54595
54596@@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
54597 vrh->last_used_idx = 0;
54598 vrh->vring.num = num;
54599 /* vring expects kernel addresses, but only used via accessors. */
54600- vrh->vring.desc = (__force struct vring_desc *)desc;
54601- vrh->vring.avail = (__force struct vring_avail *)avail;
54602- vrh->vring.used = (__force struct vring_used *)used;
54603+ vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
54604+ vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
54605+ vrh->vring.used = (__force_kernel struct vring_used *)used;
54606 return 0;
54607 }
54608 EXPORT_SYMBOL(vringh_init_user);
54609@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
54610
54611 static inline int putu16_kern(u16 *p, u16 val)
54612 {
54613- ACCESS_ONCE(*p) = val;
54614+ ACCESS_ONCE_RW(*p) = val;
54615 return 0;
54616 }
54617
54618diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
54619index 84a110a..96312c3 100644
54620--- a/drivers/video/backlight/kb3886_bl.c
54621+++ b/drivers/video/backlight/kb3886_bl.c
54622@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
54623 static unsigned long kb3886bl_flags;
54624 #define KB3886BL_SUSPENDED 0x01
54625
54626-static struct dmi_system_id kb3886bl_device_table[] __initdata = {
54627+static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
54628 {
54629 .ident = "Sahara Touch-iT",
54630 .matches = {
54631diff --git a/drivers/video/fbdev/arcfb.c b/drivers/video/fbdev/arcfb.c
54632index 1b0b233..6f34c2c 100644
54633--- a/drivers/video/fbdev/arcfb.c
54634+++ b/drivers/video/fbdev/arcfb.c
54635@@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
54636 return -ENOSPC;
54637
54638 err = 0;
54639- if ((count + p) > fbmemlength) {
54640+ if (count > (fbmemlength - p)) {
54641 count = fbmemlength - p;
54642 err = -ENOSPC;
54643 }
54644diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
54645index aedf2fb..47c9aca 100644
54646--- a/drivers/video/fbdev/aty/aty128fb.c
54647+++ b/drivers/video/fbdev/aty/aty128fb.c
54648@@ -149,7 +149,7 @@ enum {
54649 };
54650
54651 /* Must match above enum */
54652-static char * const r128_family[] = {
54653+static const char * const r128_family[] = {
54654 "AGP",
54655 "PCI",
54656 "PRO AGP",
54657diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
54658index 37ec09b..98f8862 100644
54659--- a/drivers/video/fbdev/aty/atyfb_base.c
54660+++ b/drivers/video/fbdev/aty/atyfb_base.c
54661@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
54662 par->accel_flags = var->accel_flags; /* hack */
54663
54664 if (var->accel_flags) {
54665- info->fbops->fb_sync = atyfb_sync;
54666+ pax_open_kernel();
54667+ *(void **)&info->fbops->fb_sync = atyfb_sync;
54668+ pax_close_kernel();
54669 info->flags &= ~FBINFO_HWACCEL_DISABLED;
54670 } else {
54671- info->fbops->fb_sync = NULL;
54672+ pax_open_kernel();
54673+ *(void **)&info->fbops->fb_sync = NULL;
54674+ pax_close_kernel();
54675 info->flags |= FBINFO_HWACCEL_DISABLED;
54676 }
54677
54678diff --git a/drivers/video/fbdev/aty/mach64_cursor.c b/drivers/video/fbdev/aty/mach64_cursor.c
54679index 2fa0317..4983f2a 100644
54680--- a/drivers/video/fbdev/aty/mach64_cursor.c
54681+++ b/drivers/video/fbdev/aty/mach64_cursor.c
54682@@ -8,6 +8,7 @@
54683 #include "../core/fb_draw.h"
54684
54685 #include <asm/io.h>
54686+#include <asm/pgtable.h>
54687
54688 #ifdef __sparc__
54689 #include <asm/fbio.h>
54690@@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
54691 info->sprite.buf_align = 16; /* and 64 lines tall. */
54692 info->sprite.flags = FB_PIXMAP_IO;
54693
54694- info->fbops->fb_cursor = atyfb_cursor;
54695+ pax_open_kernel();
54696+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
54697+ pax_close_kernel();
54698
54699 return 0;
54700 }
54701diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
54702index 900aa4e..6d49418 100644
54703--- a/drivers/video/fbdev/core/fb_defio.c
54704+++ b/drivers/video/fbdev/core/fb_defio.c
54705@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
54706
54707 BUG_ON(!fbdefio);
54708 mutex_init(&fbdefio->lock);
54709- info->fbops->fb_mmap = fb_deferred_io_mmap;
54710+ pax_open_kernel();
54711+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
54712+ pax_close_kernel();
54713 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
54714 INIT_LIST_HEAD(&fbdefio->pagelist);
54715 if (fbdefio->delay == 0) /* set a default of 1 s */
54716@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
54717 page->mapping = NULL;
54718 }
54719
54720- info->fbops->fb_mmap = NULL;
54721+ *(void **)&info->fbops->fb_mmap = NULL;
54722 mutex_destroy(&fbdefio->lock);
54723 }
54724 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
54725diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
54726index 0705d88..d9429bf 100644
54727--- a/drivers/video/fbdev/core/fbmem.c
54728+++ b/drivers/video/fbdev/core/fbmem.c
54729@@ -1301,7 +1301,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
54730 __u32 data;
54731 int err;
54732
54733- err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
54734+ err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
54735
54736 data = (__u32) (unsigned long) fix->smem_start;
54737 err |= put_user(data, &fix32->smem_start);
54738diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
54739index 4254336..282567e 100644
54740--- a/drivers/video/fbdev/hyperv_fb.c
54741+++ b/drivers/video/fbdev/hyperv_fb.c
54742@@ -240,7 +240,7 @@ static uint screen_fb_size;
54743 static inline int synthvid_send(struct hv_device *hdev,
54744 struct synthvid_msg *msg)
54745 {
54746- static atomic64_t request_id = ATOMIC64_INIT(0);
54747+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
54748 int ret;
54749
54750 msg->pipe_hdr.type = PIPE_MSG_DATA;
54751@@ -248,7 +248,7 @@ static inline int synthvid_send(struct hv_device *hdev,
54752
54753 ret = vmbus_sendpacket(hdev->channel, msg,
54754 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
54755- atomic64_inc_return(&request_id),
54756+ atomic64_inc_return_unchecked(&request_id),
54757 VM_PKT_DATA_INBAND, 0);
54758
54759 if (ret)
54760diff --git a/drivers/video/fbdev/i810/i810_accel.c b/drivers/video/fbdev/i810/i810_accel.c
54761index 7672d2e..b56437f 100644
54762--- a/drivers/video/fbdev/i810/i810_accel.c
54763+++ b/drivers/video/fbdev/i810/i810_accel.c
54764@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
54765 }
54766 }
54767 printk("ringbuffer lockup!!!\n");
54768+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
54769 i810_report_error(mmio);
54770 par->dev_flags |= LOCKUP;
54771 info->pixmap.scan_align = 1;
54772diff --git a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
54773index a01147f..5d896f8 100644
54774--- a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
54775+++ b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
54776@@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
54777
54778 #ifdef CONFIG_FB_MATROX_MYSTIQUE
54779 struct matrox_switch matrox_mystique = {
54780- MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
54781+ .preinit = MGA1064_preinit,
54782+ .reset = MGA1064_reset,
54783+ .init = MGA1064_init,
54784+ .restore = MGA1064_restore,
54785 };
54786 EXPORT_SYMBOL(matrox_mystique);
54787 #endif
54788
54789 #ifdef CONFIG_FB_MATROX_G
54790 struct matrox_switch matrox_G100 = {
54791- MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
54792+ .preinit = MGAG100_preinit,
54793+ .reset = MGAG100_reset,
54794+ .init = MGAG100_init,
54795+ .restore = MGAG100_restore,
54796 };
54797 EXPORT_SYMBOL(matrox_G100);
54798 #endif
54799diff --git a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
54800index 195ad7c..09743fc 100644
54801--- a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
54802+++ b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
54803@@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
54804 }
54805
54806 struct matrox_switch matrox_millennium = {
54807- Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
54808+ .preinit = Ti3026_preinit,
54809+ .reset = Ti3026_reset,
54810+ .init = Ti3026_init,
54811+ .restore = Ti3026_restore
54812 };
54813 EXPORT_SYMBOL(matrox_millennium);
54814 #endif
54815diff --git a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
54816index fe92eed..106e085 100644
54817--- a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
54818+++ b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
54819@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
54820 struct mb862xxfb_par *par = info->par;
54821
54822 if (info->var.bits_per_pixel == 32) {
54823- info->fbops->fb_fillrect = cfb_fillrect;
54824- info->fbops->fb_copyarea = cfb_copyarea;
54825- info->fbops->fb_imageblit = cfb_imageblit;
54826+ pax_open_kernel();
54827+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
54828+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
54829+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
54830+ pax_close_kernel();
54831 } else {
54832 outreg(disp, GC_L0EM, 3);
54833- info->fbops->fb_fillrect = mb86290fb_fillrect;
54834- info->fbops->fb_copyarea = mb86290fb_copyarea;
54835- info->fbops->fb_imageblit = mb86290fb_imageblit;
54836+ pax_open_kernel();
54837+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
54838+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
54839+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
54840+ pax_close_kernel();
54841 }
54842 outreg(draw, GDC_REG_DRAW_BASE, 0);
54843 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
54844diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
54845index def0412..fed6529 100644
54846--- a/drivers/video/fbdev/nvidia/nvidia.c
54847+++ b/drivers/video/fbdev/nvidia/nvidia.c
54848@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
54849 info->fix.line_length = (info->var.xres_virtual *
54850 info->var.bits_per_pixel) >> 3;
54851 if (info->var.accel_flags) {
54852- info->fbops->fb_imageblit = nvidiafb_imageblit;
54853- info->fbops->fb_fillrect = nvidiafb_fillrect;
54854- info->fbops->fb_copyarea = nvidiafb_copyarea;
54855- info->fbops->fb_sync = nvidiafb_sync;
54856+ pax_open_kernel();
54857+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
54858+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
54859+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
54860+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
54861+ pax_close_kernel();
54862 info->pixmap.scan_align = 4;
54863 info->flags &= ~FBINFO_HWACCEL_DISABLED;
54864 info->flags |= FBINFO_READS_FAST;
54865 NVResetGraphics(info);
54866 } else {
54867- info->fbops->fb_imageblit = cfb_imageblit;
54868- info->fbops->fb_fillrect = cfb_fillrect;
54869- info->fbops->fb_copyarea = cfb_copyarea;
54870- info->fbops->fb_sync = NULL;
54871+ pax_open_kernel();
54872+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
54873+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
54874+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
54875+ *(void **)&info->fbops->fb_sync = NULL;
54876+ pax_close_kernel();
54877 info->pixmap.scan_align = 1;
54878 info->flags |= FBINFO_HWACCEL_DISABLED;
54879 info->flags &= ~FBINFO_READS_FAST;
54880@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
54881 info->pixmap.size = 8 * 1024;
54882 info->pixmap.flags = FB_PIXMAP_SYSTEM;
54883
54884- if (!hwcur)
54885- info->fbops->fb_cursor = NULL;
54886+ if (!hwcur) {
54887+ pax_open_kernel();
54888+ *(void **)&info->fbops->fb_cursor = NULL;
54889+ pax_close_kernel();
54890+ }
54891
54892 info->var.accel_flags = (!noaccel);
54893
54894diff --git a/drivers/video/fbdev/omap2/dss/display.c b/drivers/video/fbdev/omap2/dss/display.c
54895index 2412a0d..294215b 100644
54896--- a/drivers/video/fbdev/omap2/dss/display.c
54897+++ b/drivers/video/fbdev/omap2/dss/display.c
54898@@ -161,12 +161,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
54899 if (dssdev->name == NULL)
54900 dssdev->name = dssdev->alias;
54901
54902+ pax_open_kernel();
54903 if (drv && drv->get_resolution == NULL)
54904- drv->get_resolution = omapdss_default_get_resolution;
54905+ *(void **)&drv->get_resolution = omapdss_default_get_resolution;
54906 if (drv && drv->get_recommended_bpp == NULL)
54907- drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
54908+ *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
54909 if (drv && drv->get_timings == NULL)
54910- drv->get_timings = omapdss_default_get_timings;
54911+ *(void **)&drv->get_timings = omapdss_default_get_timings;
54912+ pax_close_kernel();
54913
54914 mutex_lock(&panel_list_mutex);
54915 list_add_tail(&dssdev->panel_list, &panel_list);
54916diff --git a/drivers/video/fbdev/s1d13xxxfb.c b/drivers/video/fbdev/s1d13xxxfb.c
54917index 83433cb..71e9b98 100644
54918--- a/drivers/video/fbdev/s1d13xxxfb.c
54919+++ b/drivers/video/fbdev/s1d13xxxfb.c
54920@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
54921
54922 switch(prod_id) {
54923 case S1D13506_PROD_ID: /* activate acceleration */
54924- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
54925- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
54926+ pax_open_kernel();
54927+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
54928+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
54929+ pax_close_kernel();
54930 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
54931 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
54932 break;
54933diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c
54934index 2bcc84a..29dd1ea 100644
54935--- a/drivers/video/fbdev/sh_mobile_lcdcfb.c
54936+++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c
54937@@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
54938 }
54939
54940 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
54941- lcdc_sys_write_index,
54942- lcdc_sys_write_data,
54943- lcdc_sys_read_data,
54944+ .write_index = lcdc_sys_write_index,
54945+ .write_data = lcdc_sys_write_data,
54946+ .read_data = lcdc_sys_read_data,
54947 };
54948
54949 static int sh_mobile_lcdc_sginit(struct fb_info *info,
54950diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c
54951index d513ed6..90b0de9 100644
54952--- a/drivers/video/fbdev/smscufx.c
54953+++ b/drivers/video/fbdev/smscufx.c
54954@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
54955 fb_deferred_io_cleanup(info);
54956 kfree(info->fbdefio);
54957 info->fbdefio = NULL;
54958- info->fbops->fb_mmap = ufx_ops_mmap;
54959+ pax_open_kernel();
54960+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
54961+ pax_close_kernel();
54962 }
54963
54964 pr_debug("released /dev/fb%d user=%d count=%d",
54965diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
54966index 046d51d..be564da 100644
54967--- a/drivers/video/fbdev/udlfb.c
54968+++ b/drivers/video/fbdev/udlfb.c
54969@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
54970 dlfb_urb_completion(urb);
54971
54972 error:
54973- atomic_add(bytes_sent, &dev->bytes_sent);
54974- atomic_add(bytes_identical, &dev->bytes_identical);
54975- atomic_add(width*height*2, &dev->bytes_rendered);
54976+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
54977+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
54978+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
54979 end_cycles = get_cycles();
54980- atomic_add(((unsigned int) ((end_cycles - start_cycles)
54981+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
54982 >> 10)), /* Kcycles */
54983 &dev->cpu_kcycles_used);
54984
54985@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
54986 dlfb_urb_completion(urb);
54987
54988 error:
54989- atomic_add(bytes_sent, &dev->bytes_sent);
54990- atomic_add(bytes_identical, &dev->bytes_identical);
54991- atomic_add(bytes_rendered, &dev->bytes_rendered);
54992+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
54993+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
54994+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
54995 end_cycles = get_cycles();
54996- atomic_add(((unsigned int) ((end_cycles - start_cycles)
54997+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
54998 >> 10)), /* Kcycles */
54999 &dev->cpu_kcycles_used);
55000 }
55001@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
55002 fb_deferred_io_cleanup(info);
55003 kfree(info->fbdefio);
55004 info->fbdefio = NULL;
55005- info->fbops->fb_mmap = dlfb_ops_mmap;
55006+ pax_open_kernel();
55007+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
55008+ pax_close_kernel();
55009 }
55010
55011 pr_warn("released /dev/fb%d user=%d count=%d\n",
55012@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
55013 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55014 struct dlfb_data *dev = fb_info->par;
55015 return snprintf(buf, PAGE_SIZE, "%u\n",
55016- atomic_read(&dev->bytes_rendered));
55017+ atomic_read_unchecked(&dev->bytes_rendered));
55018 }
55019
55020 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55021@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55022 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55023 struct dlfb_data *dev = fb_info->par;
55024 return snprintf(buf, PAGE_SIZE, "%u\n",
55025- atomic_read(&dev->bytes_identical));
55026+ atomic_read_unchecked(&dev->bytes_identical));
55027 }
55028
55029 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55030@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55031 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55032 struct dlfb_data *dev = fb_info->par;
55033 return snprintf(buf, PAGE_SIZE, "%u\n",
55034- atomic_read(&dev->bytes_sent));
55035+ atomic_read_unchecked(&dev->bytes_sent));
55036 }
55037
55038 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55039@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55040 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55041 struct dlfb_data *dev = fb_info->par;
55042 return snprintf(buf, PAGE_SIZE, "%u\n",
55043- atomic_read(&dev->cpu_kcycles_used));
55044+ atomic_read_unchecked(&dev->cpu_kcycles_used));
55045 }
55046
55047 static ssize_t edid_show(
55048@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
55049 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55050 struct dlfb_data *dev = fb_info->par;
55051
55052- atomic_set(&dev->bytes_rendered, 0);
55053- atomic_set(&dev->bytes_identical, 0);
55054- atomic_set(&dev->bytes_sent, 0);
55055- atomic_set(&dev->cpu_kcycles_used, 0);
55056+ atomic_set_unchecked(&dev->bytes_rendered, 0);
55057+ atomic_set_unchecked(&dev->bytes_identical, 0);
55058+ atomic_set_unchecked(&dev->bytes_sent, 0);
55059+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
55060
55061 return count;
55062 }
55063diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
55064index 509d452..7c9d2de 100644
55065--- a/drivers/video/fbdev/uvesafb.c
55066+++ b/drivers/video/fbdev/uvesafb.c
55067@@ -19,6 +19,7 @@
55068 #include <linux/io.h>
55069 #include <linux/mutex.h>
55070 #include <linux/slab.h>
55071+#include <linux/moduleloader.h>
55072 #include <video/edid.h>
55073 #include <video/uvesafb.h>
55074 #ifdef CONFIG_X86
55075@@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
55076 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
55077 par->pmi_setpal = par->ypan = 0;
55078 } else {
55079+
55080+#ifdef CONFIG_PAX_KERNEXEC
55081+#ifdef CONFIG_MODULES
55082+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
55083+#endif
55084+ if (!par->pmi_code) {
55085+ par->pmi_setpal = par->ypan = 0;
55086+ return 0;
55087+ }
55088+#endif
55089+
55090 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
55091 + task->t.regs.edi);
55092+
55093+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55094+ pax_open_kernel();
55095+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
55096+ pax_close_kernel();
55097+
55098+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
55099+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
55100+#else
55101 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
55102 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
55103+#endif
55104+
55105 printk(KERN_INFO "uvesafb: protected mode interface info at "
55106 "%04x:%04x\n",
55107 (u16)task->t.regs.es, (u16)task->t.regs.edi);
55108@@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
55109 par->ypan = ypan;
55110
55111 if (par->pmi_setpal || par->ypan) {
55112+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
55113 if (__supported_pte_mask & _PAGE_NX) {
55114 par->pmi_setpal = par->ypan = 0;
55115 printk(KERN_WARNING "uvesafb: NX protection is active, "
55116 "better not use the PMI.\n");
55117- } else {
55118+ } else
55119+#endif
55120 uvesafb_vbe_getpmi(task, par);
55121- }
55122 }
55123 #else
55124 /* The protected mode interface is not available on non-x86. */
55125@@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55126 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
55127
55128 /* Disable blanking if the user requested so. */
55129- if (!blank)
55130- info->fbops->fb_blank = NULL;
55131+ if (!blank) {
55132+ pax_open_kernel();
55133+ *(void **)&info->fbops->fb_blank = NULL;
55134+ pax_close_kernel();
55135+ }
55136
55137 /*
55138 * Find out how much IO memory is required for the mode with
55139@@ -1525,8 +1552,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55140 info->flags = FBINFO_FLAG_DEFAULT |
55141 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
55142
55143- if (!par->ypan)
55144- info->fbops->fb_pan_display = NULL;
55145+ if (!par->ypan) {
55146+ pax_open_kernel();
55147+ *(void **)&info->fbops->fb_pan_display = NULL;
55148+ pax_close_kernel();
55149+ }
55150 }
55151
55152 static void uvesafb_init_mtrr(struct fb_info *info)
55153@@ -1787,6 +1817,11 @@ out_mode:
55154 out:
55155 kfree(par->vbe_modes);
55156
55157+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55158+ if (par->pmi_code)
55159+ module_free_exec(NULL, par->pmi_code);
55160+#endif
55161+
55162 framebuffer_release(info);
55163 return err;
55164 }
55165@@ -1811,6 +1846,11 @@ static int uvesafb_remove(struct platform_device *dev)
55166 kfree(par->vbe_state_orig);
55167 kfree(par->vbe_state_saved);
55168
55169+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55170+ if (par->pmi_code)
55171+ module_free_exec(NULL, par->pmi_code);
55172+#endif
55173+
55174 framebuffer_release(info);
55175 }
55176 return 0;
55177diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
55178index 6170e7f..dd63031 100644
55179--- a/drivers/video/fbdev/vesafb.c
55180+++ b/drivers/video/fbdev/vesafb.c
55181@@ -9,6 +9,7 @@
55182 */
55183
55184 #include <linux/module.h>
55185+#include <linux/moduleloader.h>
55186 #include <linux/kernel.h>
55187 #include <linux/errno.h>
55188 #include <linux/string.h>
55189@@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
55190 static int vram_total; /* Set total amount of memory */
55191 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
55192 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
55193-static void (*pmi_start)(void) __read_mostly;
55194-static void (*pmi_pal) (void) __read_mostly;
55195+static void (*pmi_start)(void) __read_only;
55196+static void (*pmi_pal) (void) __read_only;
55197 static int depth __read_mostly;
55198 static int vga_compat __read_mostly;
55199 /* --------------------------------------------------------------------- */
55200@@ -233,6 +234,7 @@ static int vesafb_probe(struct platform_device *dev)
55201 unsigned int size_remap;
55202 unsigned int size_total;
55203 char *option = NULL;
55204+ void *pmi_code = NULL;
55205
55206 /* ignore error return of fb_get_options */
55207 fb_get_options("vesafb", &option);
55208@@ -279,10 +281,6 @@ static int vesafb_probe(struct platform_device *dev)
55209 size_remap = size_total;
55210 vesafb_fix.smem_len = size_remap;
55211
55212-#ifndef __i386__
55213- screen_info.vesapm_seg = 0;
55214-#endif
55215-
55216 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
55217 printk(KERN_WARNING
55218 "vesafb: cannot reserve video memory at 0x%lx\n",
55219@@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
55220 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
55221 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
55222
55223+#ifdef __i386__
55224+
55225+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55226+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
55227+ if (!pmi_code)
55228+#elif !defined(CONFIG_PAX_KERNEXEC)
55229+ if (0)
55230+#endif
55231+
55232+#endif
55233+ screen_info.vesapm_seg = 0;
55234+
55235 if (screen_info.vesapm_seg) {
55236- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
55237- screen_info.vesapm_seg,screen_info.vesapm_off);
55238+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
55239+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
55240 }
55241
55242 if (screen_info.vesapm_seg < 0xc000)
55243@@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
55244
55245 if (ypan || pmi_setpal) {
55246 unsigned short *pmi_base;
55247+
55248 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
55249- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
55250- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
55251+
55252+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55253+ pax_open_kernel();
55254+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
55255+#else
55256+ pmi_code = pmi_base;
55257+#endif
55258+
55259+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
55260+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
55261+
55262+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55263+ pmi_start = ktva_ktla(pmi_start);
55264+ pmi_pal = ktva_ktla(pmi_pal);
55265+ pax_close_kernel();
55266+#endif
55267+
55268 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
55269 if (pmi_base[3]) {
55270 printk(KERN_INFO "vesafb: pmi: ports = ");
55271@@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
55272 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
55273 (ypan ? FBINFO_HWACCEL_YPAN : 0);
55274
55275- if (!ypan)
55276- info->fbops->fb_pan_display = NULL;
55277+ if (!ypan) {
55278+ pax_open_kernel();
55279+ *(void **)&info->fbops->fb_pan_display = NULL;
55280+ pax_close_kernel();
55281+ }
55282
55283 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
55284 err = -ENOMEM;
55285@@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
55286 fb_info(info, "%s frame buffer device\n", info->fix.id);
55287 return 0;
55288 err:
55289+
55290+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55291+ module_free_exec(NULL, pmi_code);
55292+#endif
55293+
55294 if (info->screen_base)
55295 iounmap(info->screen_base);
55296 framebuffer_release(info);
55297diff --git a/drivers/video/fbdev/via/via_clock.h b/drivers/video/fbdev/via/via_clock.h
55298index 88714ae..16c2e11 100644
55299--- a/drivers/video/fbdev/via/via_clock.h
55300+++ b/drivers/video/fbdev/via/via_clock.h
55301@@ -56,7 +56,7 @@ struct via_clock {
55302
55303 void (*set_engine_pll_state)(u8 state);
55304 void (*set_engine_pll)(struct via_pll_config config);
55305-};
55306+} __no_const;
55307
55308
55309 static inline u32 get_pll_internal_frequency(u32 ref_freq,
55310diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
55311index 3c14e43..2630570 100644
55312--- a/drivers/video/logo/logo_linux_clut224.ppm
55313+++ b/drivers/video/logo/logo_linux_clut224.ppm
55314@@ -2,1603 +2,1123 @@ P3
55315 # Standard 224-color Linux logo
55316 80 80
55317 255
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- 0 0 0 0 0 0 0 0 0 0 0 0
55324- 0 0 0 0 0 0 0 0 0 0 0 0
55325- 0 0 0 0 0 0 0 0 0 0 0 0
55326- 0 0 0 0 0 0 0 0 0 0 0 0
55327- 6 6 6 6 6 6 10 10 10 10 10 10
55328- 10 10 10 6 6 6 6 6 6 6 6 6
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 0 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 0 0 0
55343- 0 0 0 0 0 0 0 0 0 0 0 0
55344- 0 0 0 0 0 0 0 0 0 0 0 0
55345- 0 0 0 0 0 0 0 0 0 0 0 0
55346- 0 0 0 6 6 6 10 10 10 14 14 14
55347- 22 22 22 26 26 26 30 30 30 34 34 34
55348- 30 30 30 30 30 30 26 26 26 18 18 18
55349- 14 14 14 10 10 10 6 6 6 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 0 0 0 0 0 0 0 0 0 0
55357- 0 0 0 0 0 0 0 0 0 0 0 0
55358- 0 0 0 0 0 0 0 0 0 0 0 0
55359- 0 0 0 0 0 1 0 0 1 0 0 0
55360- 0 0 0 0 0 0 0 0 0 0 0 0
55361- 0 0 0 0 0 0 0 0 0 0 0 0
55362- 0 0 0 0 0 0 0 0 0 0 0 0
55363- 0 0 0 0 0 0 0 0 0 0 0 0
55364- 0 0 0 0 0 0 0 0 0 0 0 0
55365- 0 0 0 0 0 0 0 0 0 0 0 0
55366- 6 6 6 14 14 14 26 26 26 42 42 42
55367- 54 54 54 66 66 66 78 78 78 78 78 78
55368- 78 78 78 74 74 74 66 66 66 54 54 54
55369- 42 42 42 26 26 26 18 18 18 10 10 10
55370- 6 6 6 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 1 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 0 0 0 0 0 0 0 0 0
55383- 0 0 0 0 0 0 0 0 0 0 0 0
55384- 0 0 0 0 0 0 0 0 0 0 0 0
55385- 0 0 0 0 0 0 0 0 0 10 10 10
55386- 22 22 22 42 42 42 66 66 66 86 86 86
55387- 66 66 66 38 38 38 38 38 38 22 22 22
55388- 26 26 26 34 34 34 54 54 54 66 66 66
55389- 86 86 86 70 70 70 46 46 46 26 26 26
55390- 14 14 14 6 6 6 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 0 0 0 0 0 0 0 0 0 0
55397- 0 0 0 0 0 0 0 0 0 0 0 0
55398- 0 0 0 0 0 0 0 0 0 0 0 0
55399- 0 0 1 0 0 1 0 0 1 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- 0 0 0 0 0 0 0 0 0 0 0 0
55403- 0 0 0 0 0 0 0 0 0 0 0 0
55404- 0 0 0 0 0 0 0 0 0 0 0 0
55405- 0 0 0 0 0 0 10 10 10 26 26 26
55406- 50 50 50 82 82 82 58 58 58 6 6 6
55407- 2 2 6 2 2 6 2 2 6 2 2 6
55408- 2 2 6 2 2 6 2 2 6 2 2 6
55409- 6 6 6 54 54 54 86 86 86 66 66 66
55410- 38 38 38 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0 0
55417- 0 0 0 0 0 0 0 0 0 0 0 0
55418- 0 0 0 0 0 0 0 0 0 0 0 0
55419- 0 0 0 0 0 0 0 0 0 0 0 0
55420- 0 0 0 0 0 0 0 0 0 0 0 0
55421- 0 0 0 0 0 0 0 0 0 0 0 0
55422- 0 0 0 0 0 0 0 0 0 0 0 0
55423- 0 0 0 0 0 0 0 0 0 0 0 0
55424- 0 0 0 0 0 0 0 0 0 0 0 0
55425- 0 0 0 6 6 6 22 22 22 50 50 50
55426- 78 78 78 34 34 34 2 2 6 2 2 6
55427- 2 2 6 2 2 6 2 2 6 2 2 6
55428- 2 2 6 2 2 6 2 2 6 2 2 6
55429- 2 2 6 2 2 6 6 6 6 70 70 70
55430- 78 78 78 46 46 46 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0 0
55437- 0 0 0 0 0 0 0 0 0 0 0 0
55438- 0 0 0 0 0 0 0 0 0 0 0 0
55439- 0 0 1 0 0 1 0 0 1 0 0 0
55440- 0 0 0 0 0 0 0 0 0 0 0 0
55441- 0 0 0 0 0 0 0 0 0 0 0 0
55442- 0 0 0 0 0 0 0 0 0 0 0 0
55443- 0 0 0 0 0 0 0 0 0 0 0 0
55444- 0 0 0 0 0 0 0 0 0 0 0 0
55445- 6 6 6 18 18 18 42 42 42 82 82 82
55446- 26 26 26 2 2 6 2 2 6 2 2 6
55447- 2 2 6 2 2 6 2 2 6 2 2 6
55448- 2 2 6 2 2 6 2 2 6 14 14 14
55449- 46 46 46 34 34 34 6 6 6 2 2 6
55450- 42 42 42 78 78 78 42 42 42 18 18 18
55451- 6 6 6 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 1 0 0 0 0 0 1 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 0 0 0
55462- 0 0 0 0 0 0 0 0 0 0 0 0
55463- 0 0 0 0 0 0 0 0 0 0 0 0
55464- 0 0 0 0 0 0 0 0 0 0 0 0
55465- 10 10 10 30 30 30 66 66 66 58 58 58
55466- 2 2 6 2 2 6 2 2 6 2 2 6
55467- 2 2 6 2 2 6 2 2 6 2 2 6
55468- 2 2 6 2 2 6 2 2 6 26 26 26
55469- 86 86 86 101 101 101 46 46 46 10 10 10
55470- 2 2 6 58 58 58 70 70 70 34 34 34
55471- 10 10 10 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 0 0 0 0 0 0 0
55477- 0 0 0 0 0 0 0 0 0 0 0 0
55478- 0 0 0 0 0 0 0 0 0 0 0 0
55479- 0 0 1 0 0 1 0 0 1 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 0 0 0
55482- 0 0 0 0 0 0 0 0 0 0 0 0
55483- 0 0 0 0 0 0 0 0 0 0 0 0
55484- 0 0 0 0 0 0 0 0 0 0 0 0
55485- 14 14 14 42 42 42 86 86 86 10 10 10
55486- 2 2 6 2 2 6 2 2 6 2 2 6
55487- 2 2 6 2 2 6 2 2 6 2 2 6
55488- 2 2 6 2 2 6 2 2 6 30 30 30
55489- 94 94 94 94 94 94 58 58 58 26 26 26
55490- 2 2 6 6 6 6 78 78 78 54 54 54
55491- 22 22 22 6 6 6 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 0 0 0 0 0 0 0 0 0 0
55497- 0 0 0 0 0 0 0 0 0 0 0 0
55498- 0 0 0 0 0 0 0 0 0 0 0 0
55499- 0 0 0 0 0 0 0 0 0 0 0 0
55500- 0 0 0 0 0 0 0 0 0 0 0 0
55501- 0 0 0 0 0 0 0 0 0 0 0 0
55502- 0 0 0 0 0 0 0 0 0 0 0 0
55503- 0 0 0 0 0 0 0 0 0 0 0 0
55504- 0 0 0 0 0 0 0 0 0 6 6 6
55505- 22 22 22 62 62 62 62 62 62 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 2 2 6
55508- 2 2 6 2 2 6 2 2 6 26 26 26
55509- 54 54 54 38 38 38 18 18 18 10 10 10
55510- 2 2 6 2 2 6 34 34 34 82 82 82
55511- 38 38 38 14 14 14 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 0 0 0 0 0 0 0
55517- 0 0 0 0 0 0 0 0 0 0 0 0
55518- 0 0 0 0 0 0 0 0 0 0 0 0
55519- 0 0 0 0 0 1 0 0 1 0 0 0
55520- 0 0 0 0 0 0 0 0 0 0 0 0
55521- 0 0 0 0 0 0 0 0 0 0 0 0
55522- 0 0 0 0 0 0 0 0 0 0 0 0
55523- 0 0 0 0 0 0 0 0 0 0 0 0
55524- 0 0 0 0 0 0 0 0 0 6 6 6
55525- 30 30 30 78 78 78 30 30 30 2 2 6
55526- 2 2 6 2 2 6 2 2 6 2 2 6
55527- 2 2 6 2 2 6 2 2 6 2 2 6
55528- 2 2 6 2 2 6 2 2 6 10 10 10
55529- 10 10 10 2 2 6 2 2 6 2 2 6
55530- 2 2 6 2 2 6 2 2 6 78 78 78
55531- 50 50 50 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0 0
55537- 0 0 0 0 0 0 0 0 0 0 0 0
55538- 0 0 0 0 0 0 0 0 0 0 0 0
55539- 0 0 1 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 0 0 0
55542- 0 0 0 0 0 0 0 0 0 0 0 0
55543- 0 0 0 0 0 0 0 0 0 0 0 0
55544- 0 0 0 0 0 0 0 0 0 10 10 10
55545- 38 38 38 86 86 86 14 14 14 2 2 6
55546- 2 2 6 2 2 6 2 2 6 2 2 6
55547- 2 2 6 2 2 6 2 2 6 2 2 6
55548- 2 2 6 2 2 6 2 2 6 2 2 6
55549- 2 2 6 2 2 6 2 2 6 2 2 6
55550- 2 2 6 2 2 6 2 2 6 54 54 54
55551- 66 66 66 26 26 26 6 6 6 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 0 0 0 0 0 0 0 0 0 0
55557- 0 0 0 0 0 0 0 0 0 0 0 0
55558- 0 0 0 0 0 0 0 0 0 0 0 0
55559- 0 0 0 0 0 1 0 0 1 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 0 0 0
55562- 0 0 0 0 0 0 0 0 0 0 0 0
55563- 0 0 0 0 0 0 0 0 0 0 0 0
55564- 0 0 0 0 0 0 0 0 0 14 14 14
55565- 42 42 42 82 82 82 2 2 6 2 2 6
55566- 2 2 6 6 6 6 10 10 10 2 2 6
55567- 2 2 6 2 2 6 2 2 6 2 2 6
55568- 2 2 6 2 2 6 2 2 6 6 6 6
55569- 14 14 14 10 10 10 2 2 6 2 2 6
55570- 2 2 6 2 2 6 2 2 6 18 18 18
55571- 82 82 82 34 34 34 10 10 10 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 1 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 0 0 0
55582- 0 0 0 0 0 0 0 0 0 0 0 0
55583- 0 0 0 0 0 0 0 0 0 0 0 0
55584- 0 0 0 0 0 0 0 0 0 14 14 14
55585- 46 46 46 86 86 86 2 2 6 2 2 6
55586- 6 6 6 6 6 6 22 22 22 34 34 34
55587- 6 6 6 2 2 6 2 2 6 2 2 6
55588- 2 2 6 2 2 6 18 18 18 34 34 34
55589- 10 10 10 50 50 50 22 22 22 2 2 6
55590- 2 2 6 2 2 6 2 2 6 10 10 10
55591- 86 86 86 42 42 42 14 14 14 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 0 0 0 0
55596- 0 0 0 0 0 0 0 0 0 0 0 0
55597- 0 0 0 0 0 0 0 0 0 0 0 0
55598- 0 0 0 0 0 0 0 0 0 0 0 0
55599- 0 0 1 0 0 1 0 0 1 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 0 0 0
55602- 0 0 0 0 0 0 0 0 0 0 0 0
55603- 0 0 0 0 0 0 0 0 0 0 0 0
55604- 0 0 0 0 0 0 0 0 0 14 14 14
55605- 46 46 46 86 86 86 2 2 6 2 2 6
55606- 38 38 38 116 116 116 94 94 94 22 22 22
55607- 22 22 22 2 2 6 2 2 6 2 2 6
55608- 14 14 14 86 86 86 138 138 138 162 162 162
55609-154 154 154 38 38 38 26 26 26 6 6 6
55610- 2 2 6 2 2 6 2 2 6 2 2 6
55611- 86 86 86 46 46 46 14 14 14 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 0 0 0
55622- 0 0 0 0 0 0 0 0 0 0 0 0
55623- 0 0 0 0 0 0 0 0 0 0 0 0
55624- 0 0 0 0 0 0 0 0 0 14 14 14
55625- 46 46 46 86 86 86 2 2 6 14 14 14
55626-134 134 134 198 198 198 195 195 195 116 116 116
55627- 10 10 10 2 2 6 2 2 6 6 6 6
55628-101 98 89 187 187 187 210 210 210 218 218 218
55629-214 214 214 134 134 134 14 14 14 6 6 6
55630- 2 2 6 2 2 6 2 2 6 2 2 6
55631- 86 86 86 50 50 50 18 18 18 6 6 6
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 0 0 0 0
55636- 0 0 0 0 0 0 0 0 0 0 0 0
55637- 0 0 0 0 0 0 0 0 0 0 0 0
55638- 0 0 0 0 0 0 0 0 1 0 0 0
55639- 0 0 1 0 0 1 0 0 1 0 0 0
55640- 0 0 0 0 0 0 0 0 0 0 0 0
55641- 0 0 0 0 0 0 0 0 0 0 0 0
55642- 0 0 0 0 0 0 0 0 0 0 0 0
55643- 0 0 0 0 0 0 0 0 0 0 0 0
55644- 0 0 0 0 0 0 0 0 0 14 14 14
55645- 46 46 46 86 86 86 2 2 6 54 54 54
55646-218 218 218 195 195 195 226 226 226 246 246 246
55647- 58 58 58 2 2 6 2 2 6 30 30 30
55648-210 210 210 253 253 253 174 174 174 123 123 123
55649-221 221 221 234 234 234 74 74 74 2 2 6
55650- 2 2 6 2 2 6 2 2 6 2 2 6
55651- 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0 0
55656- 0 0 0 0 0 0 0 0 0 0 0 0
55657- 0 0 0 0 0 0 0 0 0 0 0 0
55658- 0 0 0 0 0 0 0 0 0 0 0 0
55659- 0 0 0 0 0 0 0 0 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 0 0 0
55662- 0 0 0 0 0 0 0 0 0 0 0 0
55663- 0 0 0 0 0 0 0 0 0 0 0 0
55664- 0 0 0 0 0 0 0 0 0 14 14 14
55665- 46 46 46 82 82 82 2 2 6 106 106 106
55666-170 170 170 26 26 26 86 86 86 226 226 226
55667-123 123 123 10 10 10 14 14 14 46 46 46
55668-231 231 231 190 190 190 6 6 6 70 70 70
55669- 90 90 90 238 238 238 158 158 158 2 2 6
55670- 2 2 6 2 2 6 2 2 6 2 2 6
55671- 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0 0
55676- 0 0 0 0 0 0 0 0 0 0 0 0
55677- 0 0 0 0 0 0 0 0 0 0 0 0
55678- 0 0 0 0 0 0 0 0 1 0 0 0
55679- 0 0 1 0 0 1 0 0 1 0 0 0
55680- 0 0 0 0 0 0 0 0 0 0 0 0
55681- 0 0 0 0 0 0 0 0 0 0 0 0
55682- 0 0 0 0 0 0 0 0 0 0 0 0
55683- 0 0 0 0 0 0 0 0 0 0 0 0
55684- 0 0 0 0 0 0 0 0 0 14 14 14
55685- 42 42 42 86 86 86 6 6 6 116 116 116
55686-106 106 106 6 6 6 70 70 70 149 149 149
55687-128 128 128 18 18 18 38 38 38 54 54 54
55688-221 221 221 106 106 106 2 2 6 14 14 14
55689- 46 46 46 190 190 190 198 198 198 2 2 6
55690- 2 2 6 2 2 6 2 2 6 2 2 6
55691- 74 74 74 62 62 62 22 22 22 6 6 6
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 1 0 0 0
55699- 0 0 1 0 0 0 0 0 1 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 0 0 0
55702- 0 0 0 0 0 0 0 0 0 0 0 0
55703- 0 0 0 0 0 0 0 0 0 0 0 0
55704- 0 0 0 0 0 0 0 0 0 14 14 14
55705- 42 42 42 94 94 94 14 14 14 101 101 101
55706-128 128 128 2 2 6 18 18 18 116 116 116
55707-118 98 46 121 92 8 121 92 8 98 78 10
55708-162 162 162 106 106 106 2 2 6 2 2 6
55709- 2 2 6 195 195 195 195 195 195 6 6 6
55710- 2 2 6 2 2 6 2 2 6 2 2 6
55711- 74 74 74 62 62 62 22 22 22 6 6 6
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 1 0 0 1
55719- 0 0 1 0 0 0 0 0 1 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 0 0 0
55722- 0 0 0 0 0 0 0 0 0 0 0 0
55723- 0 0 0 0 0 0 0 0 0 0 0 0
55724- 0 0 0 0 0 0 0 0 0 10 10 10
55725- 38 38 38 90 90 90 14 14 14 58 58 58
55726-210 210 210 26 26 26 54 38 6 154 114 10
55727-226 170 11 236 186 11 225 175 15 184 144 12
55728-215 174 15 175 146 61 37 26 9 2 2 6
55729- 70 70 70 246 246 246 138 138 138 2 2 6
55730- 2 2 6 2 2 6 2 2 6 2 2 6
55731- 70 70 70 66 66 66 26 26 26 6 6 6
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 0 0 0
55742- 0 0 0 0 0 0 0 0 0 0 0 0
55743- 0 0 0 0 0 0 0 0 0 0 0 0
55744- 0 0 0 0 0 0 0 0 0 10 10 10
55745- 38 38 38 86 86 86 14 14 14 10 10 10
55746-195 195 195 188 164 115 192 133 9 225 175 15
55747-239 182 13 234 190 10 232 195 16 232 200 30
55748-245 207 45 241 208 19 232 195 16 184 144 12
55749-218 194 134 211 206 186 42 42 42 2 2 6
55750- 2 2 6 2 2 6 2 2 6 2 2 6
55751- 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0
55762- 0 0 0 0 0 0 0 0 0 0 0 0
55763- 0 0 0 0 0 0 0 0 0 0 0 0
55764- 0 0 0 0 0 0 0 0 0 10 10 10
55765- 34 34 34 86 86 86 14 14 14 2 2 6
55766-121 87 25 192 133 9 219 162 10 239 182 13
55767-236 186 11 232 195 16 241 208 19 244 214 54
55768-246 218 60 246 218 38 246 215 20 241 208 19
55769-241 208 19 226 184 13 121 87 25 2 2 6
55770- 2 2 6 2 2 6 2 2 6 2 2 6
55771- 50 50 50 82 82 82 34 34 34 10 10 10
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 0 0 0
55782- 0 0 0 0 0 0 0 0 0 0 0 0
55783- 0 0 0 0 0 0 0 0 0 0 0 0
55784- 0 0 0 0 0 0 0 0 0 10 10 10
55785- 34 34 34 82 82 82 30 30 30 61 42 6
55786-180 123 7 206 145 10 230 174 11 239 182 13
55787-234 190 10 238 202 15 241 208 19 246 218 74
55788-246 218 38 246 215 20 246 215 20 246 215 20
55789-226 184 13 215 174 15 184 144 12 6 6 6
55790- 2 2 6 2 2 6 2 2 6 2 2 6
55791- 26 26 26 94 94 94 42 42 42 14 14 14
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 0 0 0
55802- 0 0 0 0 0 0 0 0 0 0 0 0
55803- 0 0 0 0 0 0 0 0 0 0 0 0
55804- 0 0 0 0 0 0 0 0 0 10 10 10
55805- 30 30 30 78 78 78 50 50 50 104 69 6
55806-192 133 9 216 158 10 236 178 12 236 186 11
55807-232 195 16 241 208 19 244 214 54 245 215 43
55808-246 215 20 246 215 20 241 208 19 198 155 10
55809-200 144 11 216 158 10 156 118 10 2 2 6
55810- 2 2 6 2 2 6 2 2 6 2 2 6
55811- 6 6 6 90 90 90 54 54 54 18 18 18
55812- 6 6 6 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 0 0 0
55822- 0 0 0 0 0 0 0 0 0 0 0 0
55823- 0 0 0 0 0 0 0 0 0 0 0 0
55824- 0 0 0 0 0 0 0 0 0 10 10 10
55825- 30 30 30 78 78 78 46 46 46 22 22 22
55826-137 92 6 210 162 10 239 182 13 238 190 10
55827-238 202 15 241 208 19 246 215 20 246 215 20
55828-241 208 19 203 166 17 185 133 11 210 150 10
55829-216 158 10 210 150 10 102 78 10 2 2 6
55830- 6 6 6 54 54 54 14 14 14 2 2 6
55831- 2 2 6 62 62 62 74 74 74 30 30 30
55832- 10 10 10 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 0 0 0 0 0 0
55842- 0 0 0 0 0 0 0 0 0 0 0 0
55843- 0 0 0 0 0 0 0 0 0 0 0 0
55844- 0 0 0 0 0 0 0 0 0 10 10 10
55845- 34 34 34 78 78 78 50 50 50 6 6 6
55846- 94 70 30 139 102 15 190 146 13 226 184 13
55847-232 200 30 232 195 16 215 174 15 190 146 13
55848-168 122 10 192 133 9 210 150 10 213 154 11
55849-202 150 34 182 157 106 101 98 89 2 2 6
55850- 2 2 6 78 78 78 116 116 116 58 58 58
55851- 2 2 6 22 22 22 90 90 90 46 46 46
55852- 18 18 18 6 6 6 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 0 0 0 0 0 0
55862- 0 0 0 0 0 0 0 0 0 0 0 0
55863- 0 0 0 0 0 0 0 0 0 0 0 0
55864- 0 0 0 0 0 0 0 0 0 10 10 10
55865- 38 38 38 86 86 86 50 50 50 6 6 6
55866-128 128 128 174 154 114 156 107 11 168 122 10
55867-198 155 10 184 144 12 197 138 11 200 144 11
55868-206 145 10 206 145 10 197 138 11 188 164 115
55869-195 195 195 198 198 198 174 174 174 14 14 14
55870- 2 2 6 22 22 22 116 116 116 116 116 116
55871- 22 22 22 2 2 6 74 74 74 70 70 70
55872- 30 30 30 10 10 10 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 0 0 0 0 0 0 0 0 0
55882- 0 0 0 0 0 0 0 0 0 0 0 0
55883- 0 0 0 0 0 0 0 0 0 0 0 0
55884- 0 0 0 0 0 0 6 6 6 18 18 18
55885- 50 50 50 101 101 101 26 26 26 10 10 10
55886-138 138 138 190 190 190 174 154 114 156 107 11
55887-197 138 11 200 144 11 197 138 11 192 133 9
55888-180 123 7 190 142 34 190 178 144 187 187 187
55889-202 202 202 221 221 221 214 214 214 66 66 66
55890- 2 2 6 2 2 6 50 50 50 62 62 62
55891- 6 6 6 2 2 6 10 10 10 90 90 90
55892- 50 50 50 18 18 18 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
55902- 0 0 0 0 0 0 0 0 0 0 0 0
55903- 0 0 0 0 0 0 0 0 0 0 0 0
55904- 0 0 0 0 0 0 10 10 10 34 34 34
55905- 74 74 74 74 74 74 2 2 6 6 6 6
55906-144 144 144 198 198 198 190 190 190 178 166 146
55907-154 121 60 156 107 11 156 107 11 168 124 44
55908-174 154 114 187 187 187 190 190 190 210 210 210
55909-246 246 246 253 253 253 253 253 253 182 182 182
55910- 6 6 6 2 2 6 2 2 6 2 2 6
55911- 2 2 6 2 2 6 2 2 6 62 62 62
55912- 74 74 74 34 34 34 14 14 14 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 0 0 0
55921- 0 0 0 0 0 0 0 0 0 0 0 0
55922- 0 0 0 0 0 0 0 0 0 0 0 0
55923- 0 0 0 0 0 0 0 0 0 0 0 0
55924- 0 0 0 10 10 10 22 22 22 54 54 54
55925- 94 94 94 18 18 18 2 2 6 46 46 46
55926-234 234 234 221 221 221 190 190 190 190 190 190
55927-190 190 190 187 187 187 187 187 187 190 190 190
55928-190 190 190 195 195 195 214 214 214 242 242 242
55929-253 253 253 253 253 253 253 253 253 253 253 253
55930- 82 82 82 2 2 6 2 2 6 2 2 6
55931- 2 2 6 2 2 6 2 2 6 14 14 14
55932- 86 86 86 54 54 54 22 22 22 6 6 6
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 0 0 0
55941- 0 0 0 0 0 0 0 0 0 0 0 0
55942- 0 0 0 0 0 0 0 0 0 0 0 0
55943- 0 0 0 0 0 0 0 0 0 0 0 0
55944- 6 6 6 18 18 18 46 46 46 90 90 90
55945- 46 46 46 18 18 18 6 6 6 182 182 182
55946-253 253 253 246 246 246 206 206 206 190 190 190
55947-190 190 190 190 190 190 190 190 190 190 190 190
55948-206 206 206 231 231 231 250 250 250 253 253 253
55949-253 253 253 253 253 253 253 253 253 253 253 253
55950-202 202 202 14 14 14 2 2 6 2 2 6
55951- 2 2 6 2 2 6 2 2 6 2 2 6
55952- 42 42 42 86 86 86 42 42 42 18 18 18
55953- 6 6 6 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 0 0 0 0 0 0
55961- 0 0 0 0 0 0 0 0 0 0 0 0
55962- 0 0 0 0 0 0 0 0 0 0 0 0
55963- 0 0 0 0 0 0 0 0 0 6 6 6
55964- 14 14 14 38 38 38 74 74 74 66 66 66
55965- 2 2 6 6 6 6 90 90 90 250 250 250
55966-253 253 253 253 253 253 238 238 238 198 198 198
55967-190 190 190 190 190 190 195 195 195 221 221 221
55968-246 246 246 253 253 253 253 253 253 253 253 253
55969-253 253 253 253 253 253 253 253 253 253 253 253
55970-253 253 253 82 82 82 2 2 6 2 2 6
55971- 2 2 6 2 2 6 2 2 6 2 2 6
55972- 2 2 6 78 78 78 70 70 70 34 34 34
55973- 14 14 14 6 6 6 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 0 0 0 0 0 0 0 0 0
55981- 0 0 0 0 0 0 0 0 0 0 0 0
55982- 0 0 0 0 0 0 0 0 0 0 0 0
55983- 0 0 0 0 0 0 0 0 0 14 14 14
55984- 34 34 34 66 66 66 78 78 78 6 6 6
55985- 2 2 6 18 18 18 218 218 218 253 253 253
55986-253 253 253 253 253 253 253 253 253 246 246 246
55987-226 226 226 231 231 231 246 246 246 253 253 253
55988-253 253 253 253 253 253 253 253 253 253 253 253
55989-253 253 253 253 253 253 253 253 253 253 253 253
55990-253 253 253 178 178 178 2 2 6 2 2 6
55991- 2 2 6 2 2 6 2 2 6 2 2 6
55992- 2 2 6 18 18 18 90 90 90 62 62 62
55993- 30 30 30 10 10 10 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- 0 0 0 0 0 0 0 0 0 0 0 0
56001- 0 0 0 0 0 0 0 0 0 0 0 0
56002- 0 0 0 0 0 0 0 0 0 0 0 0
56003- 0 0 0 0 0 0 10 10 10 26 26 26
56004- 58 58 58 90 90 90 18 18 18 2 2 6
56005- 2 2 6 110 110 110 253 253 253 253 253 253
56006-253 253 253 253 253 253 253 253 253 253 253 253
56007-250 250 250 253 253 253 253 253 253 253 253 253
56008-253 253 253 253 253 253 253 253 253 253 253 253
56009-253 253 253 253 253 253 253 253 253 253 253 253
56010-253 253 253 231 231 231 18 18 18 2 2 6
56011- 2 2 6 2 2 6 2 2 6 2 2 6
56012- 2 2 6 2 2 6 18 18 18 94 94 94
56013- 54 54 54 26 26 26 10 10 10 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- 0 0 0 0 0 0 0 0 0 0 0 0
56021- 0 0 0 0 0 0 0 0 0 0 0 0
56022- 0 0 0 0 0 0 0 0 0 0 0 0
56023- 0 0 0 6 6 6 22 22 22 50 50 50
56024- 90 90 90 26 26 26 2 2 6 2 2 6
56025- 14 14 14 195 195 195 250 250 250 253 253 253
56026-253 253 253 253 253 253 253 253 253 253 253 253
56027-253 253 253 253 253 253 253 253 253 253 253 253
56028-253 253 253 253 253 253 253 253 253 253 253 253
56029-253 253 253 253 253 253 253 253 253 253 253 253
56030-250 250 250 242 242 242 54 54 54 2 2 6
56031- 2 2 6 2 2 6 2 2 6 2 2 6
56032- 2 2 6 2 2 6 2 2 6 38 38 38
56033- 86 86 86 50 50 50 22 22 22 6 6 6
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- 0 0 0 0 0 0 0 0 0 0 0 0
56041- 0 0 0 0 0 0 0 0 0 0 0 0
56042- 0 0 0 0 0 0 0 0 0 0 0 0
56043- 6 6 6 14 14 14 38 38 38 82 82 82
56044- 34 34 34 2 2 6 2 2 6 2 2 6
56045- 42 42 42 195 195 195 246 246 246 253 253 253
56046-253 253 253 253 253 253 253 253 253 250 250 250
56047-242 242 242 242 242 242 250 250 250 253 253 253
56048-253 253 253 253 253 253 253 253 253 253 253 253
56049-253 253 253 250 250 250 246 246 246 238 238 238
56050-226 226 226 231 231 231 101 101 101 6 6 6
56051- 2 2 6 2 2 6 2 2 6 2 2 6
56052- 2 2 6 2 2 6 2 2 6 2 2 6
56053- 38 38 38 82 82 82 42 42 42 14 14 14
56054- 6 6 6 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 0 0 0
56060- 0 0 0 0 0 0 0 0 0 0 0 0
56061- 0 0 0 0 0 0 0 0 0 0 0 0
56062- 0 0 0 0 0 0 0 0 0 0 0 0
56063- 10 10 10 26 26 26 62 62 62 66 66 66
56064- 2 2 6 2 2 6 2 2 6 6 6 6
56065- 70 70 70 170 170 170 206 206 206 234 234 234
56066-246 246 246 250 250 250 250 250 250 238 238 238
56067-226 226 226 231 231 231 238 238 238 250 250 250
56068-250 250 250 250 250 250 246 246 246 231 231 231
56069-214 214 214 206 206 206 202 202 202 202 202 202
56070-198 198 198 202 202 202 182 182 182 18 18 18
56071- 2 2 6 2 2 6 2 2 6 2 2 6
56072- 2 2 6 2 2 6 2 2 6 2 2 6
56073- 2 2 6 62 62 62 66 66 66 30 30 30
56074- 10 10 10 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 0 0 0
56080- 0 0 0 0 0 0 0 0 0 0 0 0
56081- 0 0 0 0 0 0 0 0 0 0 0 0
56082- 0 0 0 0 0 0 0 0 0 0 0 0
56083- 14 14 14 42 42 42 82 82 82 18 18 18
56084- 2 2 6 2 2 6 2 2 6 10 10 10
56085- 94 94 94 182 182 182 218 218 218 242 242 242
56086-250 250 250 253 253 253 253 253 253 250 250 250
56087-234 234 234 253 253 253 253 253 253 253 253 253
56088-253 253 253 253 253 253 253 253 253 246 246 246
56089-238 238 238 226 226 226 210 210 210 202 202 202
56090-195 195 195 195 195 195 210 210 210 158 158 158
56091- 6 6 6 14 14 14 50 50 50 14 14 14
56092- 2 2 6 2 2 6 2 2 6 2 2 6
56093- 2 2 6 6 6 6 86 86 86 46 46 46
56094- 18 18 18 6 6 6 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 0 0 0
56100- 0 0 0 0 0 0 0 0 0 0 0 0
56101- 0 0 0 0 0 0 0 0 0 0 0 0
56102- 0 0 0 0 0 0 0 0 0 6 6 6
56103- 22 22 22 54 54 54 70 70 70 2 2 6
56104- 2 2 6 10 10 10 2 2 6 22 22 22
56105-166 166 166 231 231 231 250 250 250 253 253 253
56106-253 253 253 253 253 253 253 253 253 250 250 250
56107-242 242 242 253 253 253 253 253 253 253 253 253
56108-253 253 253 253 253 253 253 253 253 253 253 253
56109-253 253 253 253 253 253 253 253 253 246 246 246
56110-231 231 231 206 206 206 198 198 198 226 226 226
56111- 94 94 94 2 2 6 6 6 6 38 38 38
56112- 30 30 30 2 2 6 2 2 6 2 2 6
56113- 2 2 6 2 2 6 62 62 62 66 66 66
56114- 26 26 26 10 10 10 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 0 0 0 0 0 0
56120- 0 0 0 0 0 0 0 0 0 0 0 0
56121- 0 0 0 0 0 0 0 0 0 0 0 0
56122- 0 0 0 0 0 0 0 0 0 10 10 10
56123- 30 30 30 74 74 74 50 50 50 2 2 6
56124- 26 26 26 26 26 26 2 2 6 106 106 106
56125-238 238 238 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 253 253 253
56128-253 253 253 253 253 253 253 253 253 253 253 253
56129-253 253 253 253 253 253 253 253 253 253 253 253
56130-253 253 253 246 246 246 218 218 218 202 202 202
56131-210 210 210 14 14 14 2 2 6 2 2 6
56132- 30 30 30 22 22 22 2 2 6 2 2 6
56133- 2 2 6 2 2 6 18 18 18 86 86 86
56134- 42 42 42 14 14 14 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 0 0 0 0 0 0
56140- 0 0 0 0 0 0 0 0 0 0 0 0
56141- 0 0 0 0 0 0 0 0 0 0 0 0
56142- 0 0 0 0 0 0 0 0 0 14 14 14
56143- 42 42 42 90 90 90 22 22 22 2 2 6
56144- 42 42 42 2 2 6 18 18 18 218 218 218
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 253 253 253 253 253 253 253 253 253
56149-253 253 253 253 253 253 253 253 253 253 253 253
56150-253 253 253 253 253 253 250 250 250 221 221 221
56151-218 218 218 101 101 101 2 2 6 14 14 14
56152- 18 18 18 38 38 38 10 10 10 2 2 6
56153- 2 2 6 2 2 6 2 2 6 78 78 78
56154- 58 58 58 22 22 22 6 6 6 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 0 0 0 0 0 0 0 0 0
56160- 0 0 0 0 0 0 0 0 0 0 0 0
56161- 0 0 0 0 0 0 0 0 0 0 0 0
56162- 0 0 0 0 0 0 6 6 6 18 18 18
56163- 54 54 54 82 82 82 2 2 6 26 26 26
56164- 22 22 22 2 2 6 123 123 123 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 253 253 253 253 253 253
56169-253 253 253 253 253 253 253 253 253 253 253 253
56170-253 253 253 253 253 253 253 253 253 250 250 250
56171-238 238 238 198 198 198 6 6 6 38 38 38
56172- 58 58 58 26 26 26 38 38 38 2 2 6
56173- 2 2 6 2 2 6 2 2 6 46 46 46
56174- 78 78 78 30 30 30 10 10 10 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 0 0 0 0 0 0 0 0 0
56180- 0 0 0 0 0 0 0 0 0 0 0 0
56181- 0 0 0 0 0 0 0 0 0 0 0 0
56182- 0 0 0 0 0 0 10 10 10 30 30 30
56183- 74 74 74 58 58 58 2 2 6 42 42 42
56184- 2 2 6 22 22 22 231 231 231 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 250 250 250
56187-253 253 253 253 253 253 253 253 253 253 253 253
56188-253 253 253 253 253 253 253 253 253 253 253 253
56189-253 253 253 253 253 253 253 253 253 253 253 253
56190-253 253 253 253 253 253 253 253 253 253 253 253
56191-253 253 253 246 246 246 46 46 46 38 38 38
56192- 42 42 42 14 14 14 38 38 38 14 14 14
56193- 2 2 6 2 2 6 2 2 6 6 6 6
56194- 86 86 86 46 46 46 14 14 14 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- 0 0 0 0 0 0 0 0 0 0 0 0
56200- 0 0 0 0 0 0 0 0 0 0 0 0
56201- 0 0 0 0 0 0 0 0 0 0 0 0
56202- 0 0 0 6 6 6 14 14 14 42 42 42
56203- 90 90 90 18 18 18 18 18 18 26 26 26
56204- 2 2 6 116 116 116 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 250 250 250 238 238 238
56207-253 253 253 253 253 253 253 253 253 253 253 253
56208-253 253 253 253 253 253 253 253 253 253 253 253
56209-253 253 253 253 253 253 253 253 253 253 253 253
56210-253 253 253 253 253 253 253 253 253 253 253 253
56211-253 253 253 253 253 253 94 94 94 6 6 6
56212- 2 2 6 2 2 6 10 10 10 34 34 34
56213- 2 2 6 2 2 6 2 2 6 2 2 6
56214- 74 74 74 58 58 58 22 22 22 6 6 6
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- 0 0 0 0 0 0 0 0 0 0 0 0
56220- 0 0 0 0 0 0 0 0 0 0 0 0
56221- 0 0 0 0 0 0 0 0 0 0 0 0
56222- 0 0 0 10 10 10 26 26 26 66 66 66
56223- 82 82 82 2 2 6 38 38 38 6 6 6
56224- 14 14 14 210 210 210 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 246 246 246 242 242 242
56227-253 253 253 253 253 253 253 253 253 253 253 253
56228-253 253 253 253 253 253 253 253 253 253 253 253
56229-253 253 253 253 253 253 253 253 253 253 253 253
56230-253 253 253 253 253 253 253 253 253 253 253 253
56231-253 253 253 253 253 253 144 144 144 2 2 6
56232- 2 2 6 2 2 6 2 2 6 46 46 46
56233- 2 2 6 2 2 6 2 2 6 2 2 6
56234- 42 42 42 74 74 74 30 30 30 10 10 10
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 0 0 0
56239- 0 0 0 0 0 0 0 0 0 0 0 0
56240- 0 0 0 0 0 0 0 0 0 0 0 0
56241- 0 0 0 0 0 0 0 0 0 0 0 0
56242- 6 6 6 14 14 14 42 42 42 90 90 90
56243- 26 26 26 6 6 6 42 42 42 2 2 6
56244- 74 74 74 250 250 250 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 242 242 242 242 242 242
56247-253 253 253 253 253 253 253 253 253 253 253 253
56248-253 253 253 253 253 253 253 253 253 253 253 253
56249-253 253 253 253 253 253 253 253 253 253 253 253
56250-253 253 253 253 253 253 253 253 253 253 253 253
56251-253 253 253 253 253 253 182 182 182 2 2 6
56252- 2 2 6 2 2 6 2 2 6 46 46 46
56253- 2 2 6 2 2 6 2 2 6 2 2 6
56254- 10 10 10 86 86 86 38 38 38 10 10 10
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 0 0 0
56259- 0 0 0 0 0 0 0 0 0 0 0 0
56260- 0 0 0 0 0 0 0 0 0 0 0 0
56261- 0 0 0 0 0 0 0 0 0 0 0 0
56262- 10 10 10 26 26 26 66 66 66 82 82 82
56263- 2 2 6 22 22 22 18 18 18 2 2 6
56264-149 149 149 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 234 234 234 242 242 242
56267-253 253 253 253 253 253 253 253 253 253 253 253
56268-253 253 253 253 253 253 253 253 253 253 253 253
56269-253 253 253 253 253 253 253 253 253 253 253 253
56270-253 253 253 253 253 253 253 253 253 253 253 253
56271-253 253 253 253 253 253 206 206 206 2 2 6
56272- 2 2 6 2 2 6 2 2 6 38 38 38
56273- 2 2 6 2 2 6 2 2 6 2 2 6
56274- 6 6 6 86 86 86 46 46 46 14 14 14
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 0 0 0
56279- 0 0 0 0 0 0 0 0 0 0 0 0
56280- 0 0 0 0 0 0 0 0 0 0 0 0
56281- 0 0 0 0 0 0 0 0 0 6 6 6
56282- 18 18 18 46 46 46 86 86 86 18 18 18
56283- 2 2 6 34 34 34 10 10 10 6 6 6
56284-210 210 210 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 234 234 234 242 242 242
56287-253 253 253 253 253 253 253 253 253 253 253 253
56288-253 253 253 253 253 253 253 253 253 253 253 253
56289-253 253 253 253 253 253 253 253 253 253 253 253
56290-253 253 253 253 253 253 253 253 253 253 253 253
56291-253 253 253 253 253 253 221 221 221 6 6 6
56292- 2 2 6 2 2 6 6 6 6 30 30 30
56293- 2 2 6 2 2 6 2 2 6 2 2 6
56294- 2 2 6 82 82 82 54 54 54 18 18 18
56295- 6 6 6 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 0 0 0 0 0 0
56299- 0 0 0 0 0 0 0 0 0 0 0 0
56300- 0 0 0 0 0 0 0 0 0 0 0 0
56301- 0 0 0 0 0 0 0 0 0 10 10 10
56302- 26 26 26 66 66 66 62 62 62 2 2 6
56303- 2 2 6 38 38 38 10 10 10 26 26 26
56304-238 238 238 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 231 231 231 238 238 238
56307-253 253 253 253 253 253 253 253 253 253 253 253
56308-253 253 253 253 253 253 253 253 253 253 253 253
56309-253 253 253 253 253 253 253 253 253 253 253 253
56310-253 253 253 253 253 253 253 253 253 253 253 253
56311-253 253 253 253 253 253 231 231 231 6 6 6
56312- 2 2 6 2 2 6 10 10 10 30 30 30
56313- 2 2 6 2 2 6 2 2 6 2 2 6
56314- 2 2 6 66 66 66 58 58 58 22 22 22
56315- 6 6 6 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 0 0 0 0 0 0
56319- 0 0 0 0 0 0 0 0 0 0 0 0
56320- 0 0 0 0 0 0 0 0 0 0 0 0
56321- 0 0 0 0 0 0 0 0 0 10 10 10
56322- 38 38 38 78 78 78 6 6 6 2 2 6
56323- 2 2 6 46 46 46 14 14 14 42 42 42
56324-246 246 246 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 231 231 231 242 242 242
56327-253 253 253 253 253 253 253 253 253 253 253 253
56328-253 253 253 253 253 253 253 253 253 253 253 253
56329-253 253 253 253 253 253 253 253 253 253 253 253
56330-253 253 253 253 253 253 253 253 253 253 253 253
56331-253 253 253 253 253 253 234 234 234 10 10 10
56332- 2 2 6 2 2 6 22 22 22 14 14 14
56333- 2 2 6 2 2 6 2 2 6 2 2 6
56334- 2 2 6 66 66 66 62 62 62 22 22 22
56335- 6 6 6 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 0 0 0 0 0 0
56339- 0 0 0 0 0 0 0 0 0 0 0 0
56340- 0 0 0 0 0 0 0 0 0 0 0 0
56341- 0 0 0 0 0 0 6 6 6 18 18 18
56342- 50 50 50 74 74 74 2 2 6 2 2 6
56343- 14 14 14 70 70 70 34 34 34 62 62 62
56344-250 250 250 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 231 231 231 246 246 246
56347-253 253 253 253 253 253 253 253 253 253 253 253
56348-253 253 253 253 253 253 253 253 253 253 253 253
56349-253 253 253 253 253 253 253 253 253 253 253 253
56350-253 253 253 253 253 253 253 253 253 253 253 253
56351-253 253 253 253 253 253 234 234 234 14 14 14
56352- 2 2 6 2 2 6 30 30 30 2 2 6
56353- 2 2 6 2 2 6 2 2 6 2 2 6
56354- 2 2 6 66 66 66 62 62 62 22 22 22
56355- 6 6 6 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 0 0 0 0 0 0
56359- 0 0 0 0 0 0 0 0 0 0 0 0
56360- 0 0 0 0 0 0 0 0 0 0 0 0
56361- 0 0 0 0 0 0 6 6 6 18 18 18
56362- 54 54 54 62 62 62 2 2 6 2 2 6
56363- 2 2 6 30 30 30 46 46 46 70 70 70
56364-250 250 250 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 231 231 231 246 246 246
56367-253 253 253 253 253 253 253 253 253 253 253 253
56368-253 253 253 253 253 253 253 253 253 253 253 253
56369-253 253 253 253 253 253 253 253 253 253 253 253
56370-253 253 253 253 253 253 253 253 253 253 253 253
56371-253 253 253 253 253 253 226 226 226 10 10 10
56372- 2 2 6 6 6 6 30 30 30 2 2 6
56373- 2 2 6 2 2 6 2 2 6 2 2 6
56374- 2 2 6 66 66 66 58 58 58 22 22 22
56375- 6 6 6 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 0 0 0
56378- 0 0 0 0 0 0 0 0 0 0 0 0
56379- 0 0 0 0 0 0 0 0 0 0 0 0
56380- 0 0 0 0 0 0 0 0 0 0 0 0
56381- 0 0 0 0 0 0 6 6 6 22 22 22
56382- 58 58 58 62 62 62 2 2 6 2 2 6
56383- 2 2 6 2 2 6 30 30 30 78 78 78
56384-250 250 250 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 231 231 231 246 246 246
56387-253 253 253 253 253 253 253 253 253 253 253 253
56388-253 253 253 253 253 253 253 253 253 253 253 253
56389-253 253 253 253 253 253 253 253 253 253 253 253
56390-253 253 253 253 253 253 253 253 253 253 253 253
56391-253 253 253 253 253 253 206 206 206 2 2 6
56392- 22 22 22 34 34 34 18 14 6 22 22 22
56393- 26 26 26 18 18 18 6 6 6 2 2 6
56394- 2 2 6 82 82 82 54 54 54 18 18 18
56395- 6 6 6 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 0 0 0 0 0 0 0 0 0
56398- 0 0 0 0 0 0 0 0 0 0 0 0
56399- 0 0 0 0 0 0 0 0 0 0 0 0
56400- 0 0 0 0 0 0 0 0 0 0 0 0
56401- 0 0 0 0 0 0 6 6 6 26 26 26
56402- 62 62 62 106 106 106 74 54 14 185 133 11
56403-210 162 10 121 92 8 6 6 6 62 62 62
56404-238 238 238 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 231 231 231 246 246 246
56407-253 253 253 253 253 253 253 253 253 253 253 253
56408-253 253 253 253 253 253 253 253 253 253 253 253
56409-253 253 253 253 253 253 253 253 253 253 253 253
56410-253 253 253 253 253 253 253 253 253 253 253 253
56411-253 253 253 253 253 253 158 158 158 18 18 18
56412- 14 14 14 2 2 6 2 2 6 2 2 6
56413- 6 6 6 18 18 18 66 66 66 38 38 38
56414- 6 6 6 94 94 94 50 50 50 18 18 18
56415- 6 6 6 0 0 0 0 0 0 0 0 0
56416- 0 0 0 0 0 0 0 0 0 0 0 0
56417- 0 0 0 0 0 0 0 0 0 0 0 0
56418- 0 0 0 0 0 0 0 0 0 0 0 0
56419- 0 0 0 0 0 0 0 0 0 0 0 0
56420- 0 0 0 0 0 0 0 0 0 6 6 6
56421- 10 10 10 10 10 10 18 18 18 38 38 38
56422- 78 78 78 142 134 106 216 158 10 242 186 14
56423-246 190 14 246 190 14 156 118 10 10 10 10
56424- 90 90 90 238 238 238 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 231 231 231 250 250 250
56427-253 253 253 253 253 253 253 253 253 253 253 253
56428-253 253 253 253 253 253 253 253 253 253 253 253
56429-253 253 253 253 253 253 253 253 253 253 253 253
56430-253 253 253 253 253 253 253 253 253 246 230 190
56431-238 204 91 238 204 91 181 142 44 37 26 9
56432- 2 2 6 2 2 6 2 2 6 2 2 6
56433- 2 2 6 2 2 6 38 38 38 46 46 46
56434- 26 26 26 106 106 106 54 54 54 18 18 18
56435- 6 6 6 0 0 0 0 0 0 0 0 0
56436- 0 0 0 0 0 0 0 0 0 0 0 0
56437- 0 0 0 0 0 0 0 0 0 0 0 0
56438- 0 0 0 0 0 0 0 0 0 0 0 0
56439- 0 0 0 0 0 0 0 0 0 0 0 0
56440- 0 0 0 6 6 6 14 14 14 22 22 22
56441- 30 30 30 38 38 38 50 50 50 70 70 70
56442-106 106 106 190 142 34 226 170 11 242 186 14
56443-246 190 14 246 190 14 246 190 14 154 114 10
56444- 6 6 6 74 74 74 226 226 226 253 253 253
56445-253 253 253 253 253 253 253 253 253 253 253 253
56446-253 253 253 253 253 253 231 231 231 250 250 250
56447-253 253 253 253 253 253 253 253 253 253 253 253
56448-253 253 253 253 253 253 253 253 253 253 253 253
56449-253 253 253 253 253 253 253 253 253 253 253 253
56450-253 253 253 253 253 253 253 253 253 228 184 62
56451-241 196 14 241 208 19 232 195 16 38 30 10
56452- 2 2 6 2 2 6 2 2 6 2 2 6
56453- 2 2 6 6 6 6 30 30 30 26 26 26
56454-203 166 17 154 142 90 66 66 66 26 26 26
56455- 6 6 6 0 0 0 0 0 0 0 0 0
56456- 0 0 0 0 0 0 0 0 0 0 0 0
56457- 0 0 0 0 0 0 0 0 0 0 0 0
56458- 0 0 0 0 0 0 0 0 0 0 0 0
56459- 0 0 0 0 0 0 0 0 0 0 0 0
56460- 6 6 6 18 18 18 38 38 38 58 58 58
56461- 78 78 78 86 86 86 101 101 101 123 123 123
56462-175 146 61 210 150 10 234 174 13 246 186 14
56463-246 190 14 246 190 14 246 190 14 238 190 10
56464-102 78 10 2 2 6 46 46 46 198 198 198
56465-253 253 253 253 253 253 253 253 253 253 253 253
56466-253 253 253 253 253 253 234 234 234 242 242 242
56467-253 253 253 253 253 253 253 253 253 253 253 253
56468-253 253 253 253 253 253 253 253 253 253 253 253
56469-253 253 253 253 253 253 253 253 253 253 253 253
56470-253 253 253 253 253 253 253 253 253 224 178 62
56471-242 186 14 241 196 14 210 166 10 22 18 6
56472- 2 2 6 2 2 6 2 2 6 2 2 6
56473- 2 2 6 2 2 6 6 6 6 121 92 8
56474-238 202 15 232 195 16 82 82 82 34 34 34
56475- 10 10 10 0 0 0 0 0 0 0 0 0
56476- 0 0 0 0 0 0 0 0 0 0 0 0
56477- 0 0 0 0 0 0 0 0 0 0 0 0
56478- 0 0 0 0 0 0 0 0 0 0 0 0
56479- 0 0 0 0 0 0 0 0 0 0 0 0
56480- 14 14 14 38 38 38 70 70 70 154 122 46
56481-190 142 34 200 144 11 197 138 11 197 138 11
56482-213 154 11 226 170 11 242 186 14 246 190 14
56483-246 190 14 246 190 14 246 190 14 246 190 14
56484-225 175 15 46 32 6 2 2 6 22 22 22
56485-158 158 158 250 250 250 253 253 253 253 253 253
56486-253 253 253 253 253 253 253 253 253 253 253 253
56487-253 253 253 253 253 253 253 253 253 253 253 253
56488-253 253 253 253 253 253 253 253 253 253 253 253
56489-253 253 253 253 253 253 253 253 253 253 253 253
56490-253 253 253 250 250 250 242 242 242 224 178 62
56491-239 182 13 236 186 11 213 154 11 46 32 6
56492- 2 2 6 2 2 6 2 2 6 2 2 6
56493- 2 2 6 2 2 6 61 42 6 225 175 15
56494-238 190 10 236 186 11 112 100 78 42 42 42
56495- 14 14 14 0 0 0 0 0 0 0 0 0
56496- 0 0 0 0 0 0 0 0 0 0 0 0
56497- 0 0 0 0 0 0 0 0 0 0 0 0
56498- 0 0 0 0 0 0 0 0 0 0 0 0
56499- 0 0 0 0 0 0 0 0 0 6 6 6
56500- 22 22 22 54 54 54 154 122 46 213 154 11
56501-226 170 11 230 174 11 226 170 11 226 170 11
56502-236 178 12 242 186 14 246 190 14 246 190 14
56503-246 190 14 246 190 14 246 190 14 246 190 14
56504-241 196 14 184 144 12 10 10 10 2 2 6
56505- 6 6 6 116 116 116 242 242 242 253 253 253
56506-253 253 253 253 253 253 253 253 253 253 253 253
56507-253 253 253 253 253 253 253 253 253 253 253 253
56508-253 253 253 253 253 253 253 253 253 253 253 253
56509-253 253 253 253 253 253 253 253 253 253 253 253
56510-253 253 253 231 231 231 198 198 198 214 170 54
56511-236 178 12 236 178 12 210 150 10 137 92 6
56512- 18 14 6 2 2 6 2 2 6 2 2 6
56513- 6 6 6 70 47 6 200 144 11 236 178 12
56514-239 182 13 239 182 13 124 112 88 58 58 58
56515- 22 22 22 6 6 6 0 0 0 0 0 0
56516- 0 0 0 0 0 0 0 0 0 0 0 0
56517- 0 0 0 0 0 0 0 0 0 0 0 0
56518- 0 0 0 0 0 0 0 0 0 0 0 0
56519- 0 0 0 0 0 0 0 0 0 10 10 10
56520- 30 30 30 70 70 70 180 133 36 226 170 11
56521-239 182 13 242 186 14 242 186 14 246 186 14
56522-246 190 14 246 190 14 246 190 14 246 190 14
56523-246 190 14 246 190 14 246 190 14 246 190 14
56524-246 190 14 232 195 16 98 70 6 2 2 6
56525- 2 2 6 2 2 6 66 66 66 221 221 221
56526-253 253 253 253 253 253 253 253 253 253 253 253
56527-253 253 253 253 253 253 253 253 253 253 253 253
56528-253 253 253 253 253 253 253 253 253 253 253 253
56529-253 253 253 253 253 253 253 253 253 253 253 253
56530-253 253 253 206 206 206 198 198 198 214 166 58
56531-230 174 11 230 174 11 216 158 10 192 133 9
56532-163 110 8 116 81 8 102 78 10 116 81 8
56533-167 114 7 197 138 11 226 170 11 239 182 13
56534-242 186 14 242 186 14 162 146 94 78 78 78
56535- 34 34 34 14 14 14 6 6 6 0 0 0
56536- 0 0 0 0 0 0 0 0 0 0 0 0
56537- 0 0 0 0 0 0 0 0 0 0 0 0
56538- 0 0 0 0 0 0 0 0 0 0 0 0
56539- 0 0 0 0 0 0 0 0 0 6 6 6
56540- 30 30 30 78 78 78 190 142 34 226 170 11
56541-239 182 13 246 190 14 246 190 14 246 190 14
56542-246 190 14 246 190 14 246 190 14 246 190 14
56543-246 190 14 246 190 14 246 190 14 246 190 14
56544-246 190 14 241 196 14 203 166 17 22 18 6
56545- 2 2 6 2 2 6 2 2 6 38 38 38
56546-218 218 218 253 253 253 253 253 253 253 253 253
56547-253 253 253 253 253 253 253 253 253 253 253 253
56548-253 253 253 253 253 253 253 253 253 253 253 253
56549-253 253 253 253 253 253 253 253 253 253 253 253
56550-250 250 250 206 206 206 198 198 198 202 162 69
56551-226 170 11 236 178 12 224 166 10 210 150 10
56552-200 144 11 197 138 11 192 133 9 197 138 11
56553-210 150 10 226 170 11 242 186 14 246 190 14
56554-246 190 14 246 186 14 225 175 15 124 112 88
56555- 62 62 62 30 30 30 14 14 14 6 6 6
56556- 0 0 0 0 0 0 0 0 0 0 0 0
56557- 0 0 0 0 0 0 0 0 0 0 0 0
56558- 0 0 0 0 0 0 0 0 0 0 0 0
56559- 0 0 0 0 0 0 0 0 0 10 10 10
56560- 30 30 30 78 78 78 174 135 50 224 166 10
56561-239 182 13 246 190 14 246 190 14 246 190 14
56562-246 190 14 246 190 14 246 190 14 246 190 14
56563-246 190 14 246 190 14 246 190 14 246 190 14
56564-246 190 14 246 190 14 241 196 14 139 102 15
56565- 2 2 6 2 2 6 2 2 6 2 2 6
56566- 78 78 78 250 250 250 253 253 253 253 253 253
56567-253 253 253 253 253 253 253 253 253 253 253 253
56568-253 253 253 253 253 253 253 253 253 253 253 253
56569-253 253 253 253 253 253 253 253 253 253 253 253
56570-250 250 250 214 214 214 198 198 198 190 150 46
56571-219 162 10 236 178 12 234 174 13 224 166 10
56572-216 158 10 213 154 11 213 154 11 216 158 10
56573-226 170 11 239 182 13 246 190 14 246 190 14
56574-246 190 14 246 190 14 242 186 14 206 162 42
56575-101 101 101 58 58 58 30 30 30 14 14 14
56576- 6 6 6 0 0 0 0 0 0 0 0 0
56577- 0 0 0 0 0 0 0 0 0 0 0 0
56578- 0 0 0 0 0 0 0 0 0 0 0 0
56579- 0 0 0 0 0 0 0 0 0 10 10 10
56580- 30 30 30 74 74 74 174 135 50 216 158 10
56581-236 178 12 246 190 14 246 190 14 246 190 14
56582-246 190 14 246 190 14 246 190 14 246 190 14
56583-246 190 14 246 190 14 246 190 14 246 190 14
56584-246 190 14 246 190 14 241 196 14 226 184 13
56585- 61 42 6 2 2 6 2 2 6 2 2 6
56586- 22 22 22 238 238 238 253 253 253 253 253 253
56587-253 253 253 253 253 253 253 253 253 253 253 253
56588-253 253 253 253 253 253 253 253 253 253 253 253
56589-253 253 253 253 253 253 253 253 253 253 253 253
56590-253 253 253 226 226 226 187 187 187 180 133 36
56591-216 158 10 236 178 12 239 182 13 236 178 12
56592-230 174 11 226 170 11 226 170 11 230 174 11
56593-236 178 12 242 186 14 246 190 14 246 190 14
56594-246 190 14 246 190 14 246 186 14 239 182 13
56595-206 162 42 106 106 106 66 66 66 34 34 34
56596- 14 14 14 6 6 6 0 0 0 0 0 0
56597- 0 0 0 0 0 0 0 0 0 0 0 0
56598- 0 0 0 0 0 0 0 0 0 0 0 0
56599- 0 0 0 0 0 0 0 0 0 6 6 6
56600- 26 26 26 70 70 70 163 133 67 213 154 11
56601-236 178 12 246 190 14 246 190 14 246 190 14
56602-246 190 14 246 190 14 246 190 14 246 190 14
56603-246 190 14 246 190 14 246 190 14 246 190 14
56604-246 190 14 246 190 14 246 190 14 241 196 14
56605-190 146 13 18 14 6 2 2 6 2 2 6
56606- 46 46 46 246 246 246 253 253 253 253 253 253
56607-253 253 253 253 253 253 253 253 253 253 253 253
56608-253 253 253 253 253 253 253 253 253 253 253 253
56609-253 253 253 253 253 253 253 253 253 253 253 253
56610-253 253 253 221 221 221 86 86 86 156 107 11
56611-216 158 10 236 178 12 242 186 14 246 186 14
56612-242 186 14 239 182 13 239 182 13 242 186 14
56613-242 186 14 246 186 14 246 190 14 246 190 14
56614-246 190 14 246 190 14 246 190 14 246 190 14
56615-242 186 14 225 175 15 142 122 72 66 66 66
56616- 30 30 30 10 10 10 0 0 0 0 0 0
56617- 0 0 0 0 0 0 0 0 0 0 0 0
56618- 0 0 0 0 0 0 0 0 0 0 0 0
56619- 0 0 0 0 0 0 0 0 0 6 6 6
56620- 26 26 26 70 70 70 163 133 67 210 150 10
56621-236 178 12 246 190 14 246 190 14 246 190 14
56622-246 190 14 246 190 14 246 190 14 246 190 14
56623-246 190 14 246 190 14 246 190 14 246 190 14
56624-246 190 14 246 190 14 246 190 14 246 190 14
56625-232 195 16 121 92 8 34 34 34 106 106 106
56626-221 221 221 253 253 253 253 253 253 253 253 253
56627-253 253 253 253 253 253 253 253 253 253 253 253
56628-253 253 253 253 253 253 253 253 253 253 253 253
56629-253 253 253 253 253 253 253 253 253 253 253 253
56630-242 242 242 82 82 82 18 14 6 163 110 8
56631-216 158 10 236 178 12 242 186 14 246 190 14
56632-246 190 14 246 190 14 246 190 14 246 190 14
56633-246 190 14 246 190 14 246 190 14 246 190 14
56634-246 190 14 246 190 14 246 190 14 246 190 14
56635-246 190 14 246 190 14 242 186 14 163 133 67
56636- 46 46 46 18 18 18 6 6 6 0 0 0
56637- 0 0 0 0 0 0 0 0 0 0 0 0
56638- 0 0 0 0 0 0 0 0 0 0 0 0
56639- 0 0 0 0 0 0 0 0 0 10 10 10
56640- 30 30 30 78 78 78 163 133 67 210 150 10
56641-236 178 12 246 186 14 246 190 14 246 190 14
56642-246 190 14 246 190 14 246 190 14 246 190 14
56643-246 190 14 246 190 14 246 190 14 246 190 14
56644-246 190 14 246 190 14 246 190 14 246 190 14
56645-241 196 14 215 174 15 190 178 144 253 253 253
56646-253 253 253 253 253 253 253 253 253 253 253 253
56647-253 253 253 253 253 253 253 253 253 253 253 253
56648-253 253 253 253 253 253 253 253 253 253 253 253
56649-253 253 253 253 253 253 253 253 253 218 218 218
56650- 58 58 58 2 2 6 22 18 6 167 114 7
56651-216 158 10 236 178 12 246 186 14 246 190 14
56652-246 190 14 246 190 14 246 190 14 246 190 14
56653-246 190 14 246 190 14 246 190 14 246 190 14
56654-246 190 14 246 190 14 246 190 14 246 190 14
56655-246 190 14 246 186 14 242 186 14 190 150 46
56656- 54 54 54 22 22 22 6 6 6 0 0 0
56657- 0 0 0 0 0 0 0 0 0 0 0 0
56658- 0 0 0 0 0 0 0 0 0 0 0 0
56659- 0 0 0 0 0 0 0 0 0 14 14 14
56660- 38 38 38 86 86 86 180 133 36 213 154 11
56661-236 178 12 246 186 14 246 190 14 246 190 14
56662-246 190 14 246 190 14 246 190 14 246 190 14
56663-246 190 14 246 190 14 246 190 14 246 190 14
56664-246 190 14 246 190 14 246 190 14 246 190 14
56665-246 190 14 232 195 16 190 146 13 214 214 214
56666-253 253 253 253 253 253 253 253 253 253 253 253
56667-253 253 253 253 253 253 253 253 253 253 253 253
56668-253 253 253 253 253 253 253 253 253 253 253 253
56669-253 253 253 250 250 250 170 170 170 26 26 26
56670- 2 2 6 2 2 6 37 26 9 163 110 8
56671-219 162 10 239 182 13 246 186 14 246 190 14
56672-246 190 14 246 190 14 246 190 14 246 190 14
56673-246 190 14 246 190 14 246 190 14 246 190 14
56674-246 190 14 246 190 14 246 190 14 246 190 14
56675-246 186 14 236 178 12 224 166 10 142 122 72
56676- 46 46 46 18 18 18 6 6 6 0 0 0
56677- 0 0 0 0 0 0 0 0 0 0 0 0
56678- 0 0 0 0 0 0 0 0 0 0 0 0
56679- 0 0 0 0 0 0 6 6 6 18 18 18
56680- 50 50 50 109 106 95 192 133 9 224 166 10
56681-242 186 14 246 190 14 246 190 14 246 190 14
56682-246 190 14 246 190 14 246 190 14 246 190 14
56683-246 190 14 246 190 14 246 190 14 246 190 14
56684-246 190 14 246 190 14 246 190 14 246 190 14
56685-242 186 14 226 184 13 210 162 10 142 110 46
56686-226 226 226 253 253 253 253 253 253 253 253 253
56687-253 253 253 253 253 253 253 253 253 253 253 253
56688-253 253 253 253 253 253 253 253 253 253 253 253
56689-198 198 198 66 66 66 2 2 6 2 2 6
56690- 2 2 6 2 2 6 50 34 6 156 107 11
56691-219 162 10 239 182 13 246 186 14 246 190 14
56692-246 190 14 246 190 14 246 190 14 246 190 14
56693-246 190 14 246 190 14 246 190 14 246 190 14
56694-246 190 14 246 190 14 246 190 14 242 186 14
56695-234 174 13 213 154 11 154 122 46 66 66 66
56696- 30 30 30 10 10 10 0 0 0 0 0 0
56697- 0 0 0 0 0 0 0 0 0 0 0 0
56698- 0 0 0 0 0 0 0 0 0 0 0 0
56699- 0 0 0 0 0 0 6 6 6 22 22 22
56700- 58 58 58 154 121 60 206 145 10 234 174 13
56701-242 186 14 246 186 14 246 190 14 246 190 14
56702-246 190 14 246 190 14 246 190 14 246 190 14
56703-246 190 14 246 190 14 246 190 14 246 190 14
56704-246 190 14 246 190 14 246 190 14 246 190 14
56705-246 186 14 236 178 12 210 162 10 163 110 8
56706- 61 42 6 138 138 138 218 218 218 250 250 250
56707-253 253 253 253 253 253 253 253 253 250 250 250
56708-242 242 242 210 210 210 144 144 144 66 66 66
56709- 6 6 6 2 2 6 2 2 6 2 2 6
56710- 2 2 6 2 2 6 61 42 6 163 110 8
56711-216 158 10 236 178 12 246 190 14 246 190 14
56712-246 190 14 246 190 14 246 190 14 246 190 14
56713-246 190 14 246 190 14 246 190 14 246 190 14
56714-246 190 14 239 182 13 230 174 11 216 158 10
56715-190 142 34 124 112 88 70 70 70 38 38 38
56716- 18 18 18 6 6 6 0 0 0 0 0 0
56717- 0 0 0 0 0 0 0 0 0 0 0 0
56718- 0 0 0 0 0 0 0 0 0 0 0 0
56719- 0 0 0 0 0 0 6 6 6 22 22 22
56720- 62 62 62 168 124 44 206 145 10 224 166 10
56721-236 178 12 239 182 13 242 186 14 242 186 14
56722-246 186 14 246 190 14 246 190 14 246 190 14
56723-246 190 14 246 190 14 246 190 14 246 190 14
56724-246 190 14 246 190 14 246 190 14 246 190 14
56725-246 190 14 236 178 12 216 158 10 175 118 6
56726- 80 54 7 2 2 6 6 6 6 30 30 30
56727- 54 54 54 62 62 62 50 50 50 38 38 38
56728- 14 14 14 2 2 6 2 2 6 2 2 6
56729- 2 2 6 2 2 6 2 2 6 2 2 6
56730- 2 2 6 6 6 6 80 54 7 167 114 7
56731-213 154 11 236 178 12 246 190 14 246 190 14
56732-246 190 14 246 190 14 246 190 14 246 190 14
56733-246 190 14 242 186 14 239 182 13 239 182 13
56734-230 174 11 210 150 10 174 135 50 124 112 88
56735- 82 82 82 54 54 54 34 34 34 18 18 18
56736- 6 6 6 0 0 0 0 0 0 0 0 0
56737- 0 0 0 0 0 0 0 0 0 0 0 0
56738- 0 0 0 0 0 0 0 0 0 0 0 0
56739- 0 0 0 0 0 0 6 6 6 18 18 18
56740- 50 50 50 158 118 36 192 133 9 200 144 11
56741-216 158 10 219 162 10 224 166 10 226 170 11
56742-230 174 11 236 178 12 239 182 13 239 182 13
56743-242 186 14 246 186 14 246 190 14 246 190 14
56744-246 190 14 246 190 14 246 190 14 246 190 14
56745-246 186 14 230 174 11 210 150 10 163 110 8
56746-104 69 6 10 10 10 2 2 6 2 2 6
56747- 2 2 6 2 2 6 2 2 6 2 2 6
56748- 2 2 6 2 2 6 2 2 6 2 2 6
56749- 2 2 6 2 2 6 2 2 6 2 2 6
56750- 2 2 6 6 6 6 91 60 6 167 114 7
56751-206 145 10 230 174 11 242 186 14 246 190 14
56752-246 190 14 246 190 14 246 186 14 242 186 14
56753-239 182 13 230 174 11 224 166 10 213 154 11
56754-180 133 36 124 112 88 86 86 86 58 58 58
56755- 38 38 38 22 22 22 10 10 10 6 6 6
56756- 0 0 0 0 0 0 0 0 0 0 0 0
56757- 0 0 0 0 0 0 0 0 0 0 0 0
56758- 0 0 0 0 0 0 0 0 0 0 0 0
56759- 0 0 0 0 0 0 0 0 0 14 14 14
56760- 34 34 34 70 70 70 138 110 50 158 118 36
56761-167 114 7 180 123 7 192 133 9 197 138 11
56762-200 144 11 206 145 10 213 154 11 219 162 10
56763-224 166 10 230 174 11 239 182 13 242 186 14
56764-246 186 14 246 186 14 246 186 14 246 186 14
56765-239 182 13 216 158 10 185 133 11 152 99 6
56766-104 69 6 18 14 6 2 2 6 2 2 6
56767- 2 2 6 2 2 6 2 2 6 2 2 6
56768- 2 2 6 2 2 6 2 2 6 2 2 6
56769- 2 2 6 2 2 6 2 2 6 2 2 6
56770- 2 2 6 6 6 6 80 54 7 152 99 6
56771-192 133 9 219 162 10 236 178 12 239 182 13
56772-246 186 14 242 186 14 239 182 13 236 178 12
56773-224 166 10 206 145 10 192 133 9 154 121 60
56774- 94 94 94 62 62 62 42 42 42 22 22 22
56775- 14 14 14 6 6 6 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 0 0 0 0 0 0
56778- 0 0 0 0 0 0 0 0 0 0 0 0
56779- 0 0 0 0 0 0 0 0 0 6 6 6
56780- 18 18 18 34 34 34 58 58 58 78 78 78
56781-101 98 89 124 112 88 142 110 46 156 107 11
56782-163 110 8 167 114 7 175 118 6 180 123 7
56783-185 133 11 197 138 11 210 150 10 219 162 10
56784-226 170 11 236 178 12 236 178 12 234 174 13
56785-219 162 10 197 138 11 163 110 8 130 83 6
56786- 91 60 6 10 10 10 2 2 6 2 2 6
56787- 18 18 18 38 38 38 38 38 38 38 38 38
56788- 38 38 38 38 38 38 38 38 38 38 38 38
56789- 38 38 38 38 38 38 26 26 26 2 2 6
56790- 2 2 6 6 6 6 70 47 6 137 92 6
56791-175 118 6 200 144 11 219 162 10 230 174 11
56792-234 174 13 230 174 11 219 162 10 210 150 10
56793-192 133 9 163 110 8 124 112 88 82 82 82
56794- 50 50 50 30 30 30 14 14 14 6 6 6
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 0 0 0 0 0 0 0 0 0
56799- 0 0 0 0 0 0 0 0 0 0 0 0
56800- 6 6 6 14 14 14 22 22 22 34 34 34
56801- 42 42 42 58 58 58 74 74 74 86 86 86
56802-101 98 89 122 102 70 130 98 46 121 87 25
56803-137 92 6 152 99 6 163 110 8 180 123 7
56804-185 133 11 197 138 11 206 145 10 200 144 11
56805-180 123 7 156 107 11 130 83 6 104 69 6
56806- 50 34 6 54 54 54 110 110 110 101 98 89
56807- 86 86 86 82 82 82 78 78 78 78 78 78
56808- 78 78 78 78 78 78 78 78 78 78 78 78
56809- 78 78 78 82 82 82 86 86 86 94 94 94
56810-106 106 106 101 101 101 86 66 34 124 80 6
56811-156 107 11 180 123 7 192 133 9 200 144 11
56812-206 145 10 200 144 11 192 133 9 175 118 6
56813-139 102 15 109 106 95 70 70 70 42 42 42
56814- 22 22 22 10 10 10 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 0 0 0 0 0 0 0 0 0
56820- 0 0 0 0 0 0 6 6 6 10 10 10
56821- 14 14 14 22 22 22 30 30 30 38 38 38
56822- 50 50 50 62 62 62 74 74 74 90 90 90
56823-101 98 89 112 100 78 121 87 25 124 80 6
56824-137 92 6 152 99 6 152 99 6 152 99 6
56825-138 86 6 124 80 6 98 70 6 86 66 30
56826-101 98 89 82 82 82 58 58 58 46 46 46
56827- 38 38 38 34 34 34 34 34 34 34 34 34
56828- 34 34 34 34 34 34 34 34 34 34 34 34
56829- 34 34 34 34 34 34 38 38 38 42 42 42
56830- 54 54 54 82 82 82 94 86 76 91 60 6
56831-134 86 6 156 107 11 167 114 7 175 118 6
56832-175 118 6 167 114 7 152 99 6 121 87 25
56833-101 98 89 62 62 62 34 34 34 18 18 18
56834- 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
56841- 0 0 0 6 6 6 6 6 6 10 10 10
56842- 18 18 18 22 22 22 30 30 30 42 42 42
56843- 50 50 50 66 66 66 86 86 86 101 98 89
56844-106 86 58 98 70 6 104 69 6 104 69 6
56845-104 69 6 91 60 6 82 62 34 90 90 90
56846- 62 62 62 38 38 38 22 22 22 14 14 14
56847- 10 10 10 10 10 10 10 10 10 10 10 10
56848- 10 10 10 10 10 10 6 6 6 10 10 10
56849- 10 10 10 10 10 10 10 10 10 14 14 14
56850- 22 22 22 42 42 42 70 70 70 89 81 66
56851- 80 54 7 104 69 6 124 80 6 137 92 6
56852-134 86 6 116 81 8 100 82 52 86 86 86
56853- 58 58 58 30 30 30 14 14 14 6 6 6
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 0 0 0
56861- 0 0 0 0 0 0 0 0 0 0 0 0
56862- 0 0 0 6 6 6 10 10 10 14 14 14
56863- 18 18 18 26 26 26 38 38 38 54 54 54
56864- 70 70 70 86 86 86 94 86 76 89 81 66
56865- 89 81 66 86 86 86 74 74 74 50 50 50
56866- 30 30 30 14 14 14 6 6 6 0 0 0
56867- 0 0 0 0 0 0 0 0 0 0 0 0
56868- 0 0 0 0 0 0 0 0 0 0 0 0
56869- 0 0 0 0 0 0 0 0 0 0 0 0
56870- 6 6 6 18 18 18 34 34 34 58 58 58
56871- 82 82 82 89 81 66 89 81 66 89 81 66
56872- 94 86 66 94 86 76 74 74 74 50 50 50
56873- 26 26 26 14 14 14 6 6 6 0 0 0
56874- 0 0 0 0 0 0 0 0 0 0 0 0
56875- 0 0 0 0 0 0 0 0 0 0 0 0
56876- 0 0 0 0 0 0 0 0 0 0 0 0
56877- 0 0 0 0 0 0 0 0 0 0 0 0
56878- 0 0 0 0 0 0 0 0 0 0 0 0
56879- 0 0 0 0 0 0 0 0 0 0 0 0
56880- 0 0 0 0 0 0 0 0 0 0 0 0
56881- 0 0 0 0 0 0 0 0 0 0 0 0
56882- 0 0 0 0 0 0 0 0 0 0 0 0
56883- 6 6 6 6 6 6 14 14 14 18 18 18
56884- 30 30 30 38 38 38 46 46 46 54 54 54
56885- 50 50 50 42 42 42 30 30 30 18 18 18
56886- 10 10 10 0 0 0 0 0 0 0 0 0
56887- 0 0 0 0 0 0 0 0 0 0 0 0
56888- 0 0 0 0 0 0 0 0 0 0 0 0
56889- 0 0 0 0 0 0 0 0 0 0 0 0
56890- 0 0 0 6 6 6 14 14 14 26 26 26
56891- 38 38 38 50 50 50 58 58 58 58 58 58
56892- 54 54 54 42 42 42 30 30 30 18 18 18
56893- 10 10 10 0 0 0 0 0 0 0 0 0
56894- 0 0 0 0 0 0 0 0 0 0 0 0
56895- 0 0 0 0 0 0 0 0 0 0 0 0
56896- 0 0 0 0 0 0 0 0 0 0 0 0
56897- 0 0 0 0 0 0 0 0 0 0 0 0
56898- 0 0 0 0 0 0 0 0 0 0 0 0
56899- 0 0 0 0 0 0 0 0 0 0 0 0
56900- 0 0 0 0 0 0 0 0 0 0 0 0
56901- 0 0 0 0 0 0 0 0 0 0 0 0
56902- 0 0 0 0 0 0 0 0 0 0 0 0
56903- 0 0 0 0 0 0 0 0 0 6 6 6
56904- 6 6 6 10 10 10 14 14 14 18 18 18
56905- 18 18 18 14 14 14 10 10 10 6 6 6
56906- 0 0 0 0 0 0 0 0 0 0 0 0
56907- 0 0 0 0 0 0 0 0 0 0 0 0
56908- 0 0 0 0 0 0 0 0 0 0 0 0
56909- 0 0 0 0 0 0 0 0 0 0 0 0
56910- 0 0 0 0 0 0 0 0 0 6 6 6
56911- 14 14 14 18 18 18 22 22 22 22 22 22
56912- 18 18 18 14 14 14 10 10 10 6 6 6
56913- 0 0 0 0 0 0 0 0 0 0 0 0
56914- 0 0 0 0 0 0 0 0 0 0 0 0
56915- 0 0 0 0 0 0 0 0 0 0 0 0
56916- 0 0 0 0 0 0 0 0 0 0 0 0
56917- 0 0 0 0 0 0 0 0 0 0 0 0
56918+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 4 4 4 4 4 4 4 4 4 4 4 4
56931+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 4 4 4 4 4 4 4 4 4 4 4 4
56945+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 4 4 4 4 4 4 4 4 4 4 4 4
56959+4 4 4 4 4 4
56960+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56961+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56962+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56963+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56964+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56965+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56966+4 4 4 4 4 4 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 4 4 4 4 4 4
56969+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56970+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56971+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56972+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56973+4 4 4 4 4 4
56974+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56975+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56976+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56977+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56978+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56979+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56980+4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
56983+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56984+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56985+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56986+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56987+4 4 4 4 4 4
56988+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56989+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56990+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56991+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56992+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56993+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56994+4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
56997+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56998+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56999+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57000+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57001+4 4 4 4 4 4
57002+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57003+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57004+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57005+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57006+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
57007+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 4 4 4 4 4 4
57010+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57011+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
57012+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57013+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
57014+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57015+4 4 4 4 4 4
57016+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57017+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57018+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57019+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57020+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
57021+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
57022+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57023+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57024+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57025+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
57026+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
57027+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
57028+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57029+4 4 4 4 4 4
57030+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57031+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57032+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57033+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57034+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
57035+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
57036+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57037+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57038+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57039+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
57040+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
57041+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
57042+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
57043+4 4 4 4 4 4
57044+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57045+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57046+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57047+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
57048+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
57049+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
57050+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
57051+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57052+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
57053+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
57054+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
57055+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
57056+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
57057+4 4 4 4 4 4
57058+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57059+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57060+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57061+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
57062+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
57063+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
57064+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
57065+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
57066+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
57067+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
57068+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
57069+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
57070+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
57071+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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57074+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
57075+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
57076+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
57077+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
57078+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
57079+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
57080+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
57081+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
57082+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
57083+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
57084+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
57085+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+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57088+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
57089+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
57090+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
57091+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
57092+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
57093+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
57094+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
57095+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
57096+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
57097+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
57098+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
57099+4 4 4 4 4 4
57100+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57101+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57102+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
57103+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
57104+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
57105+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
57106+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
57107+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
57108+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
57109+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
57110+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
57111+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
57112+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
57113+4 4 4 4 4 4
57114+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57115+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57116+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
57117+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
57118+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
57119+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
57120+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
57121+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
57122+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
57123+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
57124+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
57125+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
57126+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57127+4 4 4 4 4 4
57128+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57129+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57130+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
57131+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
57132+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
57133+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
57134+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
57135+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
57136+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
57137+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
57138+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
57139+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
57140+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
57141+4 4 4 4 4 4
57142+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57143+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
57144+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
57145+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
57146+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
57147+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
57148+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
57149+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
57150+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
57151+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
57152+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
57153+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
57154+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
57155+4 4 4 4 4 4
57156+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57157+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
57158+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
57159+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
57160+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
57161+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
57162+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
57163+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
57164+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
57165+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
57166+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
57167+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
57168+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
57169+0 0 0 4 4 4
57170+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
57171+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
57172+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
57173+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
57174+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
57175+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
57176+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
57177+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
57178+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
57179+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
57180+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
57181+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
57182+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
57183+2 0 0 0 0 0
57184+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
57185+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
57186+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
57187+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
57188+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
57189+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
57190+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
57191+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
57192+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
57193+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
57194+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
57195+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
57196+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
57197+37 38 37 0 0 0
57198+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
57199+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
57200+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
57201+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
57202+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
57203+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
57204+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
57205+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
57206+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
57207+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
57208+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
57209+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
57210+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
57211+85 115 134 4 0 0
57212+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
57213+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
57214+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
57215+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
57216+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
57217+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
57218+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
57219+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
57220+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
57221+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
57222+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
57223+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
57224+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
57225+60 73 81 4 0 0
57226+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
57227+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
57228+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
57229+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
57230+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
57231+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
57232+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
57233+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
57234+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
57235+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
57236+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
57237+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
57238+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
57239+16 19 21 4 0 0
57240+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
57241+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
57242+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
57243+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
57244+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
57245+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
57246+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
57247+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
57248+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
57249+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
57250+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
57251+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
57252+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
57253+4 0 0 4 3 3
57254+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
57255+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
57256+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
57257+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
57258+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
57259+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
57260+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
57261+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
57262+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
57263+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
57264+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
57265+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
57266+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
57267+3 2 2 4 4 4
57268+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
57269+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
57270+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
57271+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
57272+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
57273+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
57274+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
57275+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
57276+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
57277+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
57278+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
57279+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
57280+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
57281+4 4 4 4 4 4
57282+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
57283+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
57284+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
57285+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
57286+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
57287+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
57288+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
57289+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
57290+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
57291+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
57292+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
57293+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
57294+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
57295+4 4 4 4 4 4
57296+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
57297+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
57298+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
57299+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
57300+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
57301+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
57302+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
57303+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
57304+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
57305+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
57306+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
57307+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
57308+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
57309+5 5 5 5 5 5
57310+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
57311+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
57312+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
57313+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
57314+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
57315+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57316+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
57317+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
57318+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
57319+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
57320+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
57321+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
57322+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
57323+5 5 5 4 4 4
57324+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
57325+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
57326+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
57327+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
57328+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57329+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
57330+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
57331+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
57332+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
57333+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
57334+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
57335+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
57336+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57337+4 4 4 4 4 4
57338+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
57339+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
57340+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
57341+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
57342+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
57343+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57344+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57345+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
57346+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
57347+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
57348+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
57349+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
57350+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57351+4 4 4 4 4 4
57352+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
57353+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
57354+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
57355+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
57356+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57357+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
57358+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
57359+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
57360+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
57361+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
57362+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 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 4 4 4 4 4 4 4 4 4 4 4 4
57365+4 4 4 4 4 4
57366+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
57367+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
57368+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
57369+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
57370+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57371+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57372+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57373+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
57374+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
57375+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
57376+6 6 6 4 0 0 4 0 0 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 4 4 4 4 4 4 4 4 4 4 4 4
57379+4 4 4 4 4 4
57380+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
57381+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
57382+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
57383+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
57384+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57385+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
57386+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
57387+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
57388+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
57389+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
57390+4 0 0 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57393+4 4 4 4 4 4
57394+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
57395+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
57396+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
57397+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
57398+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57399+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
57400+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
57401+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
57402+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
57403+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
57404+6 6 6 4 0 0 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
57407+4 4 4 4 4 4
57408+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
57409+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
57410+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
57411+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
57412+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57413+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
57414+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
57415+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
57416+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
57417+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
57418+4 0 0 3 2 2 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57421+4 4 4 4 4 4
57422+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
57423+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
57424+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
57425+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
57426+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
57427+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
57428+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
57429+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
57430+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
57431+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
57432+4 0 0 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57435+4 4 4 4 4 4
57436+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
57437+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
57438+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
57439+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
57440+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57441+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
57442+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
57443+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
57444+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
57445+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
57446+4 0 0 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57449+4 4 4 4 4 4
57450+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
57451+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
57452+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
57453+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
57454+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57455+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
57456+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
57457+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
57458+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
57459+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
57460+4 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57463+4 4 4 4 4 4
57464+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
57465+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
57466+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
57467+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
57468+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57469+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
57470+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
57471+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
57472+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
57473+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57474+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57477+4 4 4 4 4 4
57478+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
57479+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
57480+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
57481+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
57482+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
57483+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
57484+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
57485+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
57486+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57487+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57488+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57491+4 4 4 4 4 4
57492+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
57493+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
57494+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
57495+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
57496+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57497+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
57498+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
57499+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
57500+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57501+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57502+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57505+4 4 4 4 4 4
57506+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
57507+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
57508+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
57509+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
57510+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
57511+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
57512+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
57513+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
57514+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57515+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57516+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57519+4 4 4 4 4 4
57520+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
57521+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
57522+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57523+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
57524+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
57525+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
57526+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
57527+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
57528+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
57529+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57530+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57533+4 4 4 4 4 4
57534+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
57535+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
57536+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
57537+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
57538+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
57539+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
57540+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
57541+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
57542+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57543+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57544+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57547+4 4 4 4 4 4
57548+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
57549+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
57550+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57551+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
57552+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
57553+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
57554+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
57555+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
57556+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
57557+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57558+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57561+4 4 4 4 4 4
57562+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
57563+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
57564+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
57565+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
57566+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
57567+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
57568+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
57569+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
57570+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57571+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57572+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57575+4 4 4 4 4 4
57576+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57577+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
57578+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57579+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
57580+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
57581+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
57582+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
57583+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
57584+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57585+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57586+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57589+4 4 4 4 4 4
57590+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
57591+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
57592+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
57593+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
57594+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
57595+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
57596+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57597+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
57598+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57599+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57600+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57603+4 4 4 4 4 4
57604+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57605+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
57606+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
57607+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
57608+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
57609+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
57610+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57611+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
57612+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57613+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57614+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57617+4 4 4 4 4 4
57618+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
57619+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
57620+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
57621+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
57622+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
57623+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
57624+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
57625+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
57626+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
57627+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57628+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57631+4 4 4 4 4 4
57632+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57633+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
57634+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
57635+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
57636+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
57637+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
57638+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
57639+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
57640+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
57641+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57642+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57645+4 4 4 4 4 4
57646+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
57647+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
57648+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
57649+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
57650+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
57651+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
57652+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
57653+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
57654+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
57655+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57656+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57659+4 4 4 4 4 4
57660+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57661+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
57662+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
57663+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
57664+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
57665+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
57666+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
57667+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
57668+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
57669+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57670+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57673+4 4 4 4 4 4
57674+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
57675+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
57676+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
57677+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
57678+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
57679+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
57680+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
57681+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
57682+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
57683+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
57684+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57687+4 4 4 4 4 4
57688+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
57689+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
57690+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
57691+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
57692+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
57693+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
57694+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
57695+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
57696+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
57697+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
57698+0 0 0 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 4 4 4 4 4 4 4 4 4 4 4 4
57701+4 4 4 4 4 4
57702+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
57703+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
57704+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
57705+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
57706+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
57707+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
57708+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57709+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
57710+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
57711+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
57712+4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57715+4 4 4 4 4 4
57716+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
57717+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
57718+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
57719+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
57720+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
57721+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
57722+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
57723+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
57724+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
57725+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
57726+5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57729+4 4 4 4 4 4
57730+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
57731+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
57732+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
57733+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
57734+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
57735+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
57736+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
57737+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
57738+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
57739+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
57743+4 4 4 4 4 4
57744+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
57745+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
57746+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
57747+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
57748+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
57749+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
57750+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
57751+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
57752+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
57753+13 16 17 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
57757+4 4 4 4 4 4
57758+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
57759+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
57760+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
57761+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
57762+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
57763+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
57764+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
57765+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
57766+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
57767+4 0 0 4 0 0 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57771+4 4 4 4 4 4
57772+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
57773+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
57774+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
57775+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
57776+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
57777+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
57778+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
57779+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
57780+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
57781+4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57785+4 4 4 4 4 4
57786+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
57787+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
57788+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
57789+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
57790+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
57791+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
57792+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
57793+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
57794+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
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 4 4 4 4 4 4 4 4 4 4 4 4
57799+4 4 4 4 4 4
57800+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
57801+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
57802+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
57803+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
57804+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
57805+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
57806+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
57807+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
57808+4 0 0 4 0 0 4 0 0 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
57813+4 4 4 4 4 4
57814+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
57815+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
57816+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
57817+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
57818+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
57819+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
57820+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
57821+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
57822+4 0 0 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 4 4 4 4 4 4 4 4 4 4 4 4
57827+4 4 4 4 4 4
57828+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
57829+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
57830+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
57831+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
57832+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
57833+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
57834+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
57835+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
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 4 4 4 4 4 4 4 4 4 4 4 4
57841+4 4 4 4 4 4
57842+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
57843+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
57844+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
57845+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
57846+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
57847+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
57848+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
57849+6 6 6 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
57855+4 4 4 4 4 4
57856+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
57857+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
57858+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
57859+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
57860+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
57861+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
57862+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
57863+4 0 0 4 3 3 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
57869+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 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
57872+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
57873+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
57874+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
57875+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
57876+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
57877+6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57883+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 5 5 5 5 5 5 5 5 5
57886+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
57887+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
57888+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
57889+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
57890+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
57891+5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57897+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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
57901+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
57902+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
57903+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
57904+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
57905+4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57911+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 4 4 4 4 4 4 5 5 5
57915+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
57916+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
57917+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
57918+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
57925+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 4 4 4
57929+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
57930+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
57931+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
57932+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 4 4 4 4 4 4 4 4 4 4 4 4
57939+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 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
57944+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
57945+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
57946+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57953+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 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
57958+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
57959+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
57960+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57967+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 4 4 4 4 4 4 5 5 5
57972+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
57973+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
57974+6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57981+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 4 4 4 4 4 4
57986+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
57987+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
57988+4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
57995+4 4 4 4 4 4
57996+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57997+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57998+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57999+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58000+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
58001+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
58002+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58003+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58004+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58005+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58006+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58007+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58008+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58009+4 4 4 4 4 4
58010+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58011+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58012+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58013+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58014+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
58015+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
58016+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58017+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58018+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58019+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58020+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58021+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58022+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58023+4 4 4 4 4 4
58024+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58025+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58026+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58027+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58028+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
58029+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
58030+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58031+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58032+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58033+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58034+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58035+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58036+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58037+4 4 4 4 4 4
58038diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
58039index fef20db..d28b1ab 100644
58040--- a/drivers/xen/xenfs/xenstored.c
58041+++ b/drivers/xen/xenfs/xenstored.c
58042@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
58043 static int xsd_kva_open(struct inode *inode, struct file *file)
58044 {
58045 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
58046+#ifdef CONFIG_GRKERNSEC_HIDESYM
58047+ NULL);
58048+#else
58049 xen_store_interface);
58050+#endif
58051+
58052 if (!file->private_data)
58053 return -ENOMEM;
58054 return 0;
58055diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
58056index eb14e05..5156de7 100644
58057--- a/fs/9p/vfs_addr.c
58058+++ b/fs/9p/vfs_addr.c
58059@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
58060
58061 retval = v9fs_file_write_internal(inode,
58062 v9inode->writeback_fid,
58063- (__force const char __user *)buffer,
58064+ (const char __force_user *)buffer,
58065 len, &offset, 0);
58066 if (retval > 0)
58067 retval = 0;
58068diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
58069index 296482f..183ddc3 100644
58070--- a/fs/9p/vfs_inode.c
58071+++ b/fs/9p/vfs_inode.c
58072@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
58073 void
58074 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
58075 {
58076- char *s = nd_get_link(nd);
58077+ const char *s = nd_get_link(nd);
58078
58079 p9_debug(P9_DEBUG_VFS, " %pd %s\n",
58080 dentry, IS_ERR(s) ? "<error>" : s);
58081diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
58082index 370b24c..ff0be7b 100644
58083--- a/fs/Kconfig.binfmt
58084+++ b/fs/Kconfig.binfmt
58085@@ -103,7 +103,7 @@ config HAVE_AOUT
58086
58087 config BINFMT_AOUT
58088 tristate "Kernel support for a.out and ECOFF binaries"
58089- depends on HAVE_AOUT
58090+ depends on HAVE_AOUT && BROKEN
58091 ---help---
58092 A.out (Assembler.OUTput) is a set of formats for libraries and
58093 executables used in the earliest versions of UNIX. Linux used
58094diff --git a/fs/afs/inode.c b/fs/afs/inode.c
58095index 2946712..f737435 100644
58096--- a/fs/afs/inode.c
58097+++ b/fs/afs/inode.c
58098@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
58099 struct afs_vnode *vnode;
58100 struct super_block *sb;
58101 struct inode *inode;
58102- static atomic_t afs_autocell_ino;
58103+ static atomic_unchecked_t afs_autocell_ino;
58104
58105 _enter("{%x:%u},%*.*s,",
58106 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
58107@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
58108 data.fid.unique = 0;
58109 data.fid.vnode = 0;
58110
58111- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
58112+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
58113 afs_iget5_autocell_test, afs_iget5_set,
58114 &data);
58115 if (!inode) {
58116diff --git a/fs/aio.c b/fs/aio.c
58117index 14b9315..365980f 100644
58118--- a/fs/aio.c
58119+++ b/fs/aio.c
58120@@ -388,7 +388,7 @@ static int aio_setup_ring(struct kioctx *ctx)
58121 size += sizeof(struct io_event) * nr_events;
58122
58123 nr_pages = PFN_UP(size);
58124- if (nr_pages < 0)
58125+ if (nr_pages <= 0)
58126 return -EINVAL;
58127
58128 file = aio_private_file(ctx, nr_pages);
58129diff --git a/fs/attr.c b/fs/attr.c
58130index 6530ced..4a827e2 100644
58131--- a/fs/attr.c
58132+++ b/fs/attr.c
58133@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
58134 unsigned long limit;
58135
58136 limit = rlimit(RLIMIT_FSIZE);
58137+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
58138 if (limit != RLIM_INFINITY && offset > limit)
58139 goto out_sig;
58140 if (offset > inode->i_sb->s_maxbytes)
58141diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
58142index 116fd38..c04182da 100644
58143--- a/fs/autofs4/waitq.c
58144+++ b/fs/autofs4/waitq.c
58145@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
58146 {
58147 unsigned long sigpipe, flags;
58148 mm_segment_t fs;
58149- const char *data = (const char *)addr;
58150+ const char __user *data = (const char __force_user *)addr;
58151 ssize_t wr = 0;
58152
58153 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
58154@@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
58155 return 1;
58156 }
58157
58158+#ifdef CONFIG_GRKERNSEC_HIDESYM
58159+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
58160+#endif
58161+
58162 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
58163 enum autofs_notify notify)
58164 {
58165@@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
58166
58167 /* If this is a direct mount request create a dummy name */
58168 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
58169+#ifdef CONFIG_GRKERNSEC_HIDESYM
58170+ /* this name does get written to userland via autofs4_write() */
58171+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
58172+#else
58173 qstr.len = sprintf(name, "%p", dentry);
58174+#endif
58175 else {
58176 qstr.len = autofs4_getpath(sbi, dentry, &name);
58177 if (!qstr.len) {
58178diff --git a/fs/befs/endian.h b/fs/befs/endian.h
58179index 2722387..56059b5 100644
58180--- a/fs/befs/endian.h
58181+++ b/fs/befs/endian.h
58182@@ -11,7 +11,7 @@
58183
58184 #include <asm/byteorder.h>
58185
58186-static inline u64
58187+static inline u64 __intentional_overflow(-1)
58188 fs64_to_cpu(const struct super_block *sb, fs64 n)
58189 {
58190 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58191@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
58192 return (__force fs64)cpu_to_be64(n);
58193 }
58194
58195-static inline u32
58196+static inline u32 __intentional_overflow(-1)
58197 fs32_to_cpu(const struct super_block *sb, fs32 n)
58198 {
58199 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58200@@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
58201 return (__force fs32)cpu_to_be32(n);
58202 }
58203
58204-static inline u16
58205+static inline u16 __intentional_overflow(-1)
58206 fs16_to_cpu(const struct super_block *sb, fs16 n)
58207 {
58208 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58209diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
58210index 929dec0..84bd914 100644
58211--- a/fs/binfmt_aout.c
58212+++ b/fs/binfmt_aout.c
58213@@ -16,6 +16,7 @@
58214 #include <linux/string.h>
58215 #include <linux/fs.h>
58216 #include <linux/file.h>
58217+#include <linux/security.h>
58218 #include <linux/stat.h>
58219 #include <linux/fcntl.h>
58220 #include <linux/ptrace.h>
58221@@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
58222 #endif
58223 # define START_STACK(u) ((void __user *)u.start_stack)
58224
58225+ memset(&dump, 0, sizeof(dump));
58226+
58227 fs = get_fs();
58228 set_fs(KERNEL_DS);
58229 has_dumped = 1;
58230@@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
58231
58232 /* If the size of the dump file exceeds the rlimit, then see what would happen
58233 if we wrote the stack, but not the data area. */
58234+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
58235 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
58236 dump.u_dsize = 0;
58237
58238 /* Make sure we have enough room to write the stack and data areas. */
58239+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
58240 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
58241 dump.u_ssize = 0;
58242
58243@@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
58244 rlim = rlimit(RLIMIT_DATA);
58245 if (rlim >= RLIM_INFINITY)
58246 rlim = ~0;
58247+
58248+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
58249 if (ex.a_data + ex.a_bss > rlim)
58250 return -ENOMEM;
58251
58252@@ -261,6 +268,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
58253
58254 install_exec_creds(bprm);
58255
58256+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58257+ current->mm->pax_flags = 0UL;
58258+#endif
58259+
58260+#ifdef CONFIG_PAX_PAGEEXEC
58261+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
58262+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
58263+
58264+#ifdef CONFIG_PAX_EMUTRAMP
58265+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
58266+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
58267+#endif
58268+
58269+#ifdef CONFIG_PAX_MPROTECT
58270+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
58271+ current->mm->pax_flags |= MF_PAX_MPROTECT;
58272+#endif
58273+
58274+ }
58275+#endif
58276+
58277 if (N_MAGIC(ex) == OMAGIC) {
58278 unsigned long text_addr, map_size;
58279 loff_t pos;
58280@@ -312,7 +340,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
58281 return error;
58282
58283 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
58284- PROT_READ | PROT_WRITE | PROT_EXEC,
58285+ PROT_READ | PROT_WRITE,
58286 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
58287 fd_offset + ex.a_text);
58288 if (error != N_DATADDR(ex))
58289diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
58290index d8fc060..cbd44d5 100644
58291--- a/fs/binfmt_elf.c
58292+++ b/fs/binfmt_elf.c
58293@@ -34,6 +34,7 @@
58294 #include <linux/utsname.h>
58295 #include <linux/coredump.h>
58296 #include <linux/sched.h>
58297+#include <linux/xattr.h>
58298 #include <asm/uaccess.h>
58299 #include <asm/param.h>
58300 #include <asm/page.h>
58301@@ -47,7 +48,7 @@
58302
58303 static int load_elf_binary(struct linux_binprm *bprm);
58304 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
58305- int, int, unsigned long);
58306+ int, int, unsigned long) __intentional_overflow(-1);
58307
58308 #ifdef CONFIG_USELIB
58309 static int load_elf_library(struct file *);
58310@@ -65,6 +66,14 @@ static int elf_core_dump(struct coredump_params *cprm);
58311 #define elf_core_dump NULL
58312 #endif
58313
58314+#ifdef CONFIG_PAX_MPROTECT
58315+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
58316+#endif
58317+
58318+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58319+static void elf_handle_mmap(struct file *file);
58320+#endif
58321+
58322 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
58323 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
58324 #else
58325@@ -84,6 +93,15 @@ static struct linux_binfmt elf_format = {
58326 .load_binary = load_elf_binary,
58327 .load_shlib = load_elf_library,
58328 .core_dump = elf_core_dump,
58329+
58330+#ifdef CONFIG_PAX_MPROTECT
58331+ .handle_mprotect= elf_handle_mprotect,
58332+#endif
58333+
58334+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58335+ .handle_mmap = elf_handle_mmap,
58336+#endif
58337+
58338 .min_coredump = ELF_EXEC_PAGESIZE,
58339 };
58340
58341@@ -91,6 +109,8 @@ static struct linux_binfmt elf_format = {
58342
58343 static int set_brk(unsigned long start, unsigned long end)
58344 {
58345+ unsigned long e = end;
58346+
58347 start = ELF_PAGEALIGN(start);
58348 end = ELF_PAGEALIGN(end);
58349 if (end > start) {
58350@@ -99,7 +119,7 @@ static int set_brk(unsigned long start, unsigned long end)
58351 if (BAD_ADDR(addr))
58352 return addr;
58353 }
58354- current->mm->start_brk = current->mm->brk = end;
58355+ current->mm->start_brk = current->mm->brk = e;
58356 return 0;
58357 }
58358
58359@@ -160,12 +180,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58360 elf_addr_t __user *u_rand_bytes;
58361 const char *k_platform = ELF_PLATFORM;
58362 const char *k_base_platform = ELF_BASE_PLATFORM;
58363- unsigned char k_rand_bytes[16];
58364+ u32 k_rand_bytes[4];
58365 int items;
58366 elf_addr_t *elf_info;
58367 int ei_index = 0;
58368 const struct cred *cred = current_cred();
58369 struct vm_area_struct *vma;
58370+ unsigned long saved_auxv[AT_VECTOR_SIZE];
58371
58372 /*
58373 * In some cases (e.g. Hyper-Threading), we want to avoid L1
58374@@ -207,8 +228,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58375 * Generate 16 random bytes for userspace PRNG seeding.
58376 */
58377 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
58378- u_rand_bytes = (elf_addr_t __user *)
58379- STACK_ALLOC(p, sizeof(k_rand_bytes));
58380+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
58381+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
58382+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
58383+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
58384+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
58385+ u_rand_bytes = (elf_addr_t __user *) p;
58386 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
58387 return -EFAULT;
58388
58389@@ -323,9 +348,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58390 return -EFAULT;
58391 current->mm->env_end = p;
58392
58393+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
58394+
58395 /* Put the elf_info on the stack in the right place. */
58396 sp = (elf_addr_t __user *)envp + 1;
58397- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
58398+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
58399 return -EFAULT;
58400 return 0;
58401 }
58402@@ -393,15 +420,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
58403 an ELF header */
58404
58405 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58406- struct file *interpreter, unsigned long *interp_map_addr,
58407- unsigned long no_base)
58408+ struct file *interpreter, unsigned long no_base)
58409 {
58410 struct elf_phdr *elf_phdata;
58411 struct elf_phdr *eppnt;
58412- unsigned long load_addr = 0;
58413+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
58414 int load_addr_set = 0;
58415 unsigned long last_bss = 0, elf_bss = 0;
58416- unsigned long error = ~0UL;
58417+ unsigned long error = -EINVAL;
58418 unsigned long total_size;
58419 int retval, i, size;
58420
58421@@ -447,6 +473,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58422 goto out_close;
58423 }
58424
58425+#ifdef CONFIG_PAX_SEGMEXEC
58426+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
58427+ pax_task_size = SEGMEXEC_TASK_SIZE;
58428+#endif
58429+
58430 eppnt = elf_phdata;
58431 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
58432 if (eppnt->p_type == PT_LOAD) {
58433@@ -470,8 +501,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58434 map_addr = elf_map(interpreter, load_addr + vaddr,
58435 eppnt, elf_prot, elf_type, total_size);
58436 total_size = 0;
58437- if (!*interp_map_addr)
58438- *interp_map_addr = map_addr;
58439 error = map_addr;
58440 if (BAD_ADDR(map_addr))
58441 goto out_close;
58442@@ -490,8 +519,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58443 k = load_addr + eppnt->p_vaddr;
58444 if (BAD_ADDR(k) ||
58445 eppnt->p_filesz > eppnt->p_memsz ||
58446- eppnt->p_memsz > TASK_SIZE ||
58447- TASK_SIZE - eppnt->p_memsz < k) {
58448+ eppnt->p_memsz > pax_task_size ||
58449+ pax_task_size - eppnt->p_memsz < k) {
58450 error = -ENOMEM;
58451 goto out_close;
58452 }
58453@@ -530,9 +559,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58454 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
58455
58456 /* Map the last of the bss segment */
58457- error = vm_brk(elf_bss, last_bss - elf_bss);
58458- if (BAD_ADDR(error))
58459- goto out_close;
58460+ if (last_bss > elf_bss) {
58461+ error = vm_brk(elf_bss, last_bss - elf_bss);
58462+ if (BAD_ADDR(error))
58463+ goto out_close;
58464+ }
58465 }
58466
58467 error = load_addr;
58468@@ -543,6 +574,336 @@ out:
58469 return error;
58470 }
58471
58472+#ifdef CONFIG_PAX_PT_PAX_FLAGS
58473+#ifdef CONFIG_PAX_SOFTMODE
58474+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
58475+{
58476+ unsigned long pax_flags = 0UL;
58477+
58478+#ifdef CONFIG_PAX_PAGEEXEC
58479+ if (elf_phdata->p_flags & PF_PAGEEXEC)
58480+ pax_flags |= MF_PAX_PAGEEXEC;
58481+#endif
58482+
58483+#ifdef CONFIG_PAX_SEGMEXEC
58484+ if (elf_phdata->p_flags & PF_SEGMEXEC)
58485+ pax_flags |= MF_PAX_SEGMEXEC;
58486+#endif
58487+
58488+#ifdef CONFIG_PAX_EMUTRAMP
58489+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
58490+ pax_flags |= MF_PAX_EMUTRAMP;
58491+#endif
58492+
58493+#ifdef CONFIG_PAX_MPROTECT
58494+ if (elf_phdata->p_flags & PF_MPROTECT)
58495+ pax_flags |= MF_PAX_MPROTECT;
58496+#endif
58497+
58498+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58499+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
58500+ pax_flags |= MF_PAX_RANDMMAP;
58501+#endif
58502+
58503+ return pax_flags;
58504+}
58505+#endif
58506+
58507+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
58508+{
58509+ unsigned long pax_flags = 0UL;
58510+
58511+#ifdef CONFIG_PAX_PAGEEXEC
58512+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
58513+ pax_flags |= MF_PAX_PAGEEXEC;
58514+#endif
58515+
58516+#ifdef CONFIG_PAX_SEGMEXEC
58517+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
58518+ pax_flags |= MF_PAX_SEGMEXEC;
58519+#endif
58520+
58521+#ifdef CONFIG_PAX_EMUTRAMP
58522+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
58523+ pax_flags |= MF_PAX_EMUTRAMP;
58524+#endif
58525+
58526+#ifdef CONFIG_PAX_MPROTECT
58527+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
58528+ pax_flags |= MF_PAX_MPROTECT;
58529+#endif
58530+
58531+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58532+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
58533+ pax_flags |= MF_PAX_RANDMMAP;
58534+#endif
58535+
58536+ return pax_flags;
58537+}
58538+#endif
58539+
58540+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
58541+#ifdef CONFIG_PAX_SOFTMODE
58542+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
58543+{
58544+ unsigned long pax_flags = 0UL;
58545+
58546+#ifdef CONFIG_PAX_PAGEEXEC
58547+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
58548+ pax_flags |= MF_PAX_PAGEEXEC;
58549+#endif
58550+
58551+#ifdef CONFIG_PAX_SEGMEXEC
58552+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
58553+ pax_flags |= MF_PAX_SEGMEXEC;
58554+#endif
58555+
58556+#ifdef CONFIG_PAX_EMUTRAMP
58557+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
58558+ pax_flags |= MF_PAX_EMUTRAMP;
58559+#endif
58560+
58561+#ifdef CONFIG_PAX_MPROTECT
58562+ if (pax_flags_softmode & MF_PAX_MPROTECT)
58563+ pax_flags |= MF_PAX_MPROTECT;
58564+#endif
58565+
58566+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58567+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
58568+ pax_flags |= MF_PAX_RANDMMAP;
58569+#endif
58570+
58571+ return pax_flags;
58572+}
58573+#endif
58574+
58575+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
58576+{
58577+ unsigned long pax_flags = 0UL;
58578+
58579+#ifdef CONFIG_PAX_PAGEEXEC
58580+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
58581+ pax_flags |= MF_PAX_PAGEEXEC;
58582+#endif
58583+
58584+#ifdef CONFIG_PAX_SEGMEXEC
58585+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
58586+ pax_flags |= MF_PAX_SEGMEXEC;
58587+#endif
58588+
58589+#ifdef CONFIG_PAX_EMUTRAMP
58590+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
58591+ pax_flags |= MF_PAX_EMUTRAMP;
58592+#endif
58593+
58594+#ifdef CONFIG_PAX_MPROTECT
58595+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
58596+ pax_flags |= MF_PAX_MPROTECT;
58597+#endif
58598+
58599+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58600+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
58601+ pax_flags |= MF_PAX_RANDMMAP;
58602+#endif
58603+
58604+ return pax_flags;
58605+}
58606+#endif
58607+
58608+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58609+static unsigned long pax_parse_defaults(void)
58610+{
58611+ unsigned long pax_flags = 0UL;
58612+
58613+#ifdef CONFIG_PAX_SOFTMODE
58614+ if (pax_softmode)
58615+ return pax_flags;
58616+#endif
58617+
58618+#ifdef CONFIG_PAX_PAGEEXEC
58619+ pax_flags |= MF_PAX_PAGEEXEC;
58620+#endif
58621+
58622+#ifdef CONFIG_PAX_SEGMEXEC
58623+ pax_flags |= MF_PAX_SEGMEXEC;
58624+#endif
58625+
58626+#ifdef CONFIG_PAX_MPROTECT
58627+ pax_flags |= MF_PAX_MPROTECT;
58628+#endif
58629+
58630+#ifdef CONFIG_PAX_RANDMMAP
58631+ if (randomize_va_space)
58632+ pax_flags |= MF_PAX_RANDMMAP;
58633+#endif
58634+
58635+ return pax_flags;
58636+}
58637+
58638+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
58639+{
58640+ unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
58641+
58642+#ifdef CONFIG_PAX_EI_PAX
58643+
58644+#ifdef CONFIG_PAX_SOFTMODE
58645+ if (pax_softmode)
58646+ return pax_flags;
58647+#endif
58648+
58649+ pax_flags = 0UL;
58650+
58651+#ifdef CONFIG_PAX_PAGEEXEC
58652+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
58653+ pax_flags |= MF_PAX_PAGEEXEC;
58654+#endif
58655+
58656+#ifdef CONFIG_PAX_SEGMEXEC
58657+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
58658+ pax_flags |= MF_PAX_SEGMEXEC;
58659+#endif
58660+
58661+#ifdef CONFIG_PAX_EMUTRAMP
58662+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
58663+ pax_flags |= MF_PAX_EMUTRAMP;
58664+#endif
58665+
58666+#ifdef CONFIG_PAX_MPROTECT
58667+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
58668+ pax_flags |= MF_PAX_MPROTECT;
58669+#endif
58670+
58671+#ifdef CONFIG_PAX_ASLR
58672+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
58673+ pax_flags |= MF_PAX_RANDMMAP;
58674+#endif
58675+
58676+#endif
58677+
58678+ return pax_flags;
58679+
58680+}
58681+
58682+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
58683+{
58684+
58685+#ifdef CONFIG_PAX_PT_PAX_FLAGS
58686+ unsigned long i;
58687+
58688+ for (i = 0UL; i < elf_ex->e_phnum; i++)
58689+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
58690+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
58691+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
58692+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
58693+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
58694+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
58695+ return PAX_PARSE_FLAGS_FALLBACK;
58696+
58697+#ifdef CONFIG_PAX_SOFTMODE
58698+ if (pax_softmode)
58699+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
58700+ else
58701+#endif
58702+
58703+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
58704+ break;
58705+ }
58706+#endif
58707+
58708+ return PAX_PARSE_FLAGS_FALLBACK;
58709+}
58710+
58711+static unsigned long pax_parse_xattr_pax(struct file * const file)
58712+{
58713+
58714+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
58715+ ssize_t xattr_size, i;
58716+ unsigned char xattr_value[sizeof("pemrs") - 1];
58717+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
58718+
58719+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
58720+ if (xattr_size < 0 || xattr_size > sizeof xattr_value)
58721+ return PAX_PARSE_FLAGS_FALLBACK;
58722+
58723+ for (i = 0; i < xattr_size; i++)
58724+ switch (xattr_value[i]) {
58725+ default:
58726+ return PAX_PARSE_FLAGS_FALLBACK;
58727+
58728+#define parse_flag(option1, option2, flag) \
58729+ case option1: \
58730+ if (pax_flags_hardmode & MF_PAX_##flag) \
58731+ return PAX_PARSE_FLAGS_FALLBACK;\
58732+ pax_flags_hardmode |= MF_PAX_##flag; \
58733+ break; \
58734+ case option2: \
58735+ if (pax_flags_softmode & MF_PAX_##flag) \
58736+ return PAX_PARSE_FLAGS_FALLBACK;\
58737+ pax_flags_softmode |= MF_PAX_##flag; \
58738+ break;
58739+
58740+ parse_flag('p', 'P', PAGEEXEC);
58741+ parse_flag('e', 'E', EMUTRAMP);
58742+ parse_flag('m', 'M', MPROTECT);
58743+ parse_flag('r', 'R', RANDMMAP);
58744+ parse_flag('s', 'S', SEGMEXEC);
58745+
58746+#undef parse_flag
58747+ }
58748+
58749+ if (pax_flags_hardmode & pax_flags_softmode)
58750+ return PAX_PARSE_FLAGS_FALLBACK;
58751+
58752+#ifdef CONFIG_PAX_SOFTMODE
58753+ if (pax_softmode)
58754+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
58755+ else
58756+#endif
58757+
58758+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
58759+#else
58760+ return PAX_PARSE_FLAGS_FALLBACK;
58761+#endif
58762+
58763+}
58764+
58765+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
58766+{
58767+ unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
58768+
58769+ pax_flags = pax_parse_defaults();
58770+ ei_pax_flags = pax_parse_ei_pax(elf_ex);
58771+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
58772+ xattr_pax_flags = pax_parse_xattr_pax(file);
58773+
58774+ if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
58775+ xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
58776+ pt_pax_flags != xattr_pax_flags)
58777+ return -EINVAL;
58778+ if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
58779+ pax_flags = xattr_pax_flags;
58780+ else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
58781+ pax_flags = pt_pax_flags;
58782+ else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
58783+ pax_flags = ei_pax_flags;
58784+
58785+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
58786+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
58787+ if ((__supported_pte_mask & _PAGE_NX))
58788+ pax_flags &= ~MF_PAX_SEGMEXEC;
58789+ else
58790+ pax_flags &= ~MF_PAX_PAGEEXEC;
58791+ }
58792+#endif
58793+
58794+ if (0 > pax_check_flags(&pax_flags))
58795+ return -EINVAL;
58796+
58797+ current->mm->pax_flags = pax_flags;
58798+ return 0;
58799+}
58800+#endif
58801+
58802 /*
58803 * These are the functions used to load ELF style executables and shared
58804 * libraries. There is no binary dependent code anywhere else.
58805@@ -556,6 +917,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
58806 {
58807 unsigned int random_variable = 0;
58808
58809+#ifdef CONFIG_PAX_RANDUSTACK
58810+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
58811+ return stack_top - current->mm->delta_stack;
58812+#endif
58813+
58814 if ((current->flags & PF_RANDOMIZE) &&
58815 !(current->personality & ADDR_NO_RANDOMIZE)) {
58816 random_variable = get_random_int() & STACK_RND_MASK;
58817@@ -574,7 +940,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
58818 unsigned long load_addr = 0, load_bias = 0;
58819 int load_addr_set = 0;
58820 char * elf_interpreter = NULL;
58821- unsigned long error;
58822+ unsigned long error = 0;
58823 struct elf_phdr *elf_ppnt, *elf_phdata;
58824 unsigned long elf_bss, elf_brk;
58825 int retval, i;
58826@@ -589,6 +955,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
58827 struct elfhdr elf_ex;
58828 struct elfhdr interp_elf_ex;
58829 } *loc;
58830+ unsigned long pax_task_size;
58831
58832 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
58833 if (!loc) {
58834@@ -726,6 +1093,77 @@ static int load_elf_binary(struct linux_binprm *bprm)
58835 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
58836 may depend on the personality. */
58837 SET_PERSONALITY(loc->elf_ex);
58838+
58839+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58840+ current->mm->pax_flags = 0UL;
58841+#endif
58842+
58843+#ifdef CONFIG_PAX_DLRESOLVE
58844+ current->mm->call_dl_resolve = 0UL;
58845+#endif
58846+
58847+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
58848+ current->mm->call_syscall = 0UL;
58849+#endif
58850+
58851+#ifdef CONFIG_PAX_ASLR
58852+ current->mm->delta_mmap = 0UL;
58853+ current->mm->delta_stack = 0UL;
58854+#endif
58855+
58856+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58857+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
58858+ send_sig(SIGKILL, current, 0);
58859+ goto out_free_dentry;
58860+ }
58861+#endif
58862+
58863+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58864+ pax_set_initial_flags(bprm);
58865+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
58866+ if (pax_set_initial_flags_func)
58867+ (pax_set_initial_flags_func)(bprm);
58868+#endif
58869+
58870+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
58871+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
58872+ current->mm->context.user_cs_limit = PAGE_SIZE;
58873+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
58874+ }
58875+#endif
58876+
58877+#ifdef CONFIG_PAX_SEGMEXEC
58878+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
58879+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
58880+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
58881+ pax_task_size = SEGMEXEC_TASK_SIZE;
58882+ current->mm->def_flags |= VM_NOHUGEPAGE;
58883+ } else
58884+#endif
58885+
58886+ pax_task_size = TASK_SIZE;
58887+
58888+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
58889+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
58890+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
58891+ put_cpu();
58892+ }
58893+#endif
58894+
58895+#ifdef CONFIG_PAX_ASLR
58896+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
58897+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
58898+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
58899+ }
58900+#endif
58901+
58902+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58903+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
58904+ executable_stack = EXSTACK_DISABLE_X;
58905+ current->personality &= ~READ_IMPLIES_EXEC;
58906+ } else
58907+#endif
58908+
58909 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
58910 current->personality |= READ_IMPLIES_EXEC;
58911
58912@@ -811,6 +1249,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
58913 #else
58914 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
58915 #endif
58916+
58917+#ifdef CONFIG_PAX_RANDMMAP
58918+ /* PaX: randomize base address at the default exe base if requested */
58919+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
58920+#ifdef CONFIG_SPARC64
58921+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
58922+#else
58923+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
58924+#endif
58925+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
58926+ elf_flags |= MAP_FIXED;
58927+ }
58928+#endif
58929+
58930 }
58931
58932 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
58933@@ -842,9 +1294,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
58934 * allowed task size. Note that p_filesz must always be
58935 * <= p_memsz so it is only necessary to check p_memsz.
58936 */
58937- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
58938- elf_ppnt->p_memsz > TASK_SIZE ||
58939- TASK_SIZE - elf_ppnt->p_memsz < k) {
58940+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
58941+ elf_ppnt->p_memsz > pax_task_size ||
58942+ pax_task_size - elf_ppnt->p_memsz < k) {
58943 /* set_brk can never work. Avoid overflows. */
58944 retval = -EINVAL;
58945 goto out_free_dentry;
58946@@ -880,16 +1332,43 @@ static int load_elf_binary(struct linux_binprm *bprm)
58947 if (retval)
58948 goto out_free_dentry;
58949 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
58950- retval = -EFAULT; /* Nobody gets to see this, but.. */
58951- goto out_free_dentry;
58952+ /*
58953+ * This bss-zeroing can fail if the ELF
58954+ * file specifies odd protections. So
58955+ * we don't check the return value
58956+ */
58957 }
58958
58959+#ifdef CONFIG_PAX_RANDMMAP
58960+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
58961+ unsigned long start, size, flags;
58962+ vm_flags_t vm_flags;
58963+
58964+ start = ELF_PAGEALIGN(elf_brk);
58965+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
58966+ flags = MAP_FIXED | MAP_PRIVATE;
58967+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
58968+
58969+ down_write(&current->mm->mmap_sem);
58970+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
58971+ retval = -ENOMEM;
58972+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
58973+// if (current->personality & ADDR_NO_RANDOMIZE)
58974+// vm_flags |= VM_READ | VM_MAYREAD;
58975+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
58976+ retval = IS_ERR_VALUE(start) ? start : 0;
58977+ }
58978+ up_write(&current->mm->mmap_sem);
58979+ if (retval == 0)
58980+ retval = set_brk(start + size, start + size + PAGE_SIZE);
58981+ if (retval < 0)
58982+ goto out_free_dentry;
58983+ }
58984+#endif
58985+
58986 if (elf_interpreter) {
58987- unsigned long interp_map_addr = 0;
58988-
58989 elf_entry = load_elf_interp(&loc->interp_elf_ex,
58990 interpreter,
58991- &interp_map_addr,
58992 load_bias);
58993 if (!IS_ERR((void *)elf_entry)) {
58994 /*
58995@@ -1115,7 +1594,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
58996 * Decide what to dump of a segment, part, all or none.
58997 */
58998 static unsigned long vma_dump_size(struct vm_area_struct *vma,
58999- unsigned long mm_flags)
59000+ unsigned long mm_flags, long signr)
59001 {
59002 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
59003
59004@@ -1153,7 +1632,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
59005 if (vma->vm_file == NULL)
59006 return 0;
59007
59008- if (FILTER(MAPPED_PRIVATE))
59009+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
59010 goto whole;
59011
59012 /*
59013@@ -1360,9 +1839,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
59014 {
59015 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
59016 int i = 0;
59017- do
59018+ do {
59019 i += 2;
59020- while (auxv[i - 2] != AT_NULL);
59021+ } while (auxv[i - 2] != AT_NULL);
59022 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
59023 }
59024
59025@@ -1371,7 +1850,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
59026 {
59027 mm_segment_t old_fs = get_fs();
59028 set_fs(KERNEL_DS);
59029- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
59030+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
59031 set_fs(old_fs);
59032 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
59033 }
59034@@ -1995,14 +2474,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
59035 }
59036
59037 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
59038- unsigned long mm_flags)
59039+ struct coredump_params *cprm)
59040 {
59041 struct vm_area_struct *vma;
59042 size_t size = 0;
59043
59044 for (vma = first_vma(current, gate_vma); vma != NULL;
59045 vma = next_vma(vma, gate_vma))
59046- size += vma_dump_size(vma, mm_flags);
59047+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59048 return size;
59049 }
59050
59051@@ -2093,7 +2572,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59052
59053 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
59054
59055- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
59056+ offset += elf_core_vma_data_size(gate_vma, cprm);
59057 offset += elf_core_extra_data_size();
59058 e_shoff = offset;
59059
59060@@ -2121,7 +2600,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59061 phdr.p_offset = offset;
59062 phdr.p_vaddr = vma->vm_start;
59063 phdr.p_paddr = 0;
59064- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
59065+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59066 phdr.p_memsz = vma->vm_end - vma->vm_start;
59067 offset += phdr.p_filesz;
59068 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
59069@@ -2154,7 +2633,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59070 unsigned long addr;
59071 unsigned long end;
59072
59073- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
59074+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59075
59076 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
59077 struct page *page;
59078@@ -2195,6 +2674,167 @@ out:
59079
59080 #endif /* CONFIG_ELF_CORE */
59081
59082+#ifdef CONFIG_PAX_MPROTECT
59083+/* PaX: non-PIC ELF libraries need relocations on their executable segments
59084+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
59085+ * we'll remove VM_MAYWRITE for good on RELRO segments.
59086+ *
59087+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
59088+ * basis because we want to allow the common case and not the special ones.
59089+ */
59090+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
59091+{
59092+ struct elfhdr elf_h;
59093+ struct elf_phdr elf_p;
59094+ unsigned long i;
59095+ unsigned long oldflags;
59096+ bool is_textrel_rw, is_textrel_rx, is_relro;
59097+
59098+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
59099+ return;
59100+
59101+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
59102+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
59103+
59104+#ifdef CONFIG_PAX_ELFRELOCS
59105+ /* possible TEXTREL */
59106+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
59107+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
59108+#else
59109+ is_textrel_rw = false;
59110+ is_textrel_rx = false;
59111+#endif
59112+
59113+ /* possible RELRO */
59114+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
59115+
59116+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
59117+ return;
59118+
59119+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
59120+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
59121+
59122+#ifdef CONFIG_PAX_ETEXECRELOCS
59123+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
59124+#else
59125+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
59126+#endif
59127+
59128+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
59129+ !elf_check_arch(&elf_h) ||
59130+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
59131+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
59132+ return;
59133+
59134+ for (i = 0UL; i < elf_h.e_phnum; i++) {
59135+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
59136+ return;
59137+ switch (elf_p.p_type) {
59138+ case PT_DYNAMIC:
59139+ if (!is_textrel_rw && !is_textrel_rx)
59140+ continue;
59141+ i = 0UL;
59142+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
59143+ elf_dyn dyn;
59144+
59145+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
59146+ break;
59147+ if (dyn.d_tag == DT_NULL)
59148+ break;
59149+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
59150+ gr_log_textrel(vma);
59151+ if (is_textrel_rw)
59152+ vma->vm_flags |= VM_MAYWRITE;
59153+ else
59154+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
59155+ vma->vm_flags &= ~VM_MAYWRITE;
59156+ break;
59157+ }
59158+ i++;
59159+ }
59160+ is_textrel_rw = false;
59161+ is_textrel_rx = false;
59162+ continue;
59163+
59164+ case PT_GNU_RELRO:
59165+ if (!is_relro)
59166+ continue;
59167+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
59168+ vma->vm_flags &= ~VM_MAYWRITE;
59169+ is_relro = false;
59170+ continue;
59171+
59172+#ifdef CONFIG_PAX_PT_PAX_FLAGS
59173+ case PT_PAX_FLAGS: {
59174+ const char *msg_mprotect = "", *msg_emutramp = "";
59175+ char *buffer_lib, *buffer_exe;
59176+
59177+ if (elf_p.p_flags & PF_NOMPROTECT)
59178+ msg_mprotect = "MPROTECT disabled";
59179+
59180+#ifdef CONFIG_PAX_EMUTRAMP
59181+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
59182+ msg_emutramp = "EMUTRAMP enabled";
59183+#endif
59184+
59185+ if (!msg_mprotect[0] && !msg_emutramp[0])
59186+ continue;
59187+
59188+ if (!printk_ratelimit())
59189+ continue;
59190+
59191+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
59192+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
59193+ if (buffer_lib && buffer_exe) {
59194+ char *path_lib, *path_exe;
59195+
59196+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
59197+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
59198+
59199+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
59200+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
59201+
59202+ }
59203+ free_page((unsigned long)buffer_exe);
59204+ free_page((unsigned long)buffer_lib);
59205+ continue;
59206+ }
59207+#endif
59208+
59209+ }
59210+ }
59211+}
59212+#endif
59213+
59214+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59215+
59216+extern int grsec_enable_log_rwxmaps;
59217+
59218+static void elf_handle_mmap(struct file *file)
59219+{
59220+ struct elfhdr elf_h;
59221+ struct elf_phdr elf_p;
59222+ unsigned long i;
59223+
59224+ if (!grsec_enable_log_rwxmaps)
59225+ return;
59226+
59227+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
59228+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
59229+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
59230+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
59231+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
59232+ return;
59233+
59234+ for (i = 0UL; i < elf_h.e_phnum; i++) {
59235+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
59236+ return;
59237+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
59238+ gr_log_ptgnustack(file);
59239+ }
59240+}
59241+#endif
59242+
59243 static int __init init_elf_binfmt(void)
59244 {
59245 register_binfmt(&elf_format);
59246diff --git a/fs/block_dev.c b/fs/block_dev.c
59247index 1d9c9f3..2905786 100644
59248--- a/fs/block_dev.c
59249+++ b/fs/block_dev.c
59250@@ -697,7 +697,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
59251 else if (bdev->bd_contains == bdev)
59252 return true; /* is a whole device which isn't held */
59253
59254- else if (whole->bd_holder == bd_may_claim)
59255+ else if (whole->bd_holder == (void *)bd_may_claim)
59256 return true; /* is a partition of a device that is being partitioned */
59257 else if (whole->bd_holder != NULL)
59258 return false; /* is a partition of a held device */
59259diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
59260index 150822e..75bb326 100644
59261--- a/fs/btrfs/ctree.c
59262+++ b/fs/btrfs/ctree.c
59263@@ -1173,9 +1173,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
59264 free_extent_buffer(buf);
59265 add_root_to_dirty_list(root);
59266 } else {
59267- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
59268- parent_start = parent->start;
59269- else
59270+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
59271+ if (parent)
59272+ parent_start = parent->start;
59273+ else
59274+ parent_start = 0;
59275+ } else
59276 parent_start = 0;
59277
59278 WARN_ON(trans->transid != btrfs_header_generation(parent));
59279diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
59280index 054577b..9b342cc 100644
59281--- a/fs/btrfs/delayed-inode.c
59282+++ b/fs/btrfs/delayed-inode.c
59283@@ -462,7 +462,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
59284
59285 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
59286 {
59287- int seq = atomic_inc_return(&delayed_root->items_seq);
59288+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
59289 if ((atomic_dec_return(&delayed_root->items) <
59290 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
59291 waitqueue_active(&delayed_root->wait))
59292@@ -1412,7 +1412,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
59293
59294 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
59295 {
59296- int val = atomic_read(&delayed_root->items_seq);
59297+ int val = atomic_read_unchecked(&delayed_root->items_seq);
59298
59299 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
59300 return 1;
59301@@ -1436,7 +1436,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
59302 int seq;
59303 int ret;
59304
59305- seq = atomic_read(&delayed_root->items_seq);
59306+ seq = atomic_read_unchecked(&delayed_root->items_seq);
59307
59308 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
59309 if (ret)
59310diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
59311index f70119f..ab5894d 100644
59312--- a/fs/btrfs/delayed-inode.h
59313+++ b/fs/btrfs/delayed-inode.h
59314@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
59315 */
59316 struct list_head prepare_list;
59317 atomic_t items; /* for delayed items */
59318- atomic_t items_seq; /* for delayed items */
59319+ atomic_unchecked_t items_seq; /* for delayed items */
59320 int nodes; /* for delayed nodes */
59321 wait_queue_head_t wait;
59322 };
59323@@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
59324 struct btrfs_delayed_root *delayed_root)
59325 {
59326 atomic_set(&delayed_root->items, 0);
59327- atomic_set(&delayed_root->items_seq, 0);
59328+ atomic_set_unchecked(&delayed_root->items_seq, 0);
59329 delayed_root->nodes = 0;
59330 spin_lock_init(&delayed_root->lock);
59331 init_waitqueue_head(&delayed_root->wait);
59332diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
59333index 4399f0c..a34d8b4 100644
59334--- a/fs/btrfs/ioctl.c
59335+++ b/fs/btrfs/ioctl.c
59336@@ -3953,9 +3953,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
59337 for (i = 0; i < num_types; i++) {
59338 struct btrfs_space_info *tmp;
59339
59340+ /* Don't copy in more than we allocated */
59341 if (!slot_count)
59342 break;
59343
59344+ slot_count--;
59345+
59346 info = NULL;
59347 rcu_read_lock();
59348 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
59349@@ -3977,10 +3980,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
59350 memcpy(dest, &space, sizeof(space));
59351 dest++;
59352 space_args.total_spaces++;
59353- slot_count--;
59354 }
59355- if (!slot_count)
59356- break;
59357 }
59358 up_read(&info->groups_sem);
59359 }
59360diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
59361index 54bd91e..aefa810 100644
59362--- a/fs/btrfs/super.c
59363+++ b/fs/btrfs/super.c
59364@@ -271,7 +271,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
59365 function, line, errstr);
59366 return;
59367 }
59368- ACCESS_ONCE(trans->transaction->aborted) = errno;
59369+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
59370 /* Wake up anybody who may be waiting on this transaction */
59371 wake_up(&root->fs_info->transaction_wait);
59372 wake_up(&root->fs_info->transaction_blocked_wait);
59373diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
59374index b2e7bb4..3719201 100644
59375--- a/fs/btrfs/sysfs.c
59376+++ b/fs/btrfs/sysfs.c
59377@@ -480,7 +480,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
59378 for (set = 0; set < FEAT_MAX; set++) {
59379 int i;
59380 struct attribute *attrs[2];
59381- struct attribute_group agroup = {
59382+ attribute_group_no_const agroup = {
59383 .name = "features",
59384 .attrs = attrs,
59385 };
59386diff --git a/fs/btrfs/tests/free-space-tests.c b/fs/btrfs/tests/free-space-tests.c
59387index 2299bfd..4098e72 100644
59388--- a/fs/btrfs/tests/free-space-tests.c
59389+++ b/fs/btrfs/tests/free-space-tests.c
59390@@ -463,7 +463,9 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache)
59391 * extent entry.
59392 */
59393 use_bitmap_op = cache->free_space_ctl->op->use_bitmap;
59394- cache->free_space_ctl->op->use_bitmap = test_use_bitmap;
59395+ pax_open_kernel();
59396+ *(void **)&cache->free_space_ctl->op->use_bitmap = test_use_bitmap;
59397+ pax_close_kernel();
59398
59399 /*
59400 * Extent entry covering free space range [128Mb - 256Kb, 128Mb - 128Kb[
59401@@ -870,7 +872,9 @@ test_steal_space_from_bitmap_to_extent(struct btrfs_block_group_cache *cache)
59402 if (ret)
59403 return ret;
59404
59405- cache->free_space_ctl->op->use_bitmap = use_bitmap_op;
59406+ pax_open_kernel();
59407+ *(void **)&cache->free_space_ctl->op->use_bitmap = use_bitmap_op;
59408+ pax_close_kernel();
59409 __btrfs_remove_free_space_cache(cache->free_space_ctl);
59410
59411 return 0;
59412diff --git a/fs/btrfs/tree-log.h b/fs/btrfs/tree-log.h
59413index 154990c..d0cf699 100644
59414--- a/fs/btrfs/tree-log.h
59415+++ b/fs/btrfs/tree-log.h
59416@@ -43,7 +43,7 @@ static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx)
59417 static inline void btrfs_set_log_full_commit(struct btrfs_fs_info *fs_info,
59418 struct btrfs_trans_handle *trans)
59419 {
59420- ACCESS_ONCE(fs_info->last_trans_log_full_commit) = trans->transid;
59421+ ACCESS_ONCE_RW(fs_info->last_trans_log_full_commit) = trans->transid;
59422 }
59423
59424 static inline int btrfs_need_log_full_commit(struct btrfs_fs_info *fs_info,
59425diff --git a/fs/buffer.c b/fs/buffer.c
59426index 20805db..2e8fc69 100644
59427--- a/fs/buffer.c
59428+++ b/fs/buffer.c
59429@@ -3417,7 +3417,7 @@ void __init buffer_init(void)
59430 bh_cachep = kmem_cache_create("buffer_head",
59431 sizeof(struct buffer_head), 0,
59432 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
59433- SLAB_MEM_SPREAD),
59434+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
59435 NULL);
59436
59437 /*
59438diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
59439index fbb08e9..0fda764 100644
59440--- a/fs/cachefiles/bind.c
59441+++ b/fs/cachefiles/bind.c
59442@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
59443 args);
59444
59445 /* start by checking things over */
59446- ASSERT(cache->fstop_percent >= 0 &&
59447- cache->fstop_percent < cache->fcull_percent &&
59448+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
59449 cache->fcull_percent < cache->frun_percent &&
59450 cache->frun_percent < 100);
59451
59452- ASSERT(cache->bstop_percent >= 0 &&
59453- cache->bstop_percent < cache->bcull_percent &&
59454+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
59455 cache->bcull_percent < cache->brun_percent &&
59456 cache->brun_percent < 100);
59457
59458diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
59459index ce1b115..4a6852c 100644
59460--- a/fs/cachefiles/daemon.c
59461+++ b/fs/cachefiles/daemon.c
59462@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
59463 if (n > buflen)
59464 return -EMSGSIZE;
59465
59466- if (copy_to_user(_buffer, buffer, n) != 0)
59467+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
59468 return -EFAULT;
59469
59470 return n;
59471@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
59472 if (test_bit(CACHEFILES_DEAD, &cache->flags))
59473 return -EIO;
59474
59475- if (datalen < 0 || datalen > PAGE_SIZE - 1)
59476+ if (datalen > PAGE_SIZE - 1)
59477 return -EOPNOTSUPP;
59478
59479 /* drag the command string into the kernel so we can parse it */
59480@@ -385,7 +385,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
59481 if (args[0] != '%' || args[1] != '\0')
59482 return -EINVAL;
59483
59484- if (fstop < 0 || fstop >= cache->fcull_percent)
59485+ if (fstop >= cache->fcull_percent)
59486 return cachefiles_daemon_range_error(cache, args);
59487
59488 cache->fstop_percent = fstop;
59489@@ -457,7 +457,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
59490 if (args[0] != '%' || args[1] != '\0')
59491 return -EINVAL;
59492
59493- if (bstop < 0 || bstop >= cache->bcull_percent)
59494+ if (bstop >= cache->bcull_percent)
59495 return cachefiles_daemon_range_error(cache, args);
59496
59497 cache->bstop_percent = bstop;
59498diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
59499index 8c52472..c4e3a69 100644
59500--- a/fs/cachefiles/internal.h
59501+++ b/fs/cachefiles/internal.h
59502@@ -66,7 +66,7 @@ struct cachefiles_cache {
59503 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
59504 struct rb_root active_nodes; /* active nodes (can't be culled) */
59505 rwlock_t active_lock; /* lock for active_nodes */
59506- atomic_t gravecounter; /* graveyard uniquifier */
59507+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
59508 unsigned frun_percent; /* when to stop culling (% files) */
59509 unsigned fcull_percent; /* when to start culling (% files) */
59510 unsigned fstop_percent; /* when to stop allocating (% files) */
59511@@ -178,19 +178,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
59512 * proc.c
59513 */
59514 #ifdef CONFIG_CACHEFILES_HISTOGRAM
59515-extern atomic_t cachefiles_lookup_histogram[HZ];
59516-extern atomic_t cachefiles_mkdir_histogram[HZ];
59517-extern atomic_t cachefiles_create_histogram[HZ];
59518+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
59519+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
59520+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
59521
59522 extern int __init cachefiles_proc_init(void);
59523 extern void cachefiles_proc_cleanup(void);
59524 static inline
59525-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
59526+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
59527 {
59528 unsigned long jif = jiffies - start_jif;
59529 if (jif >= HZ)
59530 jif = HZ - 1;
59531- atomic_inc(&histogram[jif]);
59532+ atomic_inc_unchecked(&histogram[jif]);
59533 }
59534
59535 #else
59536diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
59537index e12f189..ed17244 100644
59538--- a/fs/cachefiles/namei.c
59539+++ b/fs/cachefiles/namei.c
59540@@ -312,7 +312,7 @@ try_again:
59541 /* first step is to make up a grave dentry in the graveyard */
59542 sprintf(nbuffer, "%08x%08x",
59543 (uint32_t) get_seconds(),
59544- (uint32_t) atomic_inc_return(&cache->gravecounter));
59545+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
59546
59547 /* do the multiway lock magic */
59548 trap = lock_rename(cache->graveyard, dir);
59549diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
59550index eccd339..4c1d995 100644
59551--- a/fs/cachefiles/proc.c
59552+++ b/fs/cachefiles/proc.c
59553@@ -14,9 +14,9 @@
59554 #include <linux/seq_file.h>
59555 #include "internal.h"
59556
59557-atomic_t cachefiles_lookup_histogram[HZ];
59558-atomic_t cachefiles_mkdir_histogram[HZ];
59559-atomic_t cachefiles_create_histogram[HZ];
59560+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
59561+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
59562+atomic_unchecked_t cachefiles_create_histogram[HZ];
59563
59564 /*
59565 * display the latency histogram
59566@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
59567 return 0;
59568 default:
59569 index = (unsigned long) v - 3;
59570- x = atomic_read(&cachefiles_lookup_histogram[index]);
59571- y = atomic_read(&cachefiles_mkdir_histogram[index]);
59572- z = atomic_read(&cachefiles_create_histogram[index]);
59573+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
59574+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
59575+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
59576 if (x == 0 && y == 0 && z == 0)
59577 return 0;
59578
59579diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
59580index 695e788..f4a9d4d 100644
59581--- a/fs/ceph/dir.c
59582+++ b/fs/ceph/dir.c
59583@@ -129,6 +129,8 @@ static int __dcache_readdir(struct file *file, struct dir_context *ctx,
59584 struct dentry *dentry, *last;
59585 struct ceph_dentry_info *di;
59586 int err = 0;
59587+ char d_name[DNAME_INLINE_LEN];
59588+ const unsigned char *name;
59589
59590 /* claim ref on last dentry we returned */
59591 last = fi->dentry;
59592@@ -192,7 +194,12 @@ more:
59593
59594 dout(" %llu (%llu) dentry %p %.*s %p\n", di->offset, ctx->pos,
59595 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
59596- if (!dir_emit(ctx, dentry->d_name.name,
59597+ name = dentry->d_name.name;
59598+ if (name == dentry->d_iname) {
59599+ memcpy(d_name, name, dentry->d_name.len);
59600+ name = d_name;
59601+ }
59602+ if (!dir_emit(ctx, name,
59603 dentry->d_name.len,
59604 ceph_translate_ino(dentry->d_sb, dentry->d_inode->i_ino),
59605 dentry->d_inode->i_mode >> 12)) {
59606@@ -250,7 +257,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
59607 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
59608 struct ceph_mds_client *mdsc = fsc->mdsc;
59609 unsigned frag = fpos_frag(ctx->pos);
59610- int off = fpos_off(ctx->pos);
59611+ unsigned int off = fpos_off(ctx->pos);
59612 int err;
59613 u32 ftype;
59614 struct ceph_mds_reply_info_parsed *rinfo;
59615diff --git a/fs/ceph/super.c b/fs/ceph/super.c
59616index f6e1237..796ffd1 100644
59617--- a/fs/ceph/super.c
59618+++ b/fs/ceph/super.c
59619@@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
59620 /*
59621 * construct our own bdi so we can control readahead, etc.
59622 */
59623-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
59624+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
59625
59626 static int ceph_register_bdi(struct super_block *sb,
59627 struct ceph_fs_client *fsc)
59628@@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
59629 default_backing_dev_info.ra_pages;
59630
59631 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
59632- atomic_long_inc_return(&bdi_seq));
59633+ atomic_long_inc_return_unchecked(&bdi_seq));
59634 if (!err)
59635 sb->s_bdi = &fsc->backing_dev_info;
59636 return err;
59637diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
59638index 44ec726..bcb06a3 100644
59639--- a/fs/cifs/cifs_debug.c
59640+++ b/fs/cifs/cifs_debug.c
59641@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
59642
59643 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
59644 #ifdef CONFIG_CIFS_STATS2
59645- atomic_set(&totBufAllocCount, 0);
59646- atomic_set(&totSmBufAllocCount, 0);
59647+ atomic_set_unchecked(&totBufAllocCount, 0);
59648+ atomic_set_unchecked(&totSmBufAllocCount, 0);
59649 #endif /* CONFIG_CIFS_STATS2 */
59650 spin_lock(&cifs_tcp_ses_lock);
59651 list_for_each(tmp1, &cifs_tcp_ses_list) {
59652@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
59653 tcon = list_entry(tmp3,
59654 struct cifs_tcon,
59655 tcon_list);
59656- atomic_set(&tcon->num_smbs_sent, 0);
59657+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
59658 if (server->ops->clear_stats)
59659 server->ops->clear_stats(tcon);
59660 }
59661@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
59662 smBufAllocCount.counter, cifs_min_small);
59663 #ifdef CONFIG_CIFS_STATS2
59664 seq_printf(m, "Total Large %d Small %d Allocations\n",
59665- atomic_read(&totBufAllocCount),
59666- atomic_read(&totSmBufAllocCount));
59667+ atomic_read_unchecked(&totBufAllocCount),
59668+ atomic_read_unchecked(&totSmBufAllocCount));
59669 #endif /* CONFIG_CIFS_STATS2 */
59670
59671 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
59672@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
59673 if (tcon->need_reconnect)
59674 seq_puts(m, "\tDISCONNECTED ");
59675 seq_printf(m, "\nSMBs: %d",
59676- atomic_read(&tcon->num_smbs_sent));
59677+ atomic_read_unchecked(&tcon->num_smbs_sent));
59678 if (server->ops->print_stats)
59679 server->ops->print_stats(m, tcon);
59680 }
59681diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
59682index 9d7996e..35ad5cf4 100644
59683--- a/fs/cifs/cifsfs.c
59684+++ b/fs/cifs/cifsfs.c
59685@@ -1093,7 +1093,7 @@ cifs_init_request_bufs(void)
59686 */
59687 cifs_req_cachep = kmem_cache_create("cifs_request",
59688 CIFSMaxBufSize + max_hdr_size, 0,
59689- SLAB_HWCACHE_ALIGN, NULL);
59690+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
59691 if (cifs_req_cachep == NULL)
59692 return -ENOMEM;
59693
59694@@ -1120,7 +1120,7 @@ cifs_init_request_bufs(void)
59695 efficient to alloc 1 per page off the slab compared to 17K (5page)
59696 alloc of large cifs buffers even when page debugging is on */
59697 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
59698- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
59699+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
59700 NULL);
59701 if (cifs_sm_req_cachep == NULL) {
59702 mempool_destroy(cifs_req_poolp);
59703@@ -1205,8 +1205,8 @@ init_cifs(void)
59704 atomic_set(&bufAllocCount, 0);
59705 atomic_set(&smBufAllocCount, 0);
59706 #ifdef CONFIG_CIFS_STATS2
59707- atomic_set(&totBufAllocCount, 0);
59708- atomic_set(&totSmBufAllocCount, 0);
59709+ atomic_set_unchecked(&totBufAllocCount, 0);
59710+ atomic_set_unchecked(&totSmBufAllocCount, 0);
59711 #endif /* CONFIG_CIFS_STATS2 */
59712
59713 atomic_set(&midCount, 0);
59714diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
59715index 02a33e5..3a28b5a 100644
59716--- a/fs/cifs/cifsglob.h
59717+++ b/fs/cifs/cifsglob.h
59718@@ -823,35 +823,35 @@ struct cifs_tcon {
59719 __u16 Flags; /* optional support bits */
59720 enum statusEnum tidStatus;
59721 #ifdef CONFIG_CIFS_STATS
59722- atomic_t num_smbs_sent;
59723+ atomic_unchecked_t num_smbs_sent;
59724 union {
59725 struct {
59726- atomic_t num_writes;
59727- atomic_t num_reads;
59728- atomic_t num_flushes;
59729- atomic_t num_oplock_brks;
59730- atomic_t num_opens;
59731- atomic_t num_closes;
59732- atomic_t num_deletes;
59733- atomic_t num_mkdirs;
59734- atomic_t num_posixopens;
59735- atomic_t num_posixmkdirs;
59736- atomic_t num_rmdirs;
59737- atomic_t num_renames;
59738- atomic_t num_t2renames;
59739- atomic_t num_ffirst;
59740- atomic_t num_fnext;
59741- atomic_t num_fclose;
59742- atomic_t num_hardlinks;
59743- atomic_t num_symlinks;
59744- atomic_t num_locks;
59745- atomic_t num_acl_get;
59746- atomic_t num_acl_set;
59747+ atomic_unchecked_t num_writes;
59748+ atomic_unchecked_t num_reads;
59749+ atomic_unchecked_t num_flushes;
59750+ atomic_unchecked_t num_oplock_brks;
59751+ atomic_unchecked_t num_opens;
59752+ atomic_unchecked_t num_closes;
59753+ atomic_unchecked_t num_deletes;
59754+ atomic_unchecked_t num_mkdirs;
59755+ atomic_unchecked_t num_posixopens;
59756+ atomic_unchecked_t num_posixmkdirs;
59757+ atomic_unchecked_t num_rmdirs;
59758+ atomic_unchecked_t num_renames;
59759+ atomic_unchecked_t num_t2renames;
59760+ atomic_unchecked_t num_ffirst;
59761+ atomic_unchecked_t num_fnext;
59762+ atomic_unchecked_t num_fclose;
59763+ atomic_unchecked_t num_hardlinks;
59764+ atomic_unchecked_t num_symlinks;
59765+ atomic_unchecked_t num_locks;
59766+ atomic_unchecked_t num_acl_get;
59767+ atomic_unchecked_t num_acl_set;
59768 } cifs_stats;
59769 #ifdef CONFIG_CIFS_SMB2
59770 struct {
59771- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
59772- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
59773+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
59774+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
59775 } smb2_stats;
59776 #endif /* CONFIG_CIFS_SMB2 */
59777 } stats;
59778@@ -1192,7 +1192,7 @@ convert_delimiter(char *path, char delim)
59779 }
59780
59781 #ifdef CONFIG_CIFS_STATS
59782-#define cifs_stats_inc atomic_inc
59783+#define cifs_stats_inc atomic_inc_unchecked
59784
59785 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
59786 unsigned int bytes)
59787@@ -1559,8 +1559,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
59788 /* Various Debug counters */
59789 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
59790 #ifdef CONFIG_CIFS_STATS2
59791-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
59792-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
59793+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
59794+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
59795 #endif
59796 GLOBAL_EXTERN atomic_t smBufAllocCount;
59797 GLOBAL_EXTERN atomic_t midCount;
59798diff --git a/fs/cifs/file.c b/fs/cifs/file.c
59799index 3e4d00a..38a122d 100644
59800--- a/fs/cifs/file.c
59801+++ b/fs/cifs/file.c
59802@@ -2056,10 +2056,14 @@ static int cifs_writepages(struct address_space *mapping,
59803 index = mapping->writeback_index; /* Start from prev offset */
59804 end = -1;
59805 } else {
59806- index = wbc->range_start >> PAGE_CACHE_SHIFT;
59807- end = wbc->range_end >> PAGE_CACHE_SHIFT;
59808- if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
59809+ if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
59810 range_whole = true;
59811+ index = 0;
59812+ end = ULONG_MAX;
59813+ } else {
59814+ index = wbc->range_start >> PAGE_CACHE_SHIFT;
59815+ end = wbc->range_end >> PAGE_CACHE_SHIFT;
59816+ }
59817 scanned = true;
59818 }
59819 server = cifs_sb_master_tcon(cifs_sb)->ses->server;
59820diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
59821index b7415d5..3984ec0 100644
59822--- a/fs/cifs/misc.c
59823+++ b/fs/cifs/misc.c
59824@@ -170,7 +170,7 @@ cifs_buf_get(void)
59825 memset(ret_buf, 0, buf_size + 3);
59826 atomic_inc(&bufAllocCount);
59827 #ifdef CONFIG_CIFS_STATS2
59828- atomic_inc(&totBufAllocCount);
59829+ atomic_inc_unchecked(&totBufAllocCount);
59830 #endif /* CONFIG_CIFS_STATS2 */
59831 }
59832
59833@@ -205,7 +205,7 @@ cifs_small_buf_get(void)
59834 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
59835 atomic_inc(&smBufAllocCount);
59836 #ifdef CONFIG_CIFS_STATS2
59837- atomic_inc(&totSmBufAllocCount);
59838+ atomic_inc_unchecked(&totSmBufAllocCount);
59839 #endif /* CONFIG_CIFS_STATS2 */
59840
59841 }
59842diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
59843index d297903..1cb7516 100644
59844--- a/fs/cifs/smb1ops.c
59845+++ b/fs/cifs/smb1ops.c
59846@@ -622,27 +622,27 @@ static void
59847 cifs_clear_stats(struct cifs_tcon *tcon)
59848 {
59849 #ifdef CONFIG_CIFS_STATS
59850- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
59851- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
59852- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
59853- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
59854- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
59855- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
59856- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
59857- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
59858- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
59859- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
59860- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
59861- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
59862- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
59863- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
59864- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
59865- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
59866- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
59867- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
59868- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
59869- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
59870- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
59871+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
59872+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
59873+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
59874+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
59875+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
59876+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
59877+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
59878+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
59879+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
59880+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
59881+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
59882+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
59883+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
59884+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
59885+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
59886+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
59887+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
59888+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
59889+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
59890+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
59891+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
59892 #endif
59893 }
59894
59895@@ -651,36 +651,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
59896 {
59897 #ifdef CONFIG_CIFS_STATS
59898 seq_printf(m, " Oplocks breaks: %d",
59899- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
59900+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
59901 seq_printf(m, "\nReads: %d Bytes: %llu",
59902- atomic_read(&tcon->stats.cifs_stats.num_reads),
59903+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
59904 (long long)(tcon->bytes_read));
59905 seq_printf(m, "\nWrites: %d Bytes: %llu",
59906- atomic_read(&tcon->stats.cifs_stats.num_writes),
59907+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
59908 (long long)(tcon->bytes_written));
59909 seq_printf(m, "\nFlushes: %d",
59910- atomic_read(&tcon->stats.cifs_stats.num_flushes));
59911+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
59912 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
59913- atomic_read(&tcon->stats.cifs_stats.num_locks),
59914- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
59915- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
59916+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
59917+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
59918+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
59919 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
59920- atomic_read(&tcon->stats.cifs_stats.num_opens),
59921- atomic_read(&tcon->stats.cifs_stats.num_closes),
59922- atomic_read(&tcon->stats.cifs_stats.num_deletes));
59923+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
59924+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
59925+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
59926 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
59927- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
59928- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
59929+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
59930+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
59931 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
59932- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
59933- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
59934+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
59935+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
59936 seq_printf(m, "\nRenames: %d T2 Renames %d",
59937- atomic_read(&tcon->stats.cifs_stats.num_renames),
59938- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
59939+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
59940+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
59941 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
59942- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
59943- atomic_read(&tcon->stats.cifs_stats.num_fnext),
59944- atomic_read(&tcon->stats.cifs_stats.num_fclose));
59945+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
59946+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
59947+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
59948 #endif
59949 }
59950
59951diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
59952index c5f521b..1a40865 100644
59953--- a/fs/cifs/smb2ops.c
59954+++ b/fs/cifs/smb2ops.c
59955@@ -417,8 +417,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
59956 #ifdef CONFIG_CIFS_STATS
59957 int i;
59958 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
59959- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
59960- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
59961+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
59962+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
59963 }
59964 #endif
59965 }
59966@@ -458,65 +458,65 @@ static void
59967 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
59968 {
59969 #ifdef CONFIG_CIFS_STATS
59970- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
59971- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
59972+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
59973+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
59974 seq_printf(m, "\nNegotiates: %d sent %d failed",
59975- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
59976- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
59977+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
59978+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
59979 seq_printf(m, "\nSessionSetups: %d sent %d failed",
59980- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
59981- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
59982+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
59983+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
59984 seq_printf(m, "\nLogoffs: %d sent %d failed",
59985- atomic_read(&sent[SMB2_LOGOFF_HE]),
59986- atomic_read(&failed[SMB2_LOGOFF_HE]));
59987+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
59988+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
59989 seq_printf(m, "\nTreeConnects: %d sent %d failed",
59990- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
59991- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
59992+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
59993+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
59994 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
59995- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
59996- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
59997+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
59998+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
59999 seq_printf(m, "\nCreates: %d sent %d failed",
60000- atomic_read(&sent[SMB2_CREATE_HE]),
60001- atomic_read(&failed[SMB2_CREATE_HE]));
60002+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
60003+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
60004 seq_printf(m, "\nCloses: %d sent %d failed",
60005- atomic_read(&sent[SMB2_CLOSE_HE]),
60006- atomic_read(&failed[SMB2_CLOSE_HE]));
60007+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
60008+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
60009 seq_printf(m, "\nFlushes: %d sent %d failed",
60010- atomic_read(&sent[SMB2_FLUSH_HE]),
60011- atomic_read(&failed[SMB2_FLUSH_HE]));
60012+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
60013+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
60014 seq_printf(m, "\nReads: %d sent %d failed",
60015- atomic_read(&sent[SMB2_READ_HE]),
60016- atomic_read(&failed[SMB2_READ_HE]));
60017+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
60018+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
60019 seq_printf(m, "\nWrites: %d sent %d failed",
60020- atomic_read(&sent[SMB2_WRITE_HE]),
60021- atomic_read(&failed[SMB2_WRITE_HE]));
60022+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
60023+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
60024 seq_printf(m, "\nLocks: %d sent %d failed",
60025- atomic_read(&sent[SMB2_LOCK_HE]),
60026- atomic_read(&failed[SMB2_LOCK_HE]));
60027+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
60028+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
60029 seq_printf(m, "\nIOCTLs: %d sent %d failed",
60030- atomic_read(&sent[SMB2_IOCTL_HE]),
60031- atomic_read(&failed[SMB2_IOCTL_HE]));
60032+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
60033+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
60034 seq_printf(m, "\nCancels: %d sent %d failed",
60035- atomic_read(&sent[SMB2_CANCEL_HE]),
60036- atomic_read(&failed[SMB2_CANCEL_HE]));
60037+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
60038+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
60039 seq_printf(m, "\nEchos: %d sent %d failed",
60040- atomic_read(&sent[SMB2_ECHO_HE]),
60041- atomic_read(&failed[SMB2_ECHO_HE]));
60042+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
60043+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
60044 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
60045- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
60046- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
60047+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
60048+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
60049 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
60050- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
60051- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
60052+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
60053+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
60054 seq_printf(m, "\nQueryInfos: %d sent %d failed",
60055- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
60056- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
60057+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
60058+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
60059 seq_printf(m, "\nSetInfos: %d sent %d failed",
60060- atomic_read(&sent[SMB2_SET_INFO_HE]),
60061- atomic_read(&failed[SMB2_SET_INFO_HE]));
60062+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
60063+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
60064 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
60065- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
60066- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
60067+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
60068+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
60069 #endif
60070 }
60071
60072diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
60073index 8f1672b..af339c07 100644
60074--- a/fs/cifs/smb2pdu.c
60075+++ b/fs/cifs/smb2pdu.c
60076@@ -2145,8 +2145,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
60077 default:
60078 cifs_dbg(VFS, "info level %u isn't supported\n",
60079 srch_inf->info_level);
60080- rc = -EINVAL;
60081- goto qdir_exit;
60082+ return -EINVAL;
60083 }
60084
60085 req->FileIndex = cpu_to_le32(index);
60086diff --git a/fs/coda/cache.c b/fs/coda/cache.c
60087index 46ee6f2..89a9e7f 100644
60088--- a/fs/coda/cache.c
60089+++ b/fs/coda/cache.c
60090@@ -24,7 +24,7 @@
60091 #include "coda_linux.h"
60092 #include "coda_cache.h"
60093
60094-static atomic_t permission_epoch = ATOMIC_INIT(0);
60095+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
60096
60097 /* replace or extend an acl cache hit */
60098 void coda_cache_enter(struct inode *inode, int mask)
60099@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
60100 struct coda_inode_info *cii = ITOC(inode);
60101
60102 spin_lock(&cii->c_lock);
60103- cii->c_cached_epoch = atomic_read(&permission_epoch);
60104+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
60105 if (!uid_eq(cii->c_uid, current_fsuid())) {
60106 cii->c_uid = current_fsuid();
60107 cii->c_cached_perm = mask;
60108@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
60109 {
60110 struct coda_inode_info *cii = ITOC(inode);
60111 spin_lock(&cii->c_lock);
60112- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
60113+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
60114 spin_unlock(&cii->c_lock);
60115 }
60116
60117 /* remove all acl caches */
60118 void coda_cache_clear_all(struct super_block *sb)
60119 {
60120- atomic_inc(&permission_epoch);
60121+ atomic_inc_unchecked(&permission_epoch);
60122 }
60123
60124
60125@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
60126 spin_lock(&cii->c_lock);
60127 hit = (mask & cii->c_cached_perm) == mask &&
60128 uid_eq(cii->c_uid, current_fsuid()) &&
60129- cii->c_cached_epoch == atomic_read(&permission_epoch);
60130+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
60131 spin_unlock(&cii->c_lock);
60132
60133 return hit;
60134diff --git a/fs/compat.c b/fs/compat.c
60135index b13df99..6f6f4a3 100644
60136--- a/fs/compat.c
60137+++ b/fs/compat.c
60138@@ -54,7 +54,7 @@
60139 #include <asm/ioctls.h>
60140 #include "internal.h"
60141
60142-int compat_log = 1;
60143+int compat_log = 0;
60144
60145 int compat_printk(const char *fmt, ...)
60146 {
60147@@ -512,7 +512,7 @@ COMPAT_SYSCALL_DEFINE2(io_setup, unsigned, nr_reqs, u32 __user *, ctx32p)
60148
60149 set_fs(KERNEL_DS);
60150 /* The __user pointer cast is valid because of the set_fs() */
60151- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
60152+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
60153 set_fs(oldfs);
60154 /* truncating is ok because it's a user address */
60155 if (!ret)
60156@@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
60157 goto out;
60158
60159 ret = -EINVAL;
60160- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
60161+ if (nr_segs > UIO_MAXIOV)
60162 goto out;
60163 if (nr_segs > fast_segs) {
60164 ret = -ENOMEM;
60165@@ -844,6 +844,7 @@ struct compat_old_linux_dirent {
60166 struct compat_readdir_callback {
60167 struct dir_context ctx;
60168 struct compat_old_linux_dirent __user *dirent;
60169+ struct file * file;
60170 int result;
60171 };
60172
60173@@ -861,6 +862,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
60174 buf->result = -EOVERFLOW;
60175 return -EOVERFLOW;
60176 }
60177+
60178+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60179+ return 0;
60180+
60181 buf->result++;
60182 dirent = buf->dirent;
60183 if (!access_ok(VERIFY_WRITE, dirent,
60184@@ -892,6 +897,7 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
60185 if (!f.file)
60186 return -EBADF;
60187
60188+ buf.file = f.file;
60189 error = iterate_dir(f.file, &buf.ctx);
60190 if (buf.result)
60191 error = buf.result;
60192@@ -911,6 +917,7 @@ struct compat_getdents_callback {
60193 struct dir_context ctx;
60194 struct compat_linux_dirent __user *current_dir;
60195 struct compat_linux_dirent __user *previous;
60196+ struct file * file;
60197 int count;
60198 int error;
60199 };
60200@@ -932,6 +939,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
60201 buf->error = -EOVERFLOW;
60202 return -EOVERFLOW;
60203 }
60204+
60205+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60206+ return 0;
60207+
60208 dirent = buf->previous;
60209 if (dirent) {
60210 if (__put_user(offset, &dirent->d_off))
60211@@ -977,6 +988,7 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
60212 if (!f.file)
60213 return -EBADF;
60214
60215+ buf.file = f.file;
60216 error = iterate_dir(f.file, &buf.ctx);
60217 if (error >= 0)
60218 error = buf.error;
60219@@ -997,6 +1009,7 @@ struct compat_getdents_callback64 {
60220 struct dir_context ctx;
60221 struct linux_dirent64 __user *current_dir;
60222 struct linux_dirent64 __user *previous;
60223+ struct file * file;
60224 int count;
60225 int error;
60226 };
60227@@ -1013,6 +1026,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
60228 buf->error = -EINVAL; /* only used if we fail.. */
60229 if (reclen > buf->count)
60230 return -EINVAL;
60231+
60232+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60233+ return 0;
60234+
60235 dirent = buf->previous;
60236
60237 if (dirent) {
60238@@ -1062,6 +1079,7 @@ COMPAT_SYSCALL_DEFINE3(getdents64, unsigned int, fd,
60239 if (!f.file)
60240 return -EBADF;
60241
60242+ buf.file = f.file;
60243 error = iterate_dir(f.file, &buf.ctx);
60244 if (error >= 0)
60245 error = buf.error;
60246diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
60247index 4d24d17..4f8c09e 100644
60248--- a/fs/compat_binfmt_elf.c
60249+++ b/fs/compat_binfmt_elf.c
60250@@ -30,11 +30,13 @@
60251 #undef elf_phdr
60252 #undef elf_shdr
60253 #undef elf_note
60254+#undef elf_dyn
60255 #undef elf_addr_t
60256 #define elfhdr elf32_hdr
60257 #define elf_phdr elf32_phdr
60258 #define elf_shdr elf32_shdr
60259 #define elf_note elf32_note
60260+#define elf_dyn Elf32_Dyn
60261 #define elf_addr_t Elf32_Addr
60262
60263 /*
60264diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
60265index afec645..9c65620 100644
60266--- a/fs/compat_ioctl.c
60267+++ b/fs/compat_ioctl.c
60268@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
60269 return -EFAULT;
60270 if (__get_user(udata, &ss32->iomem_base))
60271 return -EFAULT;
60272- ss.iomem_base = compat_ptr(udata);
60273+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
60274 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
60275 __get_user(ss.port_high, &ss32->port_high))
60276 return -EFAULT;
60277@@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
60278 for (i = 0; i < nmsgs; i++) {
60279 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
60280 return -EFAULT;
60281- if (get_user(datap, &umsgs[i].buf) ||
60282- put_user(compat_ptr(datap), &tmsgs[i].buf))
60283+ if (get_user(datap, (compat_caddr_t __user *)&umsgs[i].buf) ||
60284+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
60285 return -EFAULT;
60286 }
60287 return sys_ioctl(fd, cmd, (unsigned long)tdata);
60288@@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
60289 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
60290 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
60291 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
60292- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
60293+ copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
60294 return -EFAULT;
60295
60296 return ioctl_preallocate(file, p);
60297@@ -1618,8 +1618,8 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
60298 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
60299 {
60300 unsigned int a, b;
60301- a = *(unsigned int *)p;
60302- b = *(unsigned int *)q;
60303+ a = *(const unsigned int *)p;
60304+ b = *(const unsigned int *)q;
60305 if (a > b)
60306 return 1;
60307 if (a < b)
60308diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
60309index 668dcab..daebcd6 100644
60310--- a/fs/configfs/dir.c
60311+++ b/fs/configfs/dir.c
60312@@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
60313 }
60314 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
60315 struct configfs_dirent *next;
60316- const char *name;
60317+ const unsigned char * name;
60318+ char d_name[sizeof(next->s_dentry->d_iname)];
60319 int len;
60320 struct inode *inode = NULL;
60321
60322@@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
60323 continue;
60324
60325 name = configfs_get_name(next);
60326- len = strlen(name);
60327+ if (next->s_dentry && name == next->s_dentry->d_iname) {
60328+ len = next->s_dentry->d_name.len;
60329+ memcpy(d_name, name, len);
60330+ name = d_name;
60331+ } else
60332+ len = strlen(name);
60333
60334 /*
60335 * We'll have a dentry and an inode for
60336diff --git a/fs/coredump.c b/fs/coredump.c
60337index b5c86ff..0dac262 100644
60338--- a/fs/coredump.c
60339+++ b/fs/coredump.c
60340@@ -450,8 +450,8 @@ static void wait_for_dump_helpers(struct file *file)
60341 struct pipe_inode_info *pipe = file->private_data;
60342
60343 pipe_lock(pipe);
60344- pipe->readers++;
60345- pipe->writers--;
60346+ atomic_inc(&pipe->readers);
60347+ atomic_dec(&pipe->writers);
60348 wake_up_interruptible_sync(&pipe->wait);
60349 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
60350 pipe_unlock(pipe);
60351@@ -460,11 +460,11 @@ static void wait_for_dump_helpers(struct file *file)
60352 * We actually want wait_event_freezable() but then we need
60353 * to clear TIF_SIGPENDING and improve dump_interrupted().
60354 */
60355- wait_event_interruptible(pipe->wait, pipe->readers == 1);
60356+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
60357
60358 pipe_lock(pipe);
60359- pipe->readers--;
60360- pipe->writers++;
60361+ atomic_dec(&pipe->readers);
60362+ atomic_inc(&pipe->writers);
60363 pipe_unlock(pipe);
60364 }
60365
60366@@ -511,7 +511,9 @@ void do_coredump(const siginfo_t *siginfo)
60367 struct files_struct *displaced;
60368 bool need_nonrelative = false;
60369 bool core_dumped = false;
60370- static atomic_t core_dump_count = ATOMIC_INIT(0);
60371+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
60372+ long signr = siginfo->si_signo;
60373+ int dumpable;
60374 struct coredump_params cprm = {
60375 .siginfo = siginfo,
60376 .regs = signal_pt_regs(),
60377@@ -524,12 +526,17 @@ void do_coredump(const siginfo_t *siginfo)
60378 .mm_flags = mm->flags,
60379 };
60380
60381- audit_core_dumps(siginfo->si_signo);
60382+ audit_core_dumps(signr);
60383+
60384+ dumpable = __get_dumpable(cprm.mm_flags);
60385+
60386+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
60387+ gr_handle_brute_attach(dumpable);
60388
60389 binfmt = mm->binfmt;
60390 if (!binfmt || !binfmt->core_dump)
60391 goto fail;
60392- if (!__get_dumpable(cprm.mm_flags))
60393+ if (!dumpable)
60394 goto fail;
60395
60396 cred = prepare_creds();
60397@@ -548,7 +555,7 @@ void do_coredump(const siginfo_t *siginfo)
60398 need_nonrelative = true;
60399 }
60400
60401- retval = coredump_wait(siginfo->si_signo, &core_state);
60402+ retval = coredump_wait(signr, &core_state);
60403 if (retval < 0)
60404 goto fail_creds;
60405
60406@@ -591,7 +598,7 @@ void do_coredump(const siginfo_t *siginfo)
60407 }
60408 cprm.limit = RLIM_INFINITY;
60409
60410- dump_count = atomic_inc_return(&core_dump_count);
60411+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
60412 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
60413 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
60414 task_tgid_vnr(current), current->comm);
60415@@ -623,6 +630,8 @@ void do_coredump(const siginfo_t *siginfo)
60416 } else {
60417 struct inode *inode;
60418
60419+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
60420+
60421 if (cprm.limit < binfmt->min_coredump)
60422 goto fail_unlock;
60423
60424@@ -681,7 +690,7 @@ close_fail:
60425 filp_close(cprm.file, NULL);
60426 fail_dropcount:
60427 if (ispipe)
60428- atomic_dec(&core_dump_count);
60429+ atomic_dec_unchecked(&core_dump_count);
60430 fail_unlock:
60431 kfree(cn.corename);
60432 coredump_finish(mm, core_dumped);
60433@@ -702,6 +711,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
60434 struct file *file = cprm->file;
60435 loff_t pos = file->f_pos;
60436 ssize_t n;
60437+
60438+ gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
60439 if (cprm->written + nr > cprm->limit)
60440 return 0;
60441 while (nr) {
60442diff --git a/fs/dcache.c b/fs/dcache.c
60443index 71acf8d..815e743 100644
60444--- a/fs/dcache.c
60445+++ b/fs/dcache.c
60446@@ -508,7 +508,7 @@ static void __dentry_kill(struct dentry *dentry)
60447 * dentry_iput drops the locks, at which point nobody (except
60448 * transient RCU lookups) can reach this dentry.
60449 */
60450- BUG_ON((int)dentry->d_lockref.count > 0);
60451+ BUG_ON((int)__lockref_read(&dentry->d_lockref) > 0);
60452 this_cpu_dec(nr_dentry);
60453 if (dentry->d_op && dentry->d_op->d_release)
60454 dentry->d_op->d_release(dentry);
60455@@ -561,7 +561,7 @@ static inline struct dentry *lock_parent(struct dentry *dentry)
60456 struct dentry *parent = dentry->d_parent;
60457 if (IS_ROOT(dentry))
60458 return NULL;
60459- if (unlikely((int)dentry->d_lockref.count < 0))
60460+ if (unlikely((int)__lockref_read(&dentry->d_lockref) < 0))
60461 return NULL;
60462 if (likely(spin_trylock(&parent->d_lock)))
60463 return parent;
60464@@ -638,7 +638,7 @@ repeat:
60465 dentry->d_flags |= DCACHE_REFERENCED;
60466 dentry_lru_add(dentry);
60467
60468- dentry->d_lockref.count--;
60469+ __lockref_dec(&dentry->d_lockref);
60470 spin_unlock(&dentry->d_lock);
60471 return;
60472
60473@@ -653,7 +653,7 @@ EXPORT_SYMBOL(dput);
60474 /* This must be called with d_lock held */
60475 static inline void __dget_dlock(struct dentry *dentry)
60476 {
60477- dentry->d_lockref.count++;
60478+ __lockref_inc(&dentry->d_lockref);
60479 }
60480
60481 static inline void __dget(struct dentry *dentry)
60482@@ -694,8 +694,8 @@ repeat:
60483 goto repeat;
60484 }
60485 rcu_read_unlock();
60486- BUG_ON(!ret->d_lockref.count);
60487- ret->d_lockref.count++;
60488+ BUG_ON(!__lockref_read(&ret->d_lockref));
60489+ __lockref_inc(&ret->d_lockref);
60490 spin_unlock(&ret->d_lock);
60491 return ret;
60492 }
60493@@ -773,9 +773,9 @@ restart:
60494 spin_lock(&inode->i_lock);
60495 hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) {
60496 spin_lock(&dentry->d_lock);
60497- if (!dentry->d_lockref.count) {
60498+ if (!__lockref_read(&dentry->d_lockref)) {
60499 struct dentry *parent = lock_parent(dentry);
60500- if (likely(!dentry->d_lockref.count)) {
60501+ if (likely(!__lockref_read(&dentry->d_lockref))) {
60502 __dentry_kill(dentry);
60503 dput(parent);
60504 goto restart;
60505@@ -810,7 +810,7 @@ static void shrink_dentry_list(struct list_head *list)
60506 * We found an inuse dentry which was not removed from
60507 * the LRU because of laziness during lookup. Do not free it.
60508 */
60509- if ((int)dentry->d_lockref.count > 0) {
60510+ if ((int)__lockref_read(&dentry->d_lockref) > 0) {
60511 spin_unlock(&dentry->d_lock);
60512 if (parent)
60513 spin_unlock(&parent->d_lock);
60514@@ -848,8 +848,8 @@ static void shrink_dentry_list(struct list_head *list)
60515 dentry = parent;
60516 while (dentry && !lockref_put_or_lock(&dentry->d_lockref)) {
60517 parent = lock_parent(dentry);
60518- if (dentry->d_lockref.count != 1) {
60519- dentry->d_lockref.count--;
60520+ if (__lockref_read(&dentry->d_lockref) != 1) {
60521+ __lockref_inc(&dentry->d_lockref);
60522 spin_unlock(&dentry->d_lock);
60523 if (parent)
60524 spin_unlock(&parent->d_lock);
60525@@ -889,7 +889,7 @@ dentry_lru_isolate(struct list_head *item, spinlock_t *lru_lock, void *arg)
60526 * counts, just remove them from the LRU. Otherwise give them
60527 * another pass through the LRU.
60528 */
60529- if (dentry->d_lockref.count) {
60530+ if (__lockref_read(&dentry->d_lockref) > 0) {
60531 d_lru_isolate(dentry);
60532 spin_unlock(&dentry->d_lock);
60533 return LRU_REMOVED;
60534@@ -1225,7 +1225,7 @@ static enum d_walk_ret select_collect(void *_data, struct dentry *dentry)
60535 } else {
60536 if (dentry->d_flags & DCACHE_LRU_LIST)
60537 d_lru_del(dentry);
60538- if (!dentry->d_lockref.count) {
60539+ if (!__lockref_read(&dentry->d_lockref)) {
60540 d_shrink_add(dentry, &data->dispose);
60541 data->found++;
60542 }
60543@@ -1273,7 +1273,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
60544 return D_WALK_CONTINUE;
60545
60546 /* root with refcount 1 is fine */
60547- if (dentry == _data && dentry->d_lockref.count == 1)
60548+ if (dentry == _data && __lockref_read(&dentry->d_lockref) == 1)
60549 return D_WALK_CONTINUE;
60550
60551 printk(KERN_ERR "BUG: Dentry %p{i=%lx,n=%pd} "
60552@@ -1282,7 +1282,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
60553 dentry->d_inode ?
60554 dentry->d_inode->i_ino : 0UL,
60555 dentry,
60556- dentry->d_lockref.count,
60557+ __lockref_read(&dentry->d_lockref),
60558 dentry->d_sb->s_type->name,
60559 dentry->d_sb->s_id);
60560 WARN_ON(1);
60561@@ -1423,7 +1423,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
60562 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
60563 if (name->len > DNAME_INLINE_LEN-1) {
60564 size_t size = offsetof(struct external_name, name[1]);
60565- struct external_name *p = kmalloc(size + name->len, GFP_KERNEL);
60566+ struct external_name *p = kmalloc(round_up(size + name->len, sizeof(unsigned long)), GFP_KERNEL);
60567 if (!p) {
60568 kmem_cache_free(dentry_cache, dentry);
60569 return NULL;
60570@@ -1443,7 +1443,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
60571 smp_wmb();
60572 dentry->d_name.name = dname;
60573
60574- dentry->d_lockref.count = 1;
60575+ __lockref_set(&dentry->d_lockref, 1);
60576 dentry->d_flags = 0;
60577 spin_lock_init(&dentry->d_lock);
60578 seqcount_init(&dentry->d_seq);
60579@@ -2183,7 +2183,7 @@ struct dentry *__d_lookup(const struct dentry *parent, const struct qstr *name)
60580 goto next;
60581 }
60582
60583- dentry->d_lockref.count++;
60584+ __lockref_inc(&dentry->d_lockref);
60585 found = dentry;
60586 spin_unlock(&dentry->d_lock);
60587 break;
60588@@ -2282,7 +2282,7 @@ again:
60589 spin_lock(&dentry->d_lock);
60590 inode = dentry->d_inode;
60591 isdir = S_ISDIR(inode->i_mode);
60592- if (dentry->d_lockref.count == 1) {
60593+ if (__lockref_read(&dentry->d_lockref) == 1) {
60594 if (!spin_trylock(&inode->i_lock)) {
60595 spin_unlock(&dentry->d_lock);
60596 cpu_relax();
60597@@ -3306,7 +3306,7 @@ static enum d_walk_ret d_genocide_kill(void *data, struct dentry *dentry)
60598
60599 if (!(dentry->d_flags & DCACHE_GENOCIDE)) {
60600 dentry->d_flags |= DCACHE_GENOCIDE;
60601- dentry->d_lockref.count--;
60602+ __lockref_dec(&dentry->d_lockref);
60603 }
60604 }
60605 return D_WALK_CONTINUE;
60606@@ -3422,7 +3422,8 @@ void __init vfs_caches_init(unsigned long mempages)
60607 mempages -= reserve;
60608
60609 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
60610- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
60611+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
60612+ SLAB_NO_SANITIZE, NULL);
60613
60614 dcache_init();
60615 inode_init();
60616diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
60617index 05f2960..b012481 100644
60618--- a/fs/debugfs/inode.c
60619+++ b/fs/debugfs/inode.c
60620@@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
60621 */
60622 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
60623 {
60624+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
60625+ return __create_file(name, S_IFDIR | S_IRWXU,
60626+#else
60627 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
60628+#endif
60629 parent, NULL, NULL);
60630 }
60631 EXPORT_SYMBOL_GPL(debugfs_create_dir);
60632diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
60633index 1686dc2..9611c50 100644
60634--- a/fs/ecryptfs/inode.c
60635+++ b/fs/ecryptfs/inode.c
60636@@ -664,7 +664,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
60637 old_fs = get_fs();
60638 set_fs(get_ds());
60639 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
60640- (char __user *)lower_buf,
60641+ (char __force_user *)lower_buf,
60642 PATH_MAX);
60643 set_fs(old_fs);
60644 if (rc < 0)
60645diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
60646index e4141f2..d8263e8 100644
60647--- a/fs/ecryptfs/miscdev.c
60648+++ b/fs/ecryptfs/miscdev.c
60649@@ -304,7 +304,7 @@ check_list:
60650 goto out_unlock_msg_ctx;
60651 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
60652 if (msg_ctx->msg) {
60653- if (copy_to_user(&buf[i], packet_length, packet_length_size))
60654+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
60655 goto out_unlock_msg_ctx;
60656 i += packet_length_size;
60657 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
60658diff --git a/fs/exec.c b/fs/exec.c
60659index 7302b75..7d61d19 100644
60660--- a/fs/exec.c
60661+++ b/fs/exec.c
60662@@ -56,8 +56,20 @@
60663 #include <linux/pipe_fs_i.h>
60664 #include <linux/oom.h>
60665 #include <linux/compat.h>
60666+#include <linux/random.h>
60667+#include <linux/seq_file.h>
60668+#include <linux/coredump.h>
60669+#include <linux/mman.h>
60670+
60671+#ifdef CONFIG_PAX_REFCOUNT
60672+#include <linux/kallsyms.h>
60673+#include <linux/kdebug.h>
60674+#endif
60675+
60676+#include <trace/events/fs.h>
60677
60678 #include <asm/uaccess.h>
60679+#include <asm/sections.h>
60680 #include <asm/mmu_context.h>
60681 #include <asm/tlb.h>
60682
60683@@ -66,19 +78,34 @@
60684
60685 #include <trace/events/sched.h>
60686
60687+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
60688+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
60689+{
60690+ 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");
60691+}
60692+#endif
60693+
60694+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
60695+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
60696+EXPORT_SYMBOL(pax_set_initial_flags_func);
60697+#endif
60698+
60699 int suid_dumpable = 0;
60700
60701 static LIST_HEAD(formats);
60702 static DEFINE_RWLOCK(binfmt_lock);
60703
60704+extern int gr_process_kernel_exec_ban(void);
60705+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
60706+
60707 void __register_binfmt(struct linux_binfmt * fmt, int insert)
60708 {
60709 BUG_ON(!fmt);
60710 if (WARN_ON(!fmt->load_binary))
60711 return;
60712 write_lock(&binfmt_lock);
60713- insert ? list_add(&fmt->lh, &formats) :
60714- list_add_tail(&fmt->lh, &formats);
60715+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
60716+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
60717 write_unlock(&binfmt_lock);
60718 }
60719
60720@@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
60721 void unregister_binfmt(struct linux_binfmt * fmt)
60722 {
60723 write_lock(&binfmt_lock);
60724- list_del(&fmt->lh);
60725+ pax_list_del((struct list_head *)&fmt->lh);
60726 write_unlock(&binfmt_lock);
60727 }
60728
60729@@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
60730 int write)
60731 {
60732 struct page *page;
60733- int ret;
60734
60735-#ifdef CONFIG_STACK_GROWSUP
60736- if (write) {
60737- ret = expand_downwards(bprm->vma, pos);
60738- if (ret < 0)
60739- return NULL;
60740- }
60741-#endif
60742- ret = get_user_pages(current, bprm->mm, pos,
60743- 1, write, 1, &page, NULL);
60744- if (ret <= 0)
60745+ if (0 > expand_downwards(bprm->vma, pos))
60746+ return NULL;
60747+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
60748 return NULL;
60749
60750 if (write) {
60751@@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
60752 if (size <= ARG_MAX)
60753 return page;
60754
60755+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60756+ // only allow 512KB for argv+env on suid/sgid binaries
60757+ // to prevent easy ASLR exhaustion
60758+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
60759+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
60760+ (size > (512 * 1024))) {
60761+ put_page(page);
60762+ return NULL;
60763+ }
60764+#endif
60765+
60766 /*
60767 * Limit to 1/4-th the stack size for the argv+env strings.
60768 * This ensures that:
60769@@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
60770 vma->vm_end = STACK_TOP_MAX;
60771 vma->vm_start = vma->vm_end - PAGE_SIZE;
60772 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
60773+
60774+#ifdef CONFIG_PAX_SEGMEXEC
60775+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
60776+#endif
60777+
60778 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
60779 INIT_LIST_HEAD(&vma->anon_vma_chain);
60780
60781@@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
60782 mm->stack_vm = mm->total_vm = 1;
60783 up_write(&mm->mmap_sem);
60784 bprm->p = vma->vm_end - sizeof(void *);
60785+
60786+#ifdef CONFIG_PAX_RANDUSTACK
60787+ if (randomize_va_space)
60788+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
60789+#endif
60790+
60791 return 0;
60792 err:
60793 up_write(&mm->mmap_sem);
60794@@ -395,7 +436,7 @@ struct user_arg_ptr {
60795 } ptr;
60796 };
60797
60798-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
60799+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
60800 {
60801 const char __user *native;
60802
60803@@ -404,14 +445,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
60804 compat_uptr_t compat;
60805
60806 if (get_user(compat, argv.ptr.compat + nr))
60807- return ERR_PTR(-EFAULT);
60808+ return (const char __force_user *)ERR_PTR(-EFAULT);
60809
60810 return compat_ptr(compat);
60811 }
60812 #endif
60813
60814 if (get_user(native, argv.ptr.native + nr))
60815- return ERR_PTR(-EFAULT);
60816+ return (const char __force_user *)ERR_PTR(-EFAULT);
60817
60818 return native;
60819 }
60820@@ -430,7 +471,7 @@ static int count(struct user_arg_ptr argv, int max)
60821 if (!p)
60822 break;
60823
60824- if (IS_ERR(p))
60825+ if (IS_ERR((const char __force_kernel *)p))
60826 return -EFAULT;
60827
60828 if (i >= max)
60829@@ -465,7 +506,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
60830
60831 ret = -EFAULT;
60832 str = get_user_arg_ptr(argv, argc);
60833- if (IS_ERR(str))
60834+ if (IS_ERR((const char __force_kernel *)str))
60835 goto out;
60836
60837 len = strnlen_user(str, MAX_ARG_STRLEN);
60838@@ -547,7 +588,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
60839 int r;
60840 mm_segment_t oldfs = get_fs();
60841 struct user_arg_ptr argv = {
60842- .ptr.native = (const char __user *const __user *)__argv,
60843+ .ptr.native = (const char __user * const __force_user *)__argv,
60844 };
60845
60846 set_fs(KERNEL_DS);
60847@@ -582,7 +623,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
60848 unsigned long new_end = old_end - shift;
60849 struct mmu_gather tlb;
60850
60851- BUG_ON(new_start > new_end);
60852+ if (new_start >= new_end || new_start < mmap_min_addr)
60853+ return -ENOMEM;
60854
60855 /*
60856 * ensure there are no vmas between where we want to go
60857@@ -591,6 +633,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
60858 if (vma != find_vma(mm, new_start))
60859 return -EFAULT;
60860
60861+#ifdef CONFIG_PAX_SEGMEXEC
60862+ BUG_ON(pax_find_mirror_vma(vma));
60863+#endif
60864+
60865 /*
60866 * cover the whole range: [new_start, old_end)
60867 */
60868@@ -671,10 +717,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
60869 stack_top = arch_align_stack(stack_top);
60870 stack_top = PAGE_ALIGN(stack_top);
60871
60872- if (unlikely(stack_top < mmap_min_addr) ||
60873- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
60874- return -ENOMEM;
60875-
60876 stack_shift = vma->vm_end - stack_top;
60877
60878 bprm->p -= stack_shift;
60879@@ -686,8 +728,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
60880 bprm->exec -= stack_shift;
60881
60882 down_write(&mm->mmap_sem);
60883+
60884+ /* Move stack pages down in memory. */
60885+ if (stack_shift) {
60886+ ret = shift_arg_pages(vma, stack_shift);
60887+ if (ret)
60888+ goto out_unlock;
60889+ }
60890+
60891 vm_flags = VM_STACK_FLAGS;
60892
60893+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
60894+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
60895+ vm_flags &= ~VM_EXEC;
60896+
60897+#ifdef CONFIG_PAX_MPROTECT
60898+ if (mm->pax_flags & MF_PAX_MPROTECT)
60899+ vm_flags &= ~VM_MAYEXEC;
60900+#endif
60901+
60902+ }
60903+#endif
60904+
60905 /*
60906 * Adjust stack execute permissions; explicitly enable for
60907 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
60908@@ -706,13 +768,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
60909 goto out_unlock;
60910 BUG_ON(prev != vma);
60911
60912- /* Move stack pages down in memory. */
60913- if (stack_shift) {
60914- ret = shift_arg_pages(vma, stack_shift);
60915- if (ret)
60916- goto out_unlock;
60917- }
60918-
60919 /* mprotect_fixup is overkill to remove the temporary stack flags */
60920 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
60921
60922@@ -736,6 +791,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
60923 #endif
60924 current->mm->start_stack = bprm->p;
60925 ret = expand_stack(vma, stack_base);
60926+
60927+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
60928+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
60929+ unsigned long size;
60930+ vm_flags_t vm_flags;
60931+
60932+ size = STACK_TOP - vma->vm_end;
60933+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
60934+
60935+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
60936+
60937+#ifdef CONFIG_X86
60938+ if (!ret) {
60939+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
60940+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
60941+ }
60942+#endif
60943+
60944+ }
60945+#endif
60946+
60947 if (ret)
60948 ret = -EFAULT;
60949
60950@@ -771,6 +847,8 @@ static struct file *do_open_exec(struct filename *name)
60951
60952 fsnotify_open(file);
60953
60954+ trace_open_exec(name->name);
60955+
60956 err = deny_write_access(file);
60957 if (err)
60958 goto exit;
60959@@ -800,7 +878,7 @@ int kernel_read(struct file *file, loff_t offset,
60960 old_fs = get_fs();
60961 set_fs(get_ds());
60962 /* The cast to a user pointer is valid due to the set_fs() */
60963- result = vfs_read(file, (void __user *)addr, count, &pos);
60964+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
60965 set_fs(old_fs);
60966 return result;
60967 }
60968@@ -845,6 +923,7 @@ static int exec_mmap(struct mm_struct *mm)
60969 tsk->mm = mm;
60970 tsk->active_mm = mm;
60971 activate_mm(active_mm, mm);
60972+ populate_stack();
60973 tsk->mm->vmacache_seqnum = 0;
60974 vmacache_flush(tsk);
60975 task_unlock(tsk);
60976@@ -1243,7 +1322,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
60977 }
60978 rcu_read_unlock();
60979
60980- if (p->fs->users > n_fs)
60981+ if (atomic_read(&p->fs->users) > n_fs)
60982 bprm->unsafe |= LSM_UNSAFE_SHARE;
60983 else
60984 p->fs->in_exec = 1;
60985@@ -1424,6 +1503,31 @@ static int exec_binprm(struct linux_binprm *bprm)
60986 return ret;
60987 }
60988
60989+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60990+static DEFINE_PER_CPU(u64, exec_counter);
60991+static int __init init_exec_counters(void)
60992+{
60993+ unsigned int cpu;
60994+
60995+ for_each_possible_cpu(cpu) {
60996+ per_cpu(exec_counter, cpu) = (u64)cpu;
60997+ }
60998+
60999+ return 0;
61000+}
61001+early_initcall(init_exec_counters);
61002+static inline void increment_exec_counter(void)
61003+{
61004+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
61005+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
61006+}
61007+#else
61008+static inline void increment_exec_counter(void) {}
61009+#endif
61010+
61011+extern void gr_handle_exec_args(struct linux_binprm *bprm,
61012+ struct user_arg_ptr argv);
61013+
61014 /*
61015 * sys_execve() executes a new program.
61016 */
61017@@ -1431,6 +1535,11 @@ static int do_execve_common(struct filename *filename,
61018 struct user_arg_ptr argv,
61019 struct user_arg_ptr envp)
61020 {
61021+#ifdef CONFIG_GRKERNSEC
61022+ struct file *old_exec_file;
61023+ struct acl_subject_label *old_acl;
61024+ struct rlimit old_rlim[RLIM_NLIMITS];
61025+#endif
61026 struct linux_binprm *bprm;
61027 struct file *file;
61028 struct files_struct *displaced;
61029@@ -1439,6 +1548,8 @@ static int do_execve_common(struct filename *filename,
61030 if (IS_ERR(filename))
61031 return PTR_ERR(filename);
61032
61033+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
61034+
61035 /*
61036 * We move the actual failure in case of RLIMIT_NPROC excess from
61037 * set*uid() to execve() because too many poorly written programs
61038@@ -1476,11 +1587,21 @@ static int do_execve_common(struct filename *filename,
61039 if (IS_ERR(file))
61040 goto out_unmark;
61041
61042+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
61043+ retval = -EPERM;
61044+ goto out_unmark;
61045+ }
61046+
61047 sched_exec();
61048
61049 bprm->file = file;
61050 bprm->filename = bprm->interp = filename->name;
61051
61052+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
61053+ retval = -EACCES;
61054+ goto out_unmark;
61055+ }
61056+
61057 retval = bprm_mm_init(bprm);
61058 if (retval)
61059 goto out_unmark;
61060@@ -1497,24 +1618,70 @@ static int do_execve_common(struct filename *filename,
61061 if (retval < 0)
61062 goto out;
61063
61064+#ifdef CONFIG_GRKERNSEC
61065+ old_acl = current->acl;
61066+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
61067+ old_exec_file = current->exec_file;
61068+ get_file(file);
61069+ current->exec_file = file;
61070+#endif
61071+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61072+ /* limit suid stack to 8MB
61073+ * we saved the old limits above and will restore them if this exec fails
61074+ */
61075+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
61076+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
61077+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
61078+#endif
61079+
61080+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
61081+ retval = -EPERM;
61082+ goto out_fail;
61083+ }
61084+
61085+ if (!gr_tpe_allow(file)) {
61086+ retval = -EACCES;
61087+ goto out_fail;
61088+ }
61089+
61090+ if (gr_check_crash_exec(file)) {
61091+ retval = -EACCES;
61092+ goto out_fail;
61093+ }
61094+
61095+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
61096+ bprm->unsafe);
61097+ if (retval < 0)
61098+ goto out_fail;
61099+
61100 retval = copy_strings_kernel(1, &bprm->filename, bprm);
61101 if (retval < 0)
61102- goto out;
61103+ goto out_fail;
61104
61105 bprm->exec = bprm->p;
61106 retval = copy_strings(bprm->envc, envp, bprm);
61107 if (retval < 0)
61108- goto out;
61109+ goto out_fail;
61110
61111 retval = copy_strings(bprm->argc, argv, bprm);
61112 if (retval < 0)
61113- goto out;
61114+ goto out_fail;
61115+
61116+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
61117+
61118+ gr_handle_exec_args(bprm, argv);
61119
61120 retval = exec_binprm(bprm);
61121 if (retval < 0)
61122- goto out;
61123+ goto out_fail;
61124+#ifdef CONFIG_GRKERNSEC
61125+ if (old_exec_file)
61126+ fput(old_exec_file);
61127+#endif
61128
61129 /* execve succeeded */
61130+
61131+ increment_exec_counter();
61132 current->fs->in_exec = 0;
61133 current->in_execve = 0;
61134 acct_update_integrals(current);
61135@@ -1525,6 +1692,14 @@ static int do_execve_common(struct filename *filename,
61136 put_files_struct(displaced);
61137 return retval;
61138
61139+out_fail:
61140+#ifdef CONFIG_GRKERNSEC
61141+ current->acl = old_acl;
61142+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
61143+ fput(current->exec_file);
61144+ current->exec_file = old_exec_file;
61145+#endif
61146+
61147 out:
61148 if (bprm->mm) {
61149 acct_arg_size(bprm, 0);
61150@@ -1616,3 +1791,312 @@ COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
61151 return compat_do_execve(getname(filename), argv, envp);
61152 }
61153 #endif
61154+
61155+int pax_check_flags(unsigned long *flags)
61156+{
61157+ int retval = 0;
61158+
61159+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
61160+ if (*flags & MF_PAX_SEGMEXEC)
61161+ {
61162+ *flags &= ~MF_PAX_SEGMEXEC;
61163+ retval = -EINVAL;
61164+ }
61165+#endif
61166+
61167+ if ((*flags & MF_PAX_PAGEEXEC)
61168+
61169+#ifdef CONFIG_PAX_PAGEEXEC
61170+ && (*flags & MF_PAX_SEGMEXEC)
61171+#endif
61172+
61173+ )
61174+ {
61175+ *flags &= ~MF_PAX_PAGEEXEC;
61176+ retval = -EINVAL;
61177+ }
61178+
61179+ if ((*flags & MF_PAX_MPROTECT)
61180+
61181+#ifdef CONFIG_PAX_MPROTECT
61182+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
61183+#endif
61184+
61185+ )
61186+ {
61187+ *flags &= ~MF_PAX_MPROTECT;
61188+ retval = -EINVAL;
61189+ }
61190+
61191+ if ((*flags & MF_PAX_EMUTRAMP)
61192+
61193+#ifdef CONFIG_PAX_EMUTRAMP
61194+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
61195+#endif
61196+
61197+ )
61198+ {
61199+ *flags &= ~MF_PAX_EMUTRAMP;
61200+ retval = -EINVAL;
61201+ }
61202+
61203+ return retval;
61204+}
61205+
61206+EXPORT_SYMBOL(pax_check_flags);
61207+
61208+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
61209+char *pax_get_path(const struct path *path, char *buf, int buflen)
61210+{
61211+ char *pathname = d_path(path, buf, buflen);
61212+
61213+ if (IS_ERR(pathname))
61214+ goto toolong;
61215+
61216+ pathname = mangle_path(buf, pathname, "\t\n\\");
61217+ if (!pathname)
61218+ goto toolong;
61219+
61220+ *pathname = 0;
61221+ return buf;
61222+
61223+toolong:
61224+ return "<path too long>";
61225+}
61226+EXPORT_SYMBOL(pax_get_path);
61227+
61228+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
61229+{
61230+ struct task_struct *tsk = current;
61231+ struct mm_struct *mm = current->mm;
61232+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
61233+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
61234+ char *path_exec = NULL;
61235+ char *path_fault = NULL;
61236+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
61237+ siginfo_t info = { };
61238+
61239+ if (buffer_exec && buffer_fault) {
61240+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
61241+
61242+ down_read(&mm->mmap_sem);
61243+ vma = mm->mmap;
61244+ while (vma && (!vma_exec || !vma_fault)) {
61245+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
61246+ vma_exec = vma;
61247+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
61248+ vma_fault = vma;
61249+ vma = vma->vm_next;
61250+ }
61251+ if (vma_exec)
61252+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
61253+ if (vma_fault) {
61254+ start = vma_fault->vm_start;
61255+ end = vma_fault->vm_end;
61256+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
61257+ if (vma_fault->vm_file)
61258+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
61259+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
61260+ path_fault = "<heap>";
61261+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
61262+ path_fault = "<stack>";
61263+ else
61264+ path_fault = "<anonymous mapping>";
61265+ }
61266+ up_read(&mm->mmap_sem);
61267+ }
61268+ if (tsk->signal->curr_ip)
61269+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
61270+ else
61271+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
61272+ 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),
61273+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
61274+ free_page((unsigned long)buffer_exec);
61275+ free_page((unsigned long)buffer_fault);
61276+ pax_report_insns(regs, pc, sp);
61277+ info.si_signo = SIGKILL;
61278+ info.si_errno = 0;
61279+ info.si_code = SI_KERNEL;
61280+ info.si_pid = 0;
61281+ info.si_uid = 0;
61282+ do_coredump(&info);
61283+}
61284+#endif
61285+
61286+#ifdef CONFIG_PAX_REFCOUNT
61287+void pax_report_refcount_overflow(struct pt_regs *regs)
61288+{
61289+ if (current->signal->curr_ip)
61290+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
61291+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
61292+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
61293+ else
61294+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
61295+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
61296+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
61297+ preempt_disable();
61298+ show_regs(regs);
61299+ preempt_enable();
61300+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
61301+}
61302+#endif
61303+
61304+#ifdef CONFIG_PAX_USERCOPY
61305+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
61306+static noinline int check_stack_object(const void *obj, unsigned long len)
61307+{
61308+ const void * const stack = task_stack_page(current);
61309+ const void * const stackend = stack + THREAD_SIZE;
61310+
61311+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
61312+ const void *frame = NULL;
61313+ const void *oldframe;
61314+#endif
61315+
61316+ if (obj + len < obj)
61317+ return -1;
61318+
61319+ if (obj + len <= stack || stackend <= obj)
61320+ return 0;
61321+
61322+ if (obj < stack || stackend < obj + len)
61323+ return -1;
61324+
61325+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
61326+ oldframe = __builtin_frame_address(1);
61327+ if (oldframe)
61328+ frame = __builtin_frame_address(2);
61329+ /*
61330+ low ----------------------------------------------> high
61331+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
61332+ ^----------------^
61333+ allow copies only within here
61334+ */
61335+ while (stack <= frame && frame < stackend) {
61336+ /* if obj + len extends past the last frame, this
61337+ check won't pass and the next frame will be 0,
61338+ causing us to bail out and correctly report
61339+ the copy as invalid
61340+ */
61341+ if (obj + len <= frame)
61342+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
61343+ oldframe = frame;
61344+ frame = *(const void * const *)frame;
61345+ }
61346+ return -1;
61347+#else
61348+ return 1;
61349+#endif
61350+}
61351+
61352+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
61353+{
61354+ if (current->signal->curr_ip)
61355+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
61356+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
61357+ else
61358+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
61359+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
61360+ dump_stack();
61361+ gr_handle_kernel_exploit();
61362+ do_group_exit(SIGKILL);
61363+}
61364+#endif
61365+
61366+#ifdef CONFIG_PAX_USERCOPY
61367+
61368+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
61369+{
61370+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
61371+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
61372+#ifdef CONFIG_MODULES
61373+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
61374+#else
61375+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
61376+#endif
61377+
61378+#else
61379+ unsigned long textlow = (unsigned long)_stext;
61380+ unsigned long texthigh = (unsigned long)_etext;
61381+
61382+#ifdef CONFIG_X86_64
61383+ /* check against linear mapping as well */
61384+ if (high > (unsigned long)__va(__pa(textlow)) &&
61385+ low < (unsigned long)__va(__pa(texthigh)))
61386+ return true;
61387+#endif
61388+
61389+#endif
61390+
61391+ if (high <= textlow || low >= texthigh)
61392+ return false;
61393+ else
61394+ return true;
61395+}
61396+#endif
61397+
61398+void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size)
61399+{
61400+#ifdef CONFIG_PAX_USERCOPY
61401+ const char *type;
61402+#endif
61403+
61404+#ifndef CONFIG_STACK_GROWSUP
61405+ unsigned long stackstart = (unsigned long)task_stack_page(current);
61406+ unsigned long currentsp = (unsigned long)&stackstart;
61407+ if (unlikely((currentsp < stackstart + 512 ||
61408+ currentsp >= stackstart + THREAD_SIZE) && !in_interrupt()))
61409+ BUG();
61410+#endif
61411+
61412+#ifndef CONFIG_PAX_USERCOPY_DEBUG
61413+ if (const_size)
61414+ return;
61415+#endif
61416+
61417+#ifdef CONFIG_PAX_USERCOPY
61418+ if (!n)
61419+ return;
61420+
61421+ type = check_heap_object(ptr, n);
61422+ if (!type) {
61423+ int ret = check_stack_object(ptr, n);
61424+ if (ret == 1 || ret == 2)
61425+ return;
61426+ if (ret == 0) {
61427+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
61428+ type = "<kernel text>";
61429+ else
61430+ return;
61431+ } else
61432+ type = "<process stack>";
61433+ }
61434+
61435+ pax_report_usercopy(ptr, n, to_user, type);
61436+#endif
61437+
61438+}
61439+EXPORT_SYMBOL(__check_object_size);
61440+
61441+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
61442+void pax_track_stack(void)
61443+{
61444+ unsigned long sp = (unsigned long)&sp;
61445+ if (sp < current_thread_info()->lowest_stack &&
61446+ sp > (unsigned long)task_stack_page(current))
61447+ current_thread_info()->lowest_stack = sp;
61448+ if (unlikely((sp & ~(THREAD_SIZE - 1)) < (THREAD_SIZE/16)))
61449+ BUG();
61450+}
61451+EXPORT_SYMBOL(pax_track_stack);
61452+#endif
61453+
61454+#ifdef CONFIG_PAX_SIZE_OVERFLOW
61455+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
61456+{
61457+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
61458+ dump_stack();
61459+ do_group_exit(SIGKILL);
61460+}
61461+EXPORT_SYMBOL(report_size_overflow);
61462+#endif
61463diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
61464index 9f9992b..8b59411 100644
61465--- a/fs/ext2/balloc.c
61466+++ b/fs/ext2/balloc.c
61467@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
61468
61469 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
61470 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
61471- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
61472+ if (free_blocks < root_blocks + 1 &&
61473 !uid_eq(sbi->s_resuid, current_fsuid()) &&
61474 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
61475- !in_group_p (sbi->s_resgid))) {
61476+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
61477 return 0;
61478 }
61479 return 1;
61480diff --git a/fs/ext2/super.c b/fs/ext2/super.c
61481index 170dc41..62f6b18 100644
61482--- a/fs/ext2/super.c
61483+++ b/fs/ext2/super.c
61484@@ -264,10 +264,8 @@ static int ext2_show_options(struct seq_file *seq, struct dentry *root)
61485 #ifdef CONFIG_EXT2_FS_XATTR
61486 if (test_opt(sb, XATTR_USER))
61487 seq_puts(seq, ",user_xattr");
61488- if (!test_opt(sb, XATTR_USER) &&
61489- (def_mount_opts & EXT2_DEFM_XATTR_USER)) {
61490+ if (!test_opt(sb, XATTR_USER))
61491 seq_puts(seq, ",nouser_xattr");
61492- }
61493 #endif
61494
61495 #ifdef CONFIG_EXT2_FS_POSIX_ACL
61496@@ -841,8 +839,8 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
61497 if (def_mount_opts & EXT2_DEFM_UID16)
61498 set_opt(sbi->s_mount_opt, NO_UID32);
61499 #ifdef CONFIG_EXT2_FS_XATTR
61500- if (def_mount_opts & EXT2_DEFM_XATTR_USER)
61501- set_opt(sbi->s_mount_opt, XATTR_USER);
61502+ /* always enable user xattrs */
61503+ set_opt(sbi->s_mount_opt, XATTR_USER);
61504 #endif
61505 #ifdef CONFIG_EXT2_FS_POSIX_ACL
61506 if (def_mount_opts & EXT2_DEFM_ACL)
61507diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
61508index 9142614..97484fa 100644
61509--- a/fs/ext2/xattr.c
61510+++ b/fs/ext2/xattr.c
61511@@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
61512 struct buffer_head *bh = NULL;
61513 struct ext2_xattr_entry *entry;
61514 char *end;
61515- size_t rest = buffer_size;
61516+ size_t rest = buffer_size, total_size = 0;
61517 int error;
61518
61519 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
61520@@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
61521 buffer += size;
61522 }
61523 rest -= size;
61524+ total_size += size;
61525 }
61526 }
61527- error = buffer_size - rest; /* total size */
61528+ error = total_size;
61529
61530 cleanup:
61531 brelse(bh);
61532diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
61533index 158b5d4..2432610 100644
61534--- a/fs/ext3/balloc.c
61535+++ b/fs/ext3/balloc.c
61536@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
61537
61538 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
61539 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
61540- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
61541+ if (free_blocks < root_blocks + 1 &&
61542 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
61543 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
61544- !in_group_p (sbi->s_resgid))) {
61545+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
61546 return 0;
61547 }
61548 return 1;
61549diff --git a/fs/ext3/super.c b/fs/ext3/super.c
61550index eb742d0..c19f705 100644
61551--- a/fs/ext3/super.c
61552+++ b/fs/ext3/super.c
61553@@ -649,10 +649,8 @@ static int ext3_show_options(struct seq_file *seq, struct dentry *root)
61554 #ifdef CONFIG_EXT3_FS_XATTR
61555 if (test_opt(sb, XATTR_USER))
61556 seq_puts(seq, ",user_xattr");
61557- if (!test_opt(sb, XATTR_USER) &&
61558- (def_mount_opts & EXT3_DEFM_XATTR_USER)) {
61559+ if (!test_opt(sb, XATTR_USER))
61560 seq_puts(seq, ",nouser_xattr");
61561- }
61562 #endif
61563 #ifdef CONFIG_EXT3_FS_POSIX_ACL
61564 if (test_opt(sb, POSIX_ACL))
61565@@ -1749,8 +1747,8 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
61566 if (def_mount_opts & EXT3_DEFM_UID16)
61567 set_opt(sbi->s_mount_opt, NO_UID32);
61568 #ifdef CONFIG_EXT3_FS_XATTR
61569- if (def_mount_opts & EXT3_DEFM_XATTR_USER)
61570- set_opt(sbi->s_mount_opt, XATTR_USER);
61571+ /* always enable user xattrs */
61572+ set_opt(sbi->s_mount_opt, XATTR_USER);
61573 #endif
61574 #ifdef CONFIG_EXT3_FS_POSIX_ACL
61575 if (def_mount_opts & EXT3_DEFM_ACL)
61576diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
61577index c6874be..f8a6ae8 100644
61578--- a/fs/ext3/xattr.c
61579+++ b/fs/ext3/xattr.c
61580@@ -330,7 +330,7 @@ static int
61581 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
61582 char *buffer, size_t buffer_size)
61583 {
61584- size_t rest = buffer_size;
61585+ size_t rest = buffer_size, total_size = 0;
61586
61587 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
61588 const struct xattr_handler *handler =
61589@@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
61590 buffer += size;
61591 }
61592 rest -= size;
61593+ total_size += size;
61594 }
61595 }
61596- return buffer_size - rest;
61597+ return total_size;
61598 }
61599
61600 static int
61601diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
61602index 83a6f49..d4e4d03 100644
61603--- a/fs/ext4/balloc.c
61604+++ b/fs/ext4/balloc.c
61605@@ -557,8 +557,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
61606 /* Hm, nope. Are (enough) root reserved clusters available? */
61607 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
61608 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
61609- capable(CAP_SYS_RESOURCE) ||
61610- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
61611+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
61612+ capable_nolog(CAP_SYS_RESOURCE)) {
61613
61614 if (free_clusters >= (nclusters + dirty_clusters +
61615 resv_clusters))
61616diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
61617index c55a1fa..9904ebb 100644
61618--- a/fs/ext4/ext4.h
61619+++ b/fs/ext4/ext4.h
61620@@ -1279,19 +1279,19 @@ struct ext4_sb_info {
61621 unsigned long s_mb_last_start;
61622
61623 /* stats for buddy allocator */
61624- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
61625- atomic_t s_bal_success; /* we found long enough chunks */
61626- atomic_t s_bal_allocated; /* in blocks */
61627- atomic_t s_bal_ex_scanned; /* total extents scanned */
61628- atomic_t s_bal_goals; /* goal hits */
61629- atomic_t s_bal_breaks; /* too long searches */
61630- atomic_t s_bal_2orders; /* 2^order hits */
61631+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
61632+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
61633+ atomic_unchecked_t s_bal_allocated; /* in blocks */
61634+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
61635+ atomic_unchecked_t s_bal_goals; /* goal hits */
61636+ atomic_unchecked_t s_bal_breaks; /* too long searches */
61637+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
61638 spinlock_t s_bal_lock;
61639 unsigned long s_mb_buddies_generated;
61640 unsigned long long s_mb_generation_time;
61641- atomic_t s_mb_lost_chunks;
61642- atomic_t s_mb_preallocated;
61643- atomic_t s_mb_discarded;
61644+ atomic_unchecked_t s_mb_lost_chunks;
61645+ atomic_unchecked_t s_mb_preallocated;
61646+ atomic_unchecked_t s_mb_discarded;
61647 atomic_t s_lock_busy;
61648
61649 /* locality groups */
61650diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
61651index dbfe15c..9a6ee8d 100644
61652--- a/fs/ext4/mballoc.c
61653+++ b/fs/ext4/mballoc.c
61654@@ -1901,7 +1901,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
61655 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
61656
61657 if (EXT4_SB(sb)->s_mb_stats)
61658- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
61659+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
61660
61661 break;
61662 }
61663@@ -2211,7 +2211,7 @@ repeat:
61664 ac->ac_status = AC_STATUS_CONTINUE;
61665 ac->ac_flags |= EXT4_MB_HINT_FIRST;
61666 cr = 3;
61667- atomic_inc(&sbi->s_mb_lost_chunks);
61668+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
61669 goto repeat;
61670 }
61671 }
61672@@ -2717,25 +2717,25 @@ int ext4_mb_release(struct super_block *sb)
61673 if (sbi->s_mb_stats) {
61674 ext4_msg(sb, KERN_INFO,
61675 "mballoc: %u blocks %u reqs (%u success)",
61676- atomic_read(&sbi->s_bal_allocated),
61677- atomic_read(&sbi->s_bal_reqs),
61678- atomic_read(&sbi->s_bal_success));
61679+ atomic_read_unchecked(&sbi->s_bal_allocated),
61680+ atomic_read_unchecked(&sbi->s_bal_reqs),
61681+ atomic_read_unchecked(&sbi->s_bal_success));
61682 ext4_msg(sb, KERN_INFO,
61683 "mballoc: %u extents scanned, %u goal hits, "
61684 "%u 2^N hits, %u breaks, %u lost",
61685- atomic_read(&sbi->s_bal_ex_scanned),
61686- atomic_read(&sbi->s_bal_goals),
61687- atomic_read(&sbi->s_bal_2orders),
61688- atomic_read(&sbi->s_bal_breaks),
61689- atomic_read(&sbi->s_mb_lost_chunks));
61690+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
61691+ atomic_read_unchecked(&sbi->s_bal_goals),
61692+ atomic_read_unchecked(&sbi->s_bal_2orders),
61693+ atomic_read_unchecked(&sbi->s_bal_breaks),
61694+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
61695 ext4_msg(sb, KERN_INFO,
61696 "mballoc: %lu generated and it took %Lu",
61697 sbi->s_mb_buddies_generated,
61698 sbi->s_mb_generation_time);
61699 ext4_msg(sb, KERN_INFO,
61700 "mballoc: %u preallocated, %u discarded",
61701- atomic_read(&sbi->s_mb_preallocated),
61702- atomic_read(&sbi->s_mb_discarded));
61703+ atomic_read_unchecked(&sbi->s_mb_preallocated),
61704+ atomic_read_unchecked(&sbi->s_mb_discarded));
61705 }
61706
61707 free_percpu(sbi->s_locality_groups);
61708@@ -3191,16 +3191,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
61709 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
61710
61711 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
61712- atomic_inc(&sbi->s_bal_reqs);
61713- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
61714+ atomic_inc_unchecked(&sbi->s_bal_reqs);
61715+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
61716 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
61717- atomic_inc(&sbi->s_bal_success);
61718- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
61719+ atomic_inc_unchecked(&sbi->s_bal_success);
61720+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
61721 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
61722 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
61723- atomic_inc(&sbi->s_bal_goals);
61724+ atomic_inc_unchecked(&sbi->s_bal_goals);
61725 if (ac->ac_found > sbi->s_mb_max_to_scan)
61726- atomic_inc(&sbi->s_bal_breaks);
61727+ atomic_inc_unchecked(&sbi->s_bal_breaks);
61728 }
61729
61730 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
61731@@ -3627,7 +3627,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
61732 trace_ext4_mb_new_inode_pa(ac, pa);
61733
61734 ext4_mb_use_inode_pa(ac, pa);
61735- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
61736+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
61737
61738 ei = EXT4_I(ac->ac_inode);
61739 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
61740@@ -3687,7 +3687,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
61741 trace_ext4_mb_new_group_pa(ac, pa);
61742
61743 ext4_mb_use_group_pa(ac, pa);
61744- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
61745+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
61746
61747 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
61748 lg = ac->ac_lg;
61749@@ -3776,7 +3776,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
61750 * from the bitmap and continue.
61751 */
61752 }
61753- atomic_add(free, &sbi->s_mb_discarded);
61754+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
61755
61756 return err;
61757 }
61758@@ -3794,7 +3794,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
61759 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
61760 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
61761 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
61762- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
61763+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
61764 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
61765
61766 return 0;
61767diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
61768index 8313ca3..8a37d08 100644
61769--- a/fs/ext4/mmp.c
61770+++ b/fs/ext4/mmp.c
61771@@ -111,7 +111,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
61772 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
61773 const char *function, unsigned int line, const char *msg)
61774 {
61775- __ext4_warning(sb, function, line, msg);
61776+ __ext4_warning(sb, function, line, "%s", msg);
61777 __ext4_warning(sb, function, line,
61778 "MMP failure info: last update time: %llu, last update "
61779 "node: %s, last update device: %s\n",
61780diff --git a/fs/ext4/super.c b/fs/ext4/super.c
61781index 2c9e686..6a40edc 100644
61782--- a/fs/ext4/super.c
61783+++ b/fs/ext4/super.c
61784@@ -1254,7 +1254,7 @@ static ext4_fsblk_t get_sb_block(void **data)
61785 }
61786
61787 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
61788-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
61789+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
61790 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
61791
61792 #ifdef CONFIG_QUOTA
61793@@ -2434,7 +2434,7 @@ struct ext4_attr {
61794 int offset;
61795 int deprecated_val;
61796 } u;
61797-};
61798+} __do_const;
61799
61800 static int parse_strtoull(const char *buf,
61801 unsigned long long max, unsigned long long *value)
61802diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
61803index 1e09fc7..0400dd4 100644
61804--- a/fs/ext4/xattr.c
61805+++ b/fs/ext4/xattr.c
61806@@ -399,7 +399,7 @@ static int
61807 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
61808 char *buffer, size_t buffer_size)
61809 {
61810- size_t rest = buffer_size;
61811+ size_t rest = buffer_size, total_size = 0;
61812
61813 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
61814 const struct xattr_handler *handler =
61815@@ -416,9 +416,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
61816 buffer += size;
61817 }
61818 rest -= size;
61819+ total_size += size;
61820 }
61821 }
61822- return buffer_size - rest;
61823+ return total_size;
61824 }
61825
61826 static int
61827diff --git a/fs/fcntl.c b/fs/fcntl.c
61828index 99d440a..eb979d1 100644
61829--- a/fs/fcntl.c
61830+++ b/fs/fcntl.c
61831@@ -102,6 +102,10 @@ void __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
61832 int force)
61833 {
61834 security_file_set_fowner(filp);
61835+ if (gr_handle_chroot_fowner(pid, type))
61836+ return;
61837+ if (gr_check_protected_task_fowner(pid, type))
61838+ return;
61839 f_modown(filp, pid, type, force);
61840 }
61841 EXPORT_SYMBOL(__f_setown);
61842diff --git a/fs/fhandle.c b/fs/fhandle.c
61843index 999ff5c..ac037c9 100644
61844--- a/fs/fhandle.c
61845+++ b/fs/fhandle.c
61846@@ -8,6 +8,7 @@
61847 #include <linux/fs_struct.h>
61848 #include <linux/fsnotify.h>
61849 #include <linux/personality.h>
61850+#include <linux/grsecurity.h>
61851 #include <asm/uaccess.h>
61852 #include "internal.h"
61853 #include "mount.h"
61854@@ -67,8 +68,7 @@ static long do_sys_name_to_handle(struct path *path,
61855 } else
61856 retval = 0;
61857 /* copy the mount id */
61858- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
61859- sizeof(*mnt_id)) ||
61860+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
61861 copy_to_user(ufh, handle,
61862 sizeof(struct file_handle) + handle_bytes))
61863 retval = -EFAULT;
61864@@ -175,7 +175,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
61865 * the directory. Ideally we would like CAP_DAC_SEARCH.
61866 * But we don't have that
61867 */
61868- if (!capable(CAP_DAC_READ_SEARCH)) {
61869+ if (!capable(CAP_DAC_READ_SEARCH) || !gr_chroot_fhandle()) {
61870 retval = -EPERM;
61871 goto out_err;
61872 }
61873diff --git a/fs/file.c b/fs/file.c
61874index ab3eb6a..8de2392 100644
61875--- a/fs/file.c
61876+++ b/fs/file.c
61877@@ -16,6 +16,7 @@
61878 #include <linux/slab.h>
61879 #include <linux/vmalloc.h>
61880 #include <linux/file.h>
61881+#include <linux/security.h>
61882 #include <linux/fdtable.h>
61883 #include <linux/bitops.h>
61884 #include <linux/interrupt.h>
61885@@ -139,7 +140,7 @@ out:
61886 * Return <0 error code on error; 1 on successful completion.
61887 * The files->file_lock should be held on entry, and will be held on exit.
61888 */
61889-static int expand_fdtable(struct files_struct *files, int nr)
61890+static int expand_fdtable(struct files_struct *files, unsigned int nr)
61891 __releases(files->file_lock)
61892 __acquires(files->file_lock)
61893 {
61894@@ -184,7 +185,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
61895 * expanded and execution may have blocked.
61896 * The files->file_lock should be held on entry, and will be held on exit.
61897 */
61898-static int expand_files(struct files_struct *files, int nr)
61899+static int expand_files(struct files_struct *files, unsigned int nr)
61900 {
61901 struct fdtable *fdt;
61902
61903@@ -800,6 +801,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
61904 if (!file)
61905 return __close_fd(files, fd);
61906
61907+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
61908 if (fd >= rlimit(RLIMIT_NOFILE))
61909 return -EBADF;
61910
61911@@ -826,6 +828,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
61912 if (unlikely(oldfd == newfd))
61913 return -EINVAL;
61914
61915+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
61916 if (newfd >= rlimit(RLIMIT_NOFILE))
61917 return -EBADF;
61918
61919@@ -881,6 +884,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
61920 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
61921 {
61922 int err;
61923+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
61924 if (from >= rlimit(RLIMIT_NOFILE))
61925 return -EINVAL;
61926 err = alloc_fd(from, flags);
61927diff --git a/fs/filesystems.c b/fs/filesystems.c
61928index 5797d45..7d7d79a 100644
61929--- a/fs/filesystems.c
61930+++ b/fs/filesystems.c
61931@@ -275,7 +275,11 @@ struct file_system_type *get_fs_type(const char *name)
61932 int len = dot ? dot - name : strlen(name);
61933
61934 fs = __get_fs_type(name, len);
61935+#ifdef CONFIG_GRKERNSEC_MODHARDEN
61936+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
61937+#else
61938 if (!fs && (request_module("fs-%.*s", len, name) == 0))
61939+#endif
61940 fs = __get_fs_type(name, len);
61941
61942 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
61943diff --git a/fs/fs_struct.c b/fs/fs_struct.c
61944index 7dca743..543d620 100644
61945--- a/fs/fs_struct.c
61946+++ b/fs/fs_struct.c
61947@@ -4,6 +4,7 @@
61948 #include <linux/path.h>
61949 #include <linux/slab.h>
61950 #include <linux/fs_struct.h>
61951+#include <linux/grsecurity.h>
61952 #include "internal.h"
61953
61954 /*
61955@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
61956 write_seqcount_begin(&fs->seq);
61957 old_root = fs->root;
61958 fs->root = *path;
61959+ gr_set_chroot_entries(current, path);
61960 write_seqcount_end(&fs->seq);
61961 spin_unlock(&fs->lock);
61962 if (old_root.dentry)
61963@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
61964 int hits = 0;
61965 spin_lock(&fs->lock);
61966 write_seqcount_begin(&fs->seq);
61967+ /* this root replacement is only done by pivot_root,
61968+ leave grsec's chroot tagging alone for this task
61969+ so that a pivoted root isn't treated as a chroot
61970+ */
61971 hits += replace_path(&fs->root, old_root, new_root);
61972 hits += replace_path(&fs->pwd, old_root, new_root);
61973 write_seqcount_end(&fs->seq);
61974@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
61975 task_lock(tsk);
61976 spin_lock(&fs->lock);
61977 tsk->fs = NULL;
61978- kill = !--fs->users;
61979+ gr_clear_chroot_entries(tsk);
61980+ kill = !atomic_dec_return(&fs->users);
61981 spin_unlock(&fs->lock);
61982 task_unlock(tsk);
61983 if (kill)
61984@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
61985 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
61986 /* We don't need to lock fs - think why ;-) */
61987 if (fs) {
61988- fs->users = 1;
61989+ atomic_set(&fs->users, 1);
61990 fs->in_exec = 0;
61991 spin_lock_init(&fs->lock);
61992 seqcount_init(&fs->seq);
61993@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
61994 spin_lock(&old->lock);
61995 fs->root = old->root;
61996 path_get(&fs->root);
61997+ /* instead of calling gr_set_chroot_entries here,
61998+ we call it from every caller of this function
61999+ */
62000 fs->pwd = old->pwd;
62001 path_get(&fs->pwd);
62002 spin_unlock(&old->lock);
62003@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
62004
62005 task_lock(current);
62006 spin_lock(&fs->lock);
62007- kill = !--fs->users;
62008+ kill = !atomic_dec_return(&fs->users);
62009 current->fs = new_fs;
62010+ gr_set_chroot_entries(current, &new_fs->root);
62011 spin_unlock(&fs->lock);
62012 task_unlock(current);
62013
62014@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
62015
62016 int current_umask(void)
62017 {
62018- return current->fs->umask;
62019+ return current->fs->umask | gr_acl_umask();
62020 }
62021 EXPORT_SYMBOL(current_umask);
62022
62023 /* to be mentioned only in INIT_TASK */
62024 struct fs_struct init_fs = {
62025- .users = 1,
62026+ .users = ATOMIC_INIT(1),
62027 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
62028 .seq = SEQCNT_ZERO(init_fs.seq),
62029 .umask = 0022,
62030diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
62031index 89acec7..a575262 100644
62032--- a/fs/fscache/cookie.c
62033+++ b/fs/fscache/cookie.c
62034@@ -19,7 +19,7 @@
62035
62036 struct kmem_cache *fscache_cookie_jar;
62037
62038-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
62039+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
62040
62041 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
62042 static int fscache_alloc_object(struct fscache_cache *cache,
62043@@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
62044 parent ? (char *) parent->def->name : "<no-parent>",
62045 def->name, netfs_data, enable);
62046
62047- fscache_stat(&fscache_n_acquires);
62048+ fscache_stat_unchecked(&fscache_n_acquires);
62049
62050 /* if there's no parent cookie, then we don't create one here either */
62051 if (!parent) {
62052- fscache_stat(&fscache_n_acquires_null);
62053+ fscache_stat_unchecked(&fscache_n_acquires_null);
62054 _leave(" [no parent]");
62055 return NULL;
62056 }
62057@@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62058 /* allocate and initialise a cookie */
62059 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
62060 if (!cookie) {
62061- fscache_stat(&fscache_n_acquires_oom);
62062+ fscache_stat_unchecked(&fscache_n_acquires_oom);
62063 _leave(" [ENOMEM]");
62064 return NULL;
62065 }
62066@@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
62067
62068 switch (cookie->def->type) {
62069 case FSCACHE_COOKIE_TYPE_INDEX:
62070- fscache_stat(&fscache_n_cookie_index);
62071+ fscache_stat_unchecked(&fscache_n_cookie_index);
62072 break;
62073 case FSCACHE_COOKIE_TYPE_DATAFILE:
62074- fscache_stat(&fscache_n_cookie_data);
62075+ fscache_stat_unchecked(&fscache_n_cookie_data);
62076 break;
62077 default:
62078- fscache_stat(&fscache_n_cookie_special);
62079+ fscache_stat_unchecked(&fscache_n_cookie_special);
62080 break;
62081 }
62082
62083@@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62084 } else {
62085 atomic_dec(&parent->n_children);
62086 __fscache_cookie_put(cookie);
62087- fscache_stat(&fscache_n_acquires_nobufs);
62088+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
62089 _leave(" = NULL");
62090 return NULL;
62091 }
62092@@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62093 }
62094 }
62095
62096- fscache_stat(&fscache_n_acquires_ok);
62097+ fscache_stat_unchecked(&fscache_n_acquires_ok);
62098 _leave(" = %p", cookie);
62099 return cookie;
62100 }
62101@@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
62102 cache = fscache_select_cache_for_object(cookie->parent);
62103 if (!cache) {
62104 up_read(&fscache_addremove_sem);
62105- fscache_stat(&fscache_n_acquires_no_cache);
62106+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
62107 _leave(" = -ENOMEDIUM [no cache]");
62108 return -ENOMEDIUM;
62109 }
62110@@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
62111 object = cache->ops->alloc_object(cache, cookie);
62112 fscache_stat_d(&fscache_n_cop_alloc_object);
62113 if (IS_ERR(object)) {
62114- fscache_stat(&fscache_n_object_no_alloc);
62115+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
62116 ret = PTR_ERR(object);
62117 goto error;
62118 }
62119
62120- fscache_stat(&fscache_n_object_alloc);
62121+ fscache_stat_unchecked(&fscache_n_object_alloc);
62122
62123- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
62124+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
62125
62126 _debug("ALLOC OBJ%x: %s {%lx}",
62127 object->debug_id, cookie->def->name, object->events);
62128@@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
62129
62130 _enter("{%s}", cookie->def->name);
62131
62132- fscache_stat(&fscache_n_invalidates);
62133+ fscache_stat_unchecked(&fscache_n_invalidates);
62134
62135 /* Only permit invalidation of data files. Invalidating an index will
62136 * require the caller to release all its attachments to the tree rooted
62137@@ -476,10 +476,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
62138 {
62139 struct fscache_object *object;
62140
62141- fscache_stat(&fscache_n_updates);
62142+ fscache_stat_unchecked(&fscache_n_updates);
62143
62144 if (!cookie) {
62145- fscache_stat(&fscache_n_updates_null);
62146+ fscache_stat_unchecked(&fscache_n_updates_null);
62147 _leave(" [no cookie]");
62148 return;
62149 }
62150@@ -580,12 +580,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
62151 */
62152 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
62153 {
62154- fscache_stat(&fscache_n_relinquishes);
62155+ fscache_stat_unchecked(&fscache_n_relinquishes);
62156 if (retire)
62157- fscache_stat(&fscache_n_relinquishes_retire);
62158+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
62159
62160 if (!cookie) {
62161- fscache_stat(&fscache_n_relinquishes_null);
62162+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
62163 _leave(" [no cookie]");
62164 return;
62165 }
62166@@ -686,7 +686,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
62167 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
62168 goto inconsistent;
62169
62170- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
62171+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
62172
62173 __fscache_use_cookie(cookie);
62174 if (fscache_submit_op(object, op) < 0)
62175diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
62176index 7872a62..d91b19f 100644
62177--- a/fs/fscache/internal.h
62178+++ b/fs/fscache/internal.h
62179@@ -137,8 +137,8 @@ extern void fscache_operation_gc(struct work_struct *);
62180 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
62181 extern int fscache_wait_for_operation_activation(struct fscache_object *,
62182 struct fscache_operation *,
62183- atomic_t *,
62184- atomic_t *,
62185+ atomic_unchecked_t *,
62186+ atomic_unchecked_t *,
62187 void (*)(struct fscache_operation *));
62188 extern void fscache_invalidate_writes(struct fscache_cookie *);
62189
62190@@ -157,101 +157,101 @@ extern void fscache_proc_cleanup(void);
62191 * stats.c
62192 */
62193 #ifdef CONFIG_FSCACHE_STATS
62194-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
62195-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
62196+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
62197+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
62198
62199-extern atomic_t fscache_n_op_pend;
62200-extern atomic_t fscache_n_op_run;
62201-extern atomic_t fscache_n_op_enqueue;
62202-extern atomic_t fscache_n_op_deferred_release;
62203-extern atomic_t fscache_n_op_release;
62204-extern atomic_t fscache_n_op_gc;
62205-extern atomic_t fscache_n_op_cancelled;
62206-extern atomic_t fscache_n_op_rejected;
62207+extern atomic_unchecked_t fscache_n_op_pend;
62208+extern atomic_unchecked_t fscache_n_op_run;
62209+extern atomic_unchecked_t fscache_n_op_enqueue;
62210+extern atomic_unchecked_t fscache_n_op_deferred_release;
62211+extern atomic_unchecked_t fscache_n_op_release;
62212+extern atomic_unchecked_t fscache_n_op_gc;
62213+extern atomic_unchecked_t fscache_n_op_cancelled;
62214+extern atomic_unchecked_t fscache_n_op_rejected;
62215
62216-extern atomic_t fscache_n_attr_changed;
62217-extern atomic_t fscache_n_attr_changed_ok;
62218-extern atomic_t fscache_n_attr_changed_nobufs;
62219-extern atomic_t fscache_n_attr_changed_nomem;
62220-extern atomic_t fscache_n_attr_changed_calls;
62221+extern atomic_unchecked_t fscache_n_attr_changed;
62222+extern atomic_unchecked_t fscache_n_attr_changed_ok;
62223+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
62224+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
62225+extern atomic_unchecked_t fscache_n_attr_changed_calls;
62226
62227-extern atomic_t fscache_n_allocs;
62228-extern atomic_t fscache_n_allocs_ok;
62229-extern atomic_t fscache_n_allocs_wait;
62230-extern atomic_t fscache_n_allocs_nobufs;
62231-extern atomic_t fscache_n_allocs_intr;
62232-extern atomic_t fscache_n_allocs_object_dead;
62233-extern atomic_t fscache_n_alloc_ops;
62234-extern atomic_t fscache_n_alloc_op_waits;
62235+extern atomic_unchecked_t fscache_n_allocs;
62236+extern atomic_unchecked_t fscache_n_allocs_ok;
62237+extern atomic_unchecked_t fscache_n_allocs_wait;
62238+extern atomic_unchecked_t fscache_n_allocs_nobufs;
62239+extern atomic_unchecked_t fscache_n_allocs_intr;
62240+extern atomic_unchecked_t fscache_n_allocs_object_dead;
62241+extern atomic_unchecked_t fscache_n_alloc_ops;
62242+extern atomic_unchecked_t fscache_n_alloc_op_waits;
62243
62244-extern atomic_t fscache_n_retrievals;
62245-extern atomic_t fscache_n_retrievals_ok;
62246-extern atomic_t fscache_n_retrievals_wait;
62247-extern atomic_t fscache_n_retrievals_nodata;
62248-extern atomic_t fscache_n_retrievals_nobufs;
62249-extern atomic_t fscache_n_retrievals_intr;
62250-extern atomic_t fscache_n_retrievals_nomem;
62251-extern atomic_t fscache_n_retrievals_object_dead;
62252-extern atomic_t fscache_n_retrieval_ops;
62253-extern atomic_t fscache_n_retrieval_op_waits;
62254+extern atomic_unchecked_t fscache_n_retrievals;
62255+extern atomic_unchecked_t fscache_n_retrievals_ok;
62256+extern atomic_unchecked_t fscache_n_retrievals_wait;
62257+extern atomic_unchecked_t fscache_n_retrievals_nodata;
62258+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
62259+extern atomic_unchecked_t fscache_n_retrievals_intr;
62260+extern atomic_unchecked_t fscache_n_retrievals_nomem;
62261+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
62262+extern atomic_unchecked_t fscache_n_retrieval_ops;
62263+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
62264
62265-extern atomic_t fscache_n_stores;
62266-extern atomic_t fscache_n_stores_ok;
62267-extern atomic_t fscache_n_stores_again;
62268-extern atomic_t fscache_n_stores_nobufs;
62269-extern atomic_t fscache_n_stores_oom;
62270-extern atomic_t fscache_n_store_ops;
62271-extern atomic_t fscache_n_store_calls;
62272-extern atomic_t fscache_n_store_pages;
62273-extern atomic_t fscache_n_store_radix_deletes;
62274-extern atomic_t fscache_n_store_pages_over_limit;
62275+extern atomic_unchecked_t fscache_n_stores;
62276+extern atomic_unchecked_t fscache_n_stores_ok;
62277+extern atomic_unchecked_t fscache_n_stores_again;
62278+extern atomic_unchecked_t fscache_n_stores_nobufs;
62279+extern atomic_unchecked_t fscache_n_stores_oom;
62280+extern atomic_unchecked_t fscache_n_store_ops;
62281+extern atomic_unchecked_t fscache_n_store_calls;
62282+extern atomic_unchecked_t fscache_n_store_pages;
62283+extern atomic_unchecked_t fscache_n_store_radix_deletes;
62284+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
62285
62286-extern atomic_t fscache_n_store_vmscan_not_storing;
62287-extern atomic_t fscache_n_store_vmscan_gone;
62288-extern atomic_t fscache_n_store_vmscan_busy;
62289-extern atomic_t fscache_n_store_vmscan_cancelled;
62290-extern atomic_t fscache_n_store_vmscan_wait;
62291+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
62292+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
62293+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
62294+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
62295+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
62296
62297-extern atomic_t fscache_n_marks;
62298-extern atomic_t fscache_n_uncaches;
62299+extern atomic_unchecked_t fscache_n_marks;
62300+extern atomic_unchecked_t fscache_n_uncaches;
62301
62302-extern atomic_t fscache_n_acquires;
62303-extern atomic_t fscache_n_acquires_null;
62304-extern atomic_t fscache_n_acquires_no_cache;
62305-extern atomic_t fscache_n_acquires_ok;
62306-extern atomic_t fscache_n_acquires_nobufs;
62307-extern atomic_t fscache_n_acquires_oom;
62308+extern atomic_unchecked_t fscache_n_acquires;
62309+extern atomic_unchecked_t fscache_n_acquires_null;
62310+extern atomic_unchecked_t fscache_n_acquires_no_cache;
62311+extern atomic_unchecked_t fscache_n_acquires_ok;
62312+extern atomic_unchecked_t fscache_n_acquires_nobufs;
62313+extern atomic_unchecked_t fscache_n_acquires_oom;
62314
62315-extern atomic_t fscache_n_invalidates;
62316-extern atomic_t fscache_n_invalidates_run;
62317+extern atomic_unchecked_t fscache_n_invalidates;
62318+extern atomic_unchecked_t fscache_n_invalidates_run;
62319
62320-extern atomic_t fscache_n_updates;
62321-extern atomic_t fscache_n_updates_null;
62322-extern atomic_t fscache_n_updates_run;
62323+extern atomic_unchecked_t fscache_n_updates;
62324+extern atomic_unchecked_t fscache_n_updates_null;
62325+extern atomic_unchecked_t fscache_n_updates_run;
62326
62327-extern atomic_t fscache_n_relinquishes;
62328-extern atomic_t fscache_n_relinquishes_null;
62329-extern atomic_t fscache_n_relinquishes_waitcrt;
62330-extern atomic_t fscache_n_relinquishes_retire;
62331+extern atomic_unchecked_t fscache_n_relinquishes;
62332+extern atomic_unchecked_t fscache_n_relinquishes_null;
62333+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
62334+extern atomic_unchecked_t fscache_n_relinquishes_retire;
62335
62336-extern atomic_t fscache_n_cookie_index;
62337-extern atomic_t fscache_n_cookie_data;
62338-extern atomic_t fscache_n_cookie_special;
62339+extern atomic_unchecked_t fscache_n_cookie_index;
62340+extern atomic_unchecked_t fscache_n_cookie_data;
62341+extern atomic_unchecked_t fscache_n_cookie_special;
62342
62343-extern atomic_t fscache_n_object_alloc;
62344-extern atomic_t fscache_n_object_no_alloc;
62345-extern atomic_t fscache_n_object_lookups;
62346-extern atomic_t fscache_n_object_lookups_negative;
62347-extern atomic_t fscache_n_object_lookups_positive;
62348-extern atomic_t fscache_n_object_lookups_timed_out;
62349-extern atomic_t fscache_n_object_created;
62350-extern atomic_t fscache_n_object_avail;
62351-extern atomic_t fscache_n_object_dead;
62352+extern atomic_unchecked_t fscache_n_object_alloc;
62353+extern atomic_unchecked_t fscache_n_object_no_alloc;
62354+extern atomic_unchecked_t fscache_n_object_lookups;
62355+extern atomic_unchecked_t fscache_n_object_lookups_negative;
62356+extern atomic_unchecked_t fscache_n_object_lookups_positive;
62357+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
62358+extern atomic_unchecked_t fscache_n_object_created;
62359+extern atomic_unchecked_t fscache_n_object_avail;
62360+extern atomic_unchecked_t fscache_n_object_dead;
62361
62362-extern atomic_t fscache_n_checkaux_none;
62363-extern atomic_t fscache_n_checkaux_okay;
62364-extern atomic_t fscache_n_checkaux_update;
62365-extern atomic_t fscache_n_checkaux_obsolete;
62366+extern atomic_unchecked_t fscache_n_checkaux_none;
62367+extern atomic_unchecked_t fscache_n_checkaux_okay;
62368+extern atomic_unchecked_t fscache_n_checkaux_update;
62369+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
62370
62371 extern atomic_t fscache_n_cop_alloc_object;
62372 extern atomic_t fscache_n_cop_lookup_object;
62373@@ -276,6 +276,11 @@ static inline void fscache_stat(atomic_t *stat)
62374 atomic_inc(stat);
62375 }
62376
62377+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
62378+{
62379+ atomic_inc_unchecked(stat);
62380+}
62381+
62382 static inline void fscache_stat_d(atomic_t *stat)
62383 {
62384 atomic_dec(stat);
62385@@ -288,6 +293,7 @@ extern const struct file_operations fscache_stats_fops;
62386
62387 #define __fscache_stat(stat) (NULL)
62388 #define fscache_stat(stat) do {} while (0)
62389+#define fscache_stat_unchecked(stat) do {} while (0)
62390 #define fscache_stat_d(stat) do {} while (0)
62391 #endif
62392
62393diff --git a/fs/fscache/object.c b/fs/fscache/object.c
62394index da032da..0076ce7 100644
62395--- a/fs/fscache/object.c
62396+++ b/fs/fscache/object.c
62397@@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
62398 _debug("LOOKUP \"%s\" in \"%s\"",
62399 cookie->def->name, object->cache->tag->name);
62400
62401- fscache_stat(&fscache_n_object_lookups);
62402+ fscache_stat_unchecked(&fscache_n_object_lookups);
62403 fscache_stat(&fscache_n_cop_lookup_object);
62404 ret = object->cache->ops->lookup_object(object);
62405 fscache_stat_d(&fscache_n_cop_lookup_object);
62406@@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
62407 if (ret == -ETIMEDOUT) {
62408 /* probably stuck behind another object, so move this one to
62409 * the back of the queue */
62410- fscache_stat(&fscache_n_object_lookups_timed_out);
62411+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
62412 _leave(" [timeout]");
62413 return NO_TRANSIT;
62414 }
62415@@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
62416 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
62417
62418 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
62419- fscache_stat(&fscache_n_object_lookups_negative);
62420+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
62421
62422 /* Allow write requests to begin stacking up and read requests to begin
62423 * returning ENODATA.
62424@@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
62425 /* if we were still looking up, then we must have a positive lookup
62426 * result, in which case there may be data available */
62427 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
62428- fscache_stat(&fscache_n_object_lookups_positive);
62429+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
62430
62431 /* We do (presumably) have data */
62432 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
62433@@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
62434 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
62435 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
62436 } else {
62437- fscache_stat(&fscache_n_object_created);
62438+ fscache_stat_unchecked(&fscache_n_object_created);
62439 }
62440
62441 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
62442@@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
62443 fscache_stat_d(&fscache_n_cop_lookup_complete);
62444
62445 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
62446- fscache_stat(&fscache_n_object_avail);
62447+ fscache_stat_unchecked(&fscache_n_object_avail);
62448
62449 _leave("");
62450 return transit_to(JUMPSTART_DEPS);
62451@@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
62452
62453 /* this just shifts the object release to the work processor */
62454 fscache_put_object(object);
62455- fscache_stat(&fscache_n_object_dead);
62456+ fscache_stat_unchecked(&fscache_n_object_dead);
62457
62458 _leave("");
62459 return transit_to(OBJECT_DEAD);
62460@@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
62461 enum fscache_checkaux result;
62462
62463 if (!object->cookie->def->check_aux) {
62464- fscache_stat(&fscache_n_checkaux_none);
62465+ fscache_stat_unchecked(&fscache_n_checkaux_none);
62466 return FSCACHE_CHECKAUX_OKAY;
62467 }
62468
62469@@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
62470 switch (result) {
62471 /* entry okay as is */
62472 case FSCACHE_CHECKAUX_OKAY:
62473- fscache_stat(&fscache_n_checkaux_okay);
62474+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
62475 break;
62476
62477 /* entry requires update */
62478 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
62479- fscache_stat(&fscache_n_checkaux_update);
62480+ fscache_stat_unchecked(&fscache_n_checkaux_update);
62481 break;
62482
62483 /* entry requires deletion */
62484 case FSCACHE_CHECKAUX_OBSOLETE:
62485- fscache_stat(&fscache_n_checkaux_obsolete);
62486+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
62487 break;
62488
62489 default:
62490@@ -993,7 +993,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
62491 {
62492 const struct fscache_state *s;
62493
62494- fscache_stat(&fscache_n_invalidates_run);
62495+ fscache_stat_unchecked(&fscache_n_invalidates_run);
62496 fscache_stat(&fscache_n_cop_invalidate_object);
62497 s = _fscache_invalidate_object(object, event);
62498 fscache_stat_d(&fscache_n_cop_invalidate_object);
62499@@ -1008,7 +1008,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
62500 {
62501 _enter("{OBJ%x},%d", object->debug_id, event);
62502
62503- fscache_stat(&fscache_n_updates_run);
62504+ fscache_stat_unchecked(&fscache_n_updates_run);
62505 fscache_stat(&fscache_n_cop_update_object);
62506 object->cache->ops->update_object(object);
62507 fscache_stat_d(&fscache_n_cop_update_object);
62508diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
62509index e7b87a0..a85d47a 100644
62510--- a/fs/fscache/operation.c
62511+++ b/fs/fscache/operation.c
62512@@ -17,7 +17,7 @@
62513 #include <linux/slab.h>
62514 #include "internal.h"
62515
62516-atomic_t fscache_op_debug_id;
62517+atomic_unchecked_t fscache_op_debug_id;
62518 EXPORT_SYMBOL(fscache_op_debug_id);
62519
62520 /**
62521@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
62522 ASSERTCMP(atomic_read(&op->usage), >, 0);
62523 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
62524
62525- fscache_stat(&fscache_n_op_enqueue);
62526+ fscache_stat_unchecked(&fscache_n_op_enqueue);
62527 switch (op->flags & FSCACHE_OP_TYPE) {
62528 case FSCACHE_OP_ASYNC:
62529 _debug("queue async");
62530@@ -72,7 +72,7 @@ static void fscache_run_op(struct fscache_object *object,
62531 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
62532 if (op->processor)
62533 fscache_enqueue_operation(op);
62534- fscache_stat(&fscache_n_op_run);
62535+ fscache_stat_unchecked(&fscache_n_op_run);
62536 }
62537
62538 /*
62539@@ -104,11 +104,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
62540 if (object->n_in_progress > 0) {
62541 atomic_inc(&op->usage);
62542 list_add_tail(&op->pend_link, &object->pending_ops);
62543- fscache_stat(&fscache_n_op_pend);
62544+ fscache_stat_unchecked(&fscache_n_op_pend);
62545 } else if (!list_empty(&object->pending_ops)) {
62546 atomic_inc(&op->usage);
62547 list_add_tail(&op->pend_link, &object->pending_ops);
62548- fscache_stat(&fscache_n_op_pend);
62549+ fscache_stat_unchecked(&fscache_n_op_pend);
62550 fscache_start_operations(object);
62551 } else {
62552 ASSERTCMP(object->n_in_progress, ==, 0);
62553@@ -124,7 +124,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
62554 object->n_exclusive++; /* reads and writes must wait */
62555 atomic_inc(&op->usage);
62556 list_add_tail(&op->pend_link, &object->pending_ops);
62557- fscache_stat(&fscache_n_op_pend);
62558+ fscache_stat_unchecked(&fscache_n_op_pend);
62559 ret = 0;
62560 } else {
62561 /* If we're in any other state, there must have been an I/O
62562@@ -211,11 +211,11 @@ int fscache_submit_op(struct fscache_object *object,
62563 if (object->n_exclusive > 0) {
62564 atomic_inc(&op->usage);
62565 list_add_tail(&op->pend_link, &object->pending_ops);
62566- fscache_stat(&fscache_n_op_pend);
62567+ fscache_stat_unchecked(&fscache_n_op_pend);
62568 } else if (!list_empty(&object->pending_ops)) {
62569 atomic_inc(&op->usage);
62570 list_add_tail(&op->pend_link, &object->pending_ops);
62571- fscache_stat(&fscache_n_op_pend);
62572+ fscache_stat_unchecked(&fscache_n_op_pend);
62573 fscache_start_operations(object);
62574 } else {
62575 ASSERTCMP(object->n_exclusive, ==, 0);
62576@@ -227,10 +227,10 @@ int fscache_submit_op(struct fscache_object *object,
62577 object->n_ops++;
62578 atomic_inc(&op->usage);
62579 list_add_tail(&op->pend_link, &object->pending_ops);
62580- fscache_stat(&fscache_n_op_pend);
62581+ fscache_stat_unchecked(&fscache_n_op_pend);
62582 ret = 0;
62583 } else if (fscache_object_is_dying(object)) {
62584- fscache_stat(&fscache_n_op_rejected);
62585+ fscache_stat_unchecked(&fscache_n_op_rejected);
62586 op->state = FSCACHE_OP_ST_CANCELLED;
62587 ret = -ENOBUFS;
62588 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
62589@@ -309,7 +309,7 @@ int fscache_cancel_op(struct fscache_operation *op,
62590 ret = -EBUSY;
62591 if (op->state == FSCACHE_OP_ST_PENDING) {
62592 ASSERT(!list_empty(&op->pend_link));
62593- fscache_stat(&fscache_n_op_cancelled);
62594+ fscache_stat_unchecked(&fscache_n_op_cancelled);
62595 list_del_init(&op->pend_link);
62596 if (do_cancel)
62597 do_cancel(op);
62598@@ -341,7 +341,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
62599 while (!list_empty(&object->pending_ops)) {
62600 op = list_entry(object->pending_ops.next,
62601 struct fscache_operation, pend_link);
62602- fscache_stat(&fscache_n_op_cancelled);
62603+ fscache_stat_unchecked(&fscache_n_op_cancelled);
62604 list_del_init(&op->pend_link);
62605
62606 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
62607@@ -413,7 +413,7 @@ void fscache_put_operation(struct fscache_operation *op)
62608 op->state, ==, FSCACHE_OP_ST_CANCELLED);
62609 op->state = FSCACHE_OP_ST_DEAD;
62610
62611- fscache_stat(&fscache_n_op_release);
62612+ fscache_stat_unchecked(&fscache_n_op_release);
62613
62614 if (op->release) {
62615 op->release(op);
62616@@ -432,7 +432,7 @@ void fscache_put_operation(struct fscache_operation *op)
62617 * lock, and defer it otherwise */
62618 if (!spin_trylock(&object->lock)) {
62619 _debug("defer put");
62620- fscache_stat(&fscache_n_op_deferred_release);
62621+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
62622
62623 cache = object->cache;
62624 spin_lock(&cache->op_gc_list_lock);
62625@@ -485,7 +485,7 @@ void fscache_operation_gc(struct work_struct *work)
62626
62627 _debug("GC DEFERRED REL OBJ%x OP%x",
62628 object->debug_id, op->debug_id);
62629- fscache_stat(&fscache_n_op_gc);
62630+ fscache_stat_unchecked(&fscache_n_op_gc);
62631
62632 ASSERTCMP(atomic_read(&op->usage), ==, 0);
62633 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
62634diff --git a/fs/fscache/page.c b/fs/fscache/page.c
62635index de33b3f..8be4d29 100644
62636--- a/fs/fscache/page.c
62637+++ b/fs/fscache/page.c
62638@@ -74,7 +74,7 @@ try_again:
62639 val = radix_tree_lookup(&cookie->stores, page->index);
62640 if (!val) {
62641 rcu_read_unlock();
62642- fscache_stat(&fscache_n_store_vmscan_not_storing);
62643+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
62644 __fscache_uncache_page(cookie, page);
62645 return true;
62646 }
62647@@ -104,11 +104,11 @@ try_again:
62648 spin_unlock(&cookie->stores_lock);
62649
62650 if (xpage) {
62651- fscache_stat(&fscache_n_store_vmscan_cancelled);
62652- fscache_stat(&fscache_n_store_radix_deletes);
62653+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
62654+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
62655 ASSERTCMP(xpage, ==, page);
62656 } else {
62657- fscache_stat(&fscache_n_store_vmscan_gone);
62658+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
62659 }
62660
62661 wake_up_bit(&cookie->flags, 0);
62662@@ -123,11 +123,11 @@ page_busy:
62663 * sleeping on memory allocation, so we may need to impose a timeout
62664 * too. */
62665 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
62666- fscache_stat(&fscache_n_store_vmscan_busy);
62667+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
62668 return false;
62669 }
62670
62671- fscache_stat(&fscache_n_store_vmscan_wait);
62672+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
62673 if (!release_page_wait_timeout(cookie, page))
62674 _debug("fscache writeout timeout page: %p{%lx}",
62675 page, page->index);
62676@@ -156,7 +156,7 @@ static void fscache_end_page_write(struct fscache_object *object,
62677 FSCACHE_COOKIE_STORING_TAG);
62678 if (!radix_tree_tag_get(&cookie->stores, page->index,
62679 FSCACHE_COOKIE_PENDING_TAG)) {
62680- fscache_stat(&fscache_n_store_radix_deletes);
62681+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
62682 xpage = radix_tree_delete(&cookie->stores, page->index);
62683 }
62684 spin_unlock(&cookie->stores_lock);
62685@@ -177,7 +177,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
62686
62687 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
62688
62689- fscache_stat(&fscache_n_attr_changed_calls);
62690+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
62691
62692 if (fscache_object_is_active(object)) {
62693 fscache_stat(&fscache_n_cop_attr_changed);
62694@@ -204,11 +204,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
62695
62696 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
62697
62698- fscache_stat(&fscache_n_attr_changed);
62699+ fscache_stat_unchecked(&fscache_n_attr_changed);
62700
62701 op = kzalloc(sizeof(*op), GFP_KERNEL);
62702 if (!op) {
62703- fscache_stat(&fscache_n_attr_changed_nomem);
62704+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
62705 _leave(" = -ENOMEM");
62706 return -ENOMEM;
62707 }
62708@@ -230,7 +230,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
62709 if (fscache_submit_exclusive_op(object, op) < 0)
62710 goto nobufs_dec;
62711 spin_unlock(&cookie->lock);
62712- fscache_stat(&fscache_n_attr_changed_ok);
62713+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
62714 fscache_put_operation(op);
62715 _leave(" = 0");
62716 return 0;
62717@@ -242,7 +242,7 @@ nobufs:
62718 kfree(op);
62719 if (wake_cookie)
62720 __fscache_wake_unused_cookie(cookie);
62721- fscache_stat(&fscache_n_attr_changed_nobufs);
62722+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
62723 _leave(" = %d", -ENOBUFS);
62724 return -ENOBUFS;
62725 }
62726@@ -281,7 +281,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
62727 /* allocate a retrieval operation and attempt to submit it */
62728 op = kzalloc(sizeof(*op), GFP_NOIO);
62729 if (!op) {
62730- fscache_stat(&fscache_n_retrievals_nomem);
62731+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
62732 return NULL;
62733 }
62734
62735@@ -311,12 +311,12 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
62736 return 0;
62737 }
62738
62739- fscache_stat(&fscache_n_retrievals_wait);
62740+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
62741
62742 jif = jiffies;
62743 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
62744 TASK_INTERRUPTIBLE) != 0) {
62745- fscache_stat(&fscache_n_retrievals_intr);
62746+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
62747 _leave(" = -ERESTARTSYS");
62748 return -ERESTARTSYS;
62749 }
62750@@ -345,8 +345,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
62751 */
62752 int fscache_wait_for_operation_activation(struct fscache_object *object,
62753 struct fscache_operation *op,
62754- atomic_t *stat_op_waits,
62755- atomic_t *stat_object_dead,
62756+ atomic_unchecked_t *stat_op_waits,
62757+ atomic_unchecked_t *stat_object_dead,
62758 void (*do_cancel)(struct fscache_operation *))
62759 {
62760 int ret;
62761@@ -356,7 +356,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
62762
62763 _debug(">>> WT");
62764 if (stat_op_waits)
62765- fscache_stat(stat_op_waits);
62766+ fscache_stat_unchecked(stat_op_waits);
62767 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
62768 TASK_INTERRUPTIBLE) != 0) {
62769 ret = fscache_cancel_op(op, do_cancel);
62770@@ -373,7 +373,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
62771 check_if_dead:
62772 if (op->state == FSCACHE_OP_ST_CANCELLED) {
62773 if (stat_object_dead)
62774- fscache_stat(stat_object_dead);
62775+ fscache_stat_unchecked(stat_object_dead);
62776 _leave(" = -ENOBUFS [cancelled]");
62777 return -ENOBUFS;
62778 }
62779@@ -381,7 +381,7 @@ check_if_dead:
62780 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
62781 fscache_cancel_op(op, do_cancel);
62782 if (stat_object_dead)
62783- fscache_stat(stat_object_dead);
62784+ fscache_stat_unchecked(stat_object_dead);
62785 return -ENOBUFS;
62786 }
62787 return 0;
62788@@ -409,7 +409,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
62789
62790 _enter("%p,%p,,,", cookie, page);
62791
62792- fscache_stat(&fscache_n_retrievals);
62793+ fscache_stat_unchecked(&fscache_n_retrievals);
62794
62795 if (hlist_empty(&cookie->backing_objects))
62796 goto nobufs;
62797@@ -451,7 +451,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
62798 goto nobufs_unlock_dec;
62799 spin_unlock(&cookie->lock);
62800
62801- fscache_stat(&fscache_n_retrieval_ops);
62802+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
62803
62804 /* pin the netfs read context in case we need to do the actual netfs
62805 * read because we've encountered a cache read failure */
62806@@ -482,15 +482,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
62807
62808 error:
62809 if (ret == -ENOMEM)
62810- fscache_stat(&fscache_n_retrievals_nomem);
62811+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
62812 else if (ret == -ERESTARTSYS)
62813- fscache_stat(&fscache_n_retrievals_intr);
62814+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
62815 else if (ret == -ENODATA)
62816- fscache_stat(&fscache_n_retrievals_nodata);
62817+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
62818 else if (ret < 0)
62819- fscache_stat(&fscache_n_retrievals_nobufs);
62820+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
62821 else
62822- fscache_stat(&fscache_n_retrievals_ok);
62823+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
62824
62825 fscache_put_retrieval(op);
62826 _leave(" = %d", ret);
62827@@ -505,7 +505,7 @@ nobufs_unlock:
62828 __fscache_wake_unused_cookie(cookie);
62829 kfree(op);
62830 nobufs:
62831- fscache_stat(&fscache_n_retrievals_nobufs);
62832+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
62833 _leave(" = -ENOBUFS");
62834 return -ENOBUFS;
62835 }
62836@@ -544,7 +544,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
62837
62838 _enter("%p,,%d,,,", cookie, *nr_pages);
62839
62840- fscache_stat(&fscache_n_retrievals);
62841+ fscache_stat_unchecked(&fscache_n_retrievals);
62842
62843 if (hlist_empty(&cookie->backing_objects))
62844 goto nobufs;
62845@@ -582,7 +582,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
62846 goto nobufs_unlock_dec;
62847 spin_unlock(&cookie->lock);
62848
62849- fscache_stat(&fscache_n_retrieval_ops);
62850+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
62851
62852 /* pin the netfs read context in case we need to do the actual netfs
62853 * read because we've encountered a cache read failure */
62854@@ -613,15 +613,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
62855
62856 error:
62857 if (ret == -ENOMEM)
62858- fscache_stat(&fscache_n_retrievals_nomem);
62859+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
62860 else if (ret == -ERESTARTSYS)
62861- fscache_stat(&fscache_n_retrievals_intr);
62862+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
62863 else if (ret == -ENODATA)
62864- fscache_stat(&fscache_n_retrievals_nodata);
62865+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
62866 else if (ret < 0)
62867- fscache_stat(&fscache_n_retrievals_nobufs);
62868+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
62869 else
62870- fscache_stat(&fscache_n_retrievals_ok);
62871+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
62872
62873 fscache_put_retrieval(op);
62874 _leave(" = %d", ret);
62875@@ -636,7 +636,7 @@ nobufs_unlock:
62876 if (wake_cookie)
62877 __fscache_wake_unused_cookie(cookie);
62878 nobufs:
62879- fscache_stat(&fscache_n_retrievals_nobufs);
62880+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
62881 _leave(" = -ENOBUFS");
62882 return -ENOBUFS;
62883 }
62884@@ -661,7 +661,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
62885
62886 _enter("%p,%p,,,", cookie, page);
62887
62888- fscache_stat(&fscache_n_allocs);
62889+ fscache_stat_unchecked(&fscache_n_allocs);
62890
62891 if (hlist_empty(&cookie->backing_objects))
62892 goto nobufs;
62893@@ -695,7 +695,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
62894 goto nobufs_unlock_dec;
62895 spin_unlock(&cookie->lock);
62896
62897- fscache_stat(&fscache_n_alloc_ops);
62898+ fscache_stat_unchecked(&fscache_n_alloc_ops);
62899
62900 ret = fscache_wait_for_operation_activation(
62901 object, &op->op,
62902@@ -712,11 +712,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
62903
62904 error:
62905 if (ret == -ERESTARTSYS)
62906- fscache_stat(&fscache_n_allocs_intr);
62907+ fscache_stat_unchecked(&fscache_n_allocs_intr);
62908 else if (ret < 0)
62909- fscache_stat(&fscache_n_allocs_nobufs);
62910+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
62911 else
62912- fscache_stat(&fscache_n_allocs_ok);
62913+ fscache_stat_unchecked(&fscache_n_allocs_ok);
62914
62915 fscache_put_retrieval(op);
62916 _leave(" = %d", ret);
62917@@ -730,7 +730,7 @@ nobufs_unlock:
62918 if (wake_cookie)
62919 __fscache_wake_unused_cookie(cookie);
62920 nobufs:
62921- fscache_stat(&fscache_n_allocs_nobufs);
62922+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
62923 _leave(" = -ENOBUFS");
62924 return -ENOBUFS;
62925 }
62926@@ -806,7 +806,7 @@ static void fscache_write_op(struct fscache_operation *_op)
62927
62928 spin_lock(&cookie->stores_lock);
62929
62930- fscache_stat(&fscache_n_store_calls);
62931+ fscache_stat_unchecked(&fscache_n_store_calls);
62932
62933 /* find a page to store */
62934 page = NULL;
62935@@ -817,7 +817,7 @@ static void fscache_write_op(struct fscache_operation *_op)
62936 page = results[0];
62937 _debug("gang %d [%lx]", n, page->index);
62938 if (page->index > op->store_limit) {
62939- fscache_stat(&fscache_n_store_pages_over_limit);
62940+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
62941 goto superseded;
62942 }
62943
62944@@ -829,7 +829,7 @@ static void fscache_write_op(struct fscache_operation *_op)
62945 spin_unlock(&cookie->stores_lock);
62946 spin_unlock(&object->lock);
62947
62948- fscache_stat(&fscache_n_store_pages);
62949+ fscache_stat_unchecked(&fscache_n_store_pages);
62950 fscache_stat(&fscache_n_cop_write_page);
62951 ret = object->cache->ops->write_page(op, page);
62952 fscache_stat_d(&fscache_n_cop_write_page);
62953@@ -933,7 +933,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
62954 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
62955 ASSERT(PageFsCache(page));
62956
62957- fscache_stat(&fscache_n_stores);
62958+ fscache_stat_unchecked(&fscache_n_stores);
62959
62960 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
62961 _leave(" = -ENOBUFS [invalidating]");
62962@@ -992,7 +992,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
62963 spin_unlock(&cookie->stores_lock);
62964 spin_unlock(&object->lock);
62965
62966- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
62967+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
62968 op->store_limit = object->store_limit;
62969
62970 __fscache_use_cookie(cookie);
62971@@ -1001,8 +1001,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
62972
62973 spin_unlock(&cookie->lock);
62974 radix_tree_preload_end();
62975- fscache_stat(&fscache_n_store_ops);
62976- fscache_stat(&fscache_n_stores_ok);
62977+ fscache_stat_unchecked(&fscache_n_store_ops);
62978+ fscache_stat_unchecked(&fscache_n_stores_ok);
62979
62980 /* the work queue now carries its own ref on the object */
62981 fscache_put_operation(&op->op);
62982@@ -1010,14 +1010,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
62983 return 0;
62984
62985 already_queued:
62986- fscache_stat(&fscache_n_stores_again);
62987+ fscache_stat_unchecked(&fscache_n_stores_again);
62988 already_pending:
62989 spin_unlock(&cookie->stores_lock);
62990 spin_unlock(&object->lock);
62991 spin_unlock(&cookie->lock);
62992 radix_tree_preload_end();
62993 kfree(op);
62994- fscache_stat(&fscache_n_stores_ok);
62995+ fscache_stat_unchecked(&fscache_n_stores_ok);
62996 _leave(" = 0");
62997 return 0;
62998
62999@@ -1039,14 +1039,14 @@ nobufs:
63000 kfree(op);
63001 if (wake_cookie)
63002 __fscache_wake_unused_cookie(cookie);
63003- fscache_stat(&fscache_n_stores_nobufs);
63004+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
63005 _leave(" = -ENOBUFS");
63006 return -ENOBUFS;
63007
63008 nomem_free:
63009 kfree(op);
63010 nomem:
63011- fscache_stat(&fscache_n_stores_oom);
63012+ fscache_stat_unchecked(&fscache_n_stores_oom);
63013 _leave(" = -ENOMEM");
63014 return -ENOMEM;
63015 }
63016@@ -1064,7 +1064,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
63017 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63018 ASSERTCMP(page, !=, NULL);
63019
63020- fscache_stat(&fscache_n_uncaches);
63021+ fscache_stat_unchecked(&fscache_n_uncaches);
63022
63023 /* cache withdrawal may beat us to it */
63024 if (!PageFsCache(page))
63025@@ -1115,7 +1115,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
63026 struct fscache_cookie *cookie = op->op.object->cookie;
63027
63028 #ifdef CONFIG_FSCACHE_STATS
63029- atomic_inc(&fscache_n_marks);
63030+ atomic_inc_unchecked(&fscache_n_marks);
63031 #endif
63032
63033 _debug("- mark %p{%lx}", page, page->index);
63034diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
63035index 40d13c7..ddf52b9 100644
63036--- a/fs/fscache/stats.c
63037+++ b/fs/fscache/stats.c
63038@@ -18,99 +18,99 @@
63039 /*
63040 * operation counters
63041 */
63042-atomic_t fscache_n_op_pend;
63043-atomic_t fscache_n_op_run;
63044-atomic_t fscache_n_op_enqueue;
63045-atomic_t fscache_n_op_requeue;
63046-atomic_t fscache_n_op_deferred_release;
63047-atomic_t fscache_n_op_release;
63048-atomic_t fscache_n_op_gc;
63049-atomic_t fscache_n_op_cancelled;
63050-atomic_t fscache_n_op_rejected;
63051+atomic_unchecked_t fscache_n_op_pend;
63052+atomic_unchecked_t fscache_n_op_run;
63053+atomic_unchecked_t fscache_n_op_enqueue;
63054+atomic_unchecked_t fscache_n_op_requeue;
63055+atomic_unchecked_t fscache_n_op_deferred_release;
63056+atomic_unchecked_t fscache_n_op_release;
63057+atomic_unchecked_t fscache_n_op_gc;
63058+atomic_unchecked_t fscache_n_op_cancelled;
63059+atomic_unchecked_t fscache_n_op_rejected;
63060
63061-atomic_t fscache_n_attr_changed;
63062-atomic_t fscache_n_attr_changed_ok;
63063-atomic_t fscache_n_attr_changed_nobufs;
63064-atomic_t fscache_n_attr_changed_nomem;
63065-atomic_t fscache_n_attr_changed_calls;
63066+atomic_unchecked_t fscache_n_attr_changed;
63067+atomic_unchecked_t fscache_n_attr_changed_ok;
63068+atomic_unchecked_t fscache_n_attr_changed_nobufs;
63069+atomic_unchecked_t fscache_n_attr_changed_nomem;
63070+atomic_unchecked_t fscache_n_attr_changed_calls;
63071
63072-atomic_t fscache_n_allocs;
63073-atomic_t fscache_n_allocs_ok;
63074-atomic_t fscache_n_allocs_wait;
63075-atomic_t fscache_n_allocs_nobufs;
63076-atomic_t fscache_n_allocs_intr;
63077-atomic_t fscache_n_allocs_object_dead;
63078-atomic_t fscache_n_alloc_ops;
63079-atomic_t fscache_n_alloc_op_waits;
63080+atomic_unchecked_t fscache_n_allocs;
63081+atomic_unchecked_t fscache_n_allocs_ok;
63082+atomic_unchecked_t fscache_n_allocs_wait;
63083+atomic_unchecked_t fscache_n_allocs_nobufs;
63084+atomic_unchecked_t fscache_n_allocs_intr;
63085+atomic_unchecked_t fscache_n_allocs_object_dead;
63086+atomic_unchecked_t fscache_n_alloc_ops;
63087+atomic_unchecked_t fscache_n_alloc_op_waits;
63088
63089-atomic_t fscache_n_retrievals;
63090-atomic_t fscache_n_retrievals_ok;
63091-atomic_t fscache_n_retrievals_wait;
63092-atomic_t fscache_n_retrievals_nodata;
63093-atomic_t fscache_n_retrievals_nobufs;
63094-atomic_t fscache_n_retrievals_intr;
63095-atomic_t fscache_n_retrievals_nomem;
63096-atomic_t fscache_n_retrievals_object_dead;
63097-atomic_t fscache_n_retrieval_ops;
63098-atomic_t fscache_n_retrieval_op_waits;
63099+atomic_unchecked_t fscache_n_retrievals;
63100+atomic_unchecked_t fscache_n_retrievals_ok;
63101+atomic_unchecked_t fscache_n_retrievals_wait;
63102+atomic_unchecked_t fscache_n_retrievals_nodata;
63103+atomic_unchecked_t fscache_n_retrievals_nobufs;
63104+atomic_unchecked_t fscache_n_retrievals_intr;
63105+atomic_unchecked_t fscache_n_retrievals_nomem;
63106+atomic_unchecked_t fscache_n_retrievals_object_dead;
63107+atomic_unchecked_t fscache_n_retrieval_ops;
63108+atomic_unchecked_t fscache_n_retrieval_op_waits;
63109
63110-atomic_t fscache_n_stores;
63111-atomic_t fscache_n_stores_ok;
63112-atomic_t fscache_n_stores_again;
63113-atomic_t fscache_n_stores_nobufs;
63114-atomic_t fscache_n_stores_oom;
63115-atomic_t fscache_n_store_ops;
63116-atomic_t fscache_n_store_calls;
63117-atomic_t fscache_n_store_pages;
63118-atomic_t fscache_n_store_radix_deletes;
63119-atomic_t fscache_n_store_pages_over_limit;
63120+atomic_unchecked_t fscache_n_stores;
63121+atomic_unchecked_t fscache_n_stores_ok;
63122+atomic_unchecked_t fscache_n_stores_again;
63123+atomic_unchecked_t fscache_n_stores_nobufs;
63124+atomic_unchecked_t fscache_n_stores_oom;
63125+atomic_unchecked_t fscache_n_store_ops;
63126+atomic_unchecked_t fscache_n_store_calls;
63127+atomic_unchecked_t fscache_n_store_pages;
63128+atomic_unchecked_t fscache_n_store_radix_deletes;
63129+atomic_unchecked_t fscache_n_store_pages_over_limit;
63130
63131-atomic_t fscache_n_store_vmscan_not_storing;
63132-atomic_t fscache_n_store_vmscan_gone;
63133-atomic_t fscache_n_store_vmscan_busy;
63134-atomic_t fscache_n_store_vmscan_cancelled;
63135-atomic_t fscache_n_store_vmscan_wait;
63136+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
63137+atomic_unchecked_t fscache_n_store_vmscan_gone;
63138+atomic_unchecked_t fscache_n_store_vmscan_busy;
63139+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
63140+atomic_unchecked_t fscache_n_store_vmscan_wait;
63141
63142-atomic_t fscache_n_marks;
63143-atomic_t fscache_n_uncaches;
63144+atomic_unchecked_t fscache_n_marks;
63145+atomic_unchecked_t fscache_n_uncaches;
63146
63147-atomic_t fscache_n_acquires;
63148-atomic_t fscache_n_acquires_null;
63149-atomic_t fscache_n_acquires_no_cache;
63150-atomic_t fscache_n_acquires_ok;
63151-atomic_t fscache_n_acquires_nobufs;
63152-atomic_t fscache_n_acquires_oom;
63153+atomic_unchecked_t fscache_n_acquires;
63154+atomic_unchecked_t fscache_n_acquires_null;
63155+atomic_unchecked_t fscache_n_acquires_no_cache;
63156+atomic_unchecked_t fscache_n_acquires_ok;
63157+atomic_unchecked_t fscache_n_acquires_nobufs;
63158+atomic_unchecked_t fscache_n_acquires_oom;
63159
63160-atomic_t fscache_n_invalidates;
63161-atomic_t fscache_n_invalidates_run;
63162+atomic_unchecked_t fscache_n_invalidates;
63163+atomic_unchecked_t fscache_n_invalidates_run;
63164
63165-atomic_t fscache_n_updates;
63166-atomic_t fscache_n_updates_null;
63167-atomic_t fscache_n_updates_run;
63168+atomic_unchecked_t fscache_n_updates;
63169+atomic_unchecked_t fscache_n_updates_null;
63170+atomic_unchecked_t fscache_n_updates_run;
63171
63172-atomic_t fscache_n_relinquishes;
63173-atomic_t fscache_n_relinquishes_null;
63174-atomic_t fscache_n_relinquishes_waitcrt;
63175-atomic_t fscache_n_relinquishes_retire;
63176+atomic_unchecked_t fscache_n_relinquishes;
63177+atomic_unchecked_t fscache_n_relinquishes_null;
63178+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
63179+atomic_unchecked_t fscache_n_relinquishes_retire;
63180
63181-atomic_t fscache_n_cookie_index;
63182-atomic_t fscache_n_cookie_data;
63183-atomic_t fscache_n_cookie_special;
63184+atomic_unchecked_t fscache_n_cookie_index;
63185+atomic_unchecked_t fscache_n_cookie_data;
63186+atomic_unchecked_t fscache_n_cookie_special;
63187
63188-atomic_t fscache_n_object_alloc;
63189-atomic_t fscache_n_object_no_alloc;
63190-atomic_t fscache_n_object_lookups;
63191-atomic_t fscache_n_object_lookups_negative;
63192-atomic_t fscache_n_object_lookups_positive;
63193-atomic_t fscache_n_object_lookups_timed_out;
63194-atomic_t fscache_n_object_created;
63195-atomic_t fscache_n_object_avail;
63196-atomic_t fscache_n_object_dead;
63197+atomic_unchecked_t fscache_n_object_alloc;
63198+atomic_unchecked_t fscache_n_object_no_alloc;
63199+atomic_unchecked_t fscache_n_object_lookups;
63200+atomic_unchecked_t fscache_n_object_lookups_negative;
63201+atomic_unchecked_t fscache_n_object_lookups_positive;
63202+atomic_unchecked_t fscache_n_object_lookups_timed_out;
63203+atomic_unchecked_t fscache_n_object_created;
63204+atomic_unchecked_t fscache_n_object_avail;
63205+atomic_unchecked_t fscache_n_object_dead;
63206
63207-atomic_t fscache_n_checkaux_none;
63208-atomic_t fscache_n_checkaux_okay;
63209-atomic_t fscache_n_checkaux_update;
63210-atomic_t fscache_n_checkaux_obsolete;
63211+atomic_unchecked_t fscache_n_checkaux_none;
63212+atomic_unchecked_t fscache_n_checkaux_okay;
63213+atomic_unchecked_t fscache_n_checkaux_update;
63214+atomic_unchecked_t fscache_n_checkaux_obsolete;
63215
63216 atomic_t fscache_n_cop_alloc_object;
63217 atomic_t fscache_n_cop_lookup_object;
63218@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
63219 seq_puts(m, "FS-Cache statistics\n");
63220
63221 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
63222- atomic_read(&fscache_n_cookie_index),
63223- atomic_read(&fscache_n_cookie_data),
63224- atomic_read(&fscache_n_cookie_special));
63225+ atomic_read_unchecked(&fscache_n_cookie_index),
63226+ atomic_read_unchecked(&fscache_n_cookie_data),
63227+ atomic_read_unchecked(&fscache_n_cookie_special));
63228
63229 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
63230- atomic_read(&fscache_n_object_alloc),
63231- atomic_read(&fscache_n_object_no_alloc),
63232- atomic_read(&fscache_n_object_avail),
63233- atomic_read(&fscache_n_object_dead));
63234+ atomic_read_unchecked(&fscache_n_object_alloc),
63235+ atomic_read_unchecked(&fscache_n_object_no_alloc),
63236+ atomic_read_unchecked(&fscache_n_object_avail),
63237+ atomic_read_unchecked(&fscache_n_object_dead));
63238 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
63239- atomic_read(&fscache_n_checkaux_none),
63240- atomic_read(&fscache_n_checkaux_okay),
63241- atomic_read(&fscache_n_checkaux_update),
63242- atomic_read(&fscache_n_checkaux_obsolete));
63243+ atomic_read_unchecked(&fscache_n_checkaux_none),
63244+ atomic_read_unchecked(&fscache_n_checkaux_okay),
63245+ atomic_read_unchecked(&fscache_n_checkaux_update),
63246+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
63247
63248 seq_printf(m, "Pages : mrk=%u unc=%u\n",
63249- atomic_read(&fscache_n_marks),
63250- atomic_read(&fscache_n_uncaches));
63251+ atomic_read_unchecked(&fscache_n_marks),
63252+ atomic_read_unchecked(&fscache_n_uncaches));
63253
63254 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
63255 " oom=%u\n",
63256- atomic_read(&fscache_n_acquires),
63257- atomic_read(&fscache_n_acquires_null),
63258- atomic_read(&fscache_n_acquires_no_cache),
63259- atomic_read(&fscache_n_acquires_ok),
63260- atomic_read(&fscache_n_acquires_nobufs),
63261- atomic_read(&fscache_n_acquires_oom));
63262+ atomic_read_unchecked(&fscache_n_acquires),
63263+ atomic_read_unchecked(&fscache_n_acquires_null),
63264+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
63265+ atomic_read_unchecked(&fscache_n_acquires_ok),
63266+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
63267+ atomic_read_unchecked(&fscache_n_acquires_oom));
63268
63269 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
63270- atomic_read(&fscache_n_object_lookups),
63271- atomic_read(&fscache_n_object_lookups_negative),
63272- atomic_read(&fscache_n_object_lookups_positive),
63273- atomic_read(&fscache_n_object_created),
63274- atomic_read(&fscache_n_object_lookups_timed_out));
63275+ atomic_read_unchecked(&fscache_n_object_lookups),
63276+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
63277+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
63278+ atomic_read_unchecked(&fscache_n_object_created),
63279+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
63280
63281 seq_printf(m, "Invals : n=%u run=%u\n",
63282- atomic_read(&fscache_n_invalidates),
63283- atomic_read(&fscache_n_invalidates_run));
63284+ atomic_read_unchecked(&fscache_n_invalidates),
63285+ atomic_read_unchecked(&fscache_n_invalidates_run));
63286
63287 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
63288- atomic_read(&fscache_n_updates),
63289- atomic_read(&fscache_n_updates_null),
63290- atomic_read(&fscache_n_updates_run));
63291+ atomic_read_unchecked(&fscache_n_updates),
63292+ atomic_read_unchecked(&fscache_n_updates_null),
63293+ atomic_read_unchecked(&fscache_n_updates_run));
63294
63295 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
63296- atomic_read(&fscache_n_relinquishes),
63297- atomic_read(&fscache_n_relinquishes_null),
63298- atomic_read(&fscache_n_relinquishes_waitcrt),
63299- atomic_read(&fscache_n_relinquishes_retire));
63300+ atomic_read_unchecked(&fscache_n_relinquishes),
63301+ atomic_read_unchecked(&fscache_n_relinquishes_null),
63302+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
63303+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
63304
63305 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
63306- atomic_read(&fscache_n_attr_changed),
63307- atomic_read(&fscache_n_attr_changed_ok),
63308- atomic_read(&fscache_n_attr_changed_nobufs),
63309- atomic_read(&fscache_n_attr_changed_nomem),
63310- atomic_read(&fscache_n_attr_changed_calls));
63311+ atomic_read_unchecked(&fscache_n_attr_changed),
63312+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
63313+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
63314+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
63315+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
63316
63317 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
63318- atomic_read(&fscache_n_allocs),
63319- atomic_read(&fscache_n_allocs_ok),
63320- atomic_read(&fscache_n_allocs_wait),
63321- atomic_read(&fscache_n_allocs_nobufs),
63322- atomic_read(&fscache_n_allocs_intr));
63323+ atomic_read_unchecked(&fscache_n_allocs),
63324+ atomic_read_unchecked(&fscache_n_allocs_ok),
63325+ atomic_read_unchecked(&fscache_n_allocs_wait),
63326+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
63327+ atomic_read_unchecked(&fscache_n_allocs_intr));
63328 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
63329- atomic_read(&fscache_n_alloc_ops),
63330- atomic_read(&fscache_n_alloc_op_waits),
63331- atomic_read(&fscache_n_allocs_object_dead));
63332+ atomic_read_unchecked(&fscache_n_alloc_ops),
63333+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
63334+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
63335
63336 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
63337 " int=%u oom=%u\n",
63338- atomic_read(&fscache_n_retrievals),
63339- atomic_read(&fscache_n_retrievals_ok),
63340- atomic_read(&fscache_n_retrievals_wait),
63341- atomic_read(&fscache_n_retrievals_nodata),
63342- atomic_read(&fscache_n_retrievals_nobufs),
63343- atomic_read(&fscache_n_retrievals_intr),
63344- atomic_read(&fscache_n_retrievals_nomem));
63345+ atomic_read_unchecked(&fscache_n_retrievals),
63346+ atomic_read_unchecked(&fscache_n_retrievals_ok),
63347+ atomic_read_unchecked(&fscache_n_retrievals_wait),
63348+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
63349+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
63350+ atomic_read_unchecked(&fscache_n_retrievals_intr),
63351+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
63352 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
63353- atomic_read(&fscache_n_retrieval_ops),
63354- atomic_read(&fscache_n_retrieval_op_waits),
63355- atomic_read(&fscache_n_retrievals_object_dead));
63356+ atomic_read_unchecked(&fscache_n_retrieval_ops),
63357+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
63358+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
63359
63360 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
63361- atomic_read(&fscache_n_stores),
63362- atomic_read(&fscache_n_stores_ok),
63363- atomic_read(&fscache_n_stores_again),
63364- atomic_read(&fscache_n_stores_nobufs),
63365- atomic_read(&fscache_n_stores_oom));
63366+ atomic_read_unchecked(&fscache_n_stores),
63367+ atomic_read_unchecked(&fscache_n_stores_ok),
63368+ atomic_read_unchecked(&fscache_n_stores_again),
63369+ atomic_read_unchecked(&fscache_n_stores_nobufs),
63370+ atomic_read_unchecked(&fscache_n_stores_oom));
63371 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
63372- atomic_read(&fscache_n_store_ops),
63373- atomic_read(&fscache_n_store_calls),
63374- atomic_read(&fscache_n_store_pages),
63375- atomic_read(&fscache_n_store_radix_deletes),
63376- atomic_read(&fscache_n_store_pages_over_limit));
63377+ atomic_read_unchecked(&fscache_n_store_ops),
63378+ atomic_read_unchecked(&fscache_n_store_calls),
63379+ atomic_read_unchecked(&fscache_n_store_pages),
63380+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
63381+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
63382
63383 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
63384- atomic_read(&fscache_n_store_vmscan_not_storing),
63385- atomic_read(&fscache_n_store_vmscan_gone),
63386- atomic_read(&fscache_n_store_vmscan_busy),
63387- atomic_read(&fscache_n_store_vmscan_cancelled),
63388- atomic_read(&fscache_n_store_vmscan_wait));
63389+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
63390+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
63391+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
63392+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
63393+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
63394
63395 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
63396- atomic_read(&fscache_n_op_pend),
63397- atomic_read(&fscache_n_op_run),
63398- atomic_read(&fscache_n_op_enqueue),
63399- atomic_read(&fscache_n_op_cancelled),
63400- atomic_read(&fscache_n_op_rejected));
63401+ atomic_read_unchecked(&fscache_n_op_pend),
63402+ atomic_read_unchecked(&fscache_n_op_run),
63403+ atomic_read_unchecked(&fscache_n_op_enqueue),
63404+ atomic_read_unchecked(&fscache_n_op_cancelled),
63405+ atomic_read_unchecked(&fscache_n_op_rejected));
63406 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
63407- atomic_read(&fscache_n_op_deferred_release),
63408- atomic_read(&fscache_n_op_release),
63409- atomic_read(&fscache_n_op_gc));
63410+ atomic_read_unchecked(&fscache_n_op_deferred_release),
63411+ atomic_read_unchecked(&fscache_n_op_release),
63412+ atomic_read_unchecked(&fscache_n_op_gc));
63413
63414 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
63415 atomic_read(&fscache_n_cop_alloc_object),
63416diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
63417index 966ace8..030a03a 100644
63418--- a/fs/fuse/cuse.c
63419+++ b/fs/fuse/cuse.c
63420@@ -611,10 +611,12 @@ static int __init cuse_init(void)
63421 INIT_LIST_HEAD(&cuse_conntbl[i]);
63422
63423 /* inherit and extend fuse_dev_operations */
63424- cuse_channel_fops = fuse_dev_operations;
63425- cuse_channel_fops.owner = THIS_MODULE;
63426- cuse_channel_fops.open = cuse_channel_open;
63427- cuse_channel_fops.release = cuse_channel_release;
63428+ pax_open_kernel();
63429+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
63430+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
63431+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
63432+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
63433+ pax_close_kernel();
63434
63435 cuse_class = class_create(THIS_MODULE, "cuse");
63436 if (IS_ERR(cuse_class))
63437diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
63438index ca88731..8e9c55d 100644
63439--- a/fs/fuse/dev.c
63440+++ b/fs/fuse/dev.c
63441@@ -1318,7 +1318,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
63442 ret = 0;
63443 pipe_lock(pipe);
63444
63445- if (!pipe->readers) {
63446+ if (!atomic_read(&pipe->readers)) {
63447 send_sig(SIGPIPE, current, 0);
63448 if (!ret)
63449 ret = -EPIPE;
63450@@ -1347,7 +1347,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
63451 page_nr++;
63452 ret += buf->len;
63453
63454- if (pipe->files)
63455+ if (atomic_read(&pipe->files))
63456 do_wakeup = 1;
63457 }
63458
63459diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
63460index dbab798..fefa22b 100644
63461--- a/fs/fuse/dir.c
63462+++ b/fs/fuse/dir.c
63463@@ -1474,7 +1474,7 @@ static char *read_link(struct dentry *dentry)
63464 return link;
63465 }
63466
63467-static void free_link(char *link)
63468+static void free_link(const char *link)
63469 {
63470 if (!IS_ERR(link))
63471 free_page((unsigned long) link);
63472diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
63473index fd62cae..3494dfa 100644
63474--- a/fs/hostfs/hostfs_kern.c
63475+++ b/fs/hostfs/hostfs_kern.c
63476@@ -908,7 +908,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
63477
63478 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
63479 {
63480- char *s = nd_get_link(nd);
63481+ const char *s = nd_get_link(nd);
63482 if (!IS_ERR(s))
63483 __putname(s);
63484 }
63485diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
63486index 1e2872b..7aea000 100644
63487--- a/fs/hugetlbfs/inode.c
63488+++ b/fs/hugetlbfs/inode.c
63489@@ -154,6 +154,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
63490 struct mm_struct *mm = current->mm;
63491 struct vm_area_struct *vma;
63492 struct hstate *h = hstate_file(file);
63493+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
63494 struct vm_unmapped_area_info info;
63495
63496 if (len & ~huge_page_mask(h))
63497@@ -167,17 +168,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
63498 return addr;
63499 }
63500
63501+#ifdef CONFIG_PAX_RANDMMAP
63502+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
63503+#endif
63504+
63505 if (addr) {
63506 addr = ALIGN(addr, huge_page_size(h));
63507 vma = find_vma(mm, addr);
63508- if (TASK_SIZE - len >= addr &&
63509- (!vma || addr + len <= vma->vm_start))
63510+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
63511 return addr;
63512 }
63513
63514 info.flags = 0;
63515 info.length = len;
63516 info.low_limit = TASK_UNMAPPED_BASE;
63517+
63518+#ifdef CONFIG_PAX_RANDMMAP
63519+ if (mm->pax_flags & MF_PAX_RANDMMAP)
63520+ info.low_limit += mm->delta_mmap;
63521+#endif
63522+
63523 info.high_limit = TASK_SIZE;
63524 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
63525 info.align_offset = 0;
63526@@ -919,7 +929,7 @@ static struct file_system_type hugetlbfs_fs_type = {
63527 };
63528 MODULE_ALIAS_FS("hugetlbfs");
63529
63530-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
63531+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
63532
63533 static int can_do_hugetlb_shm(void)
63534 {
63535diff --git a/fs/inode.c b/fs/inode.c
63536index 26753ba..d19eb34 100644
63537--- a/fs/inode.c
63538+++ b/fs/inode.c
63539@@ -840,16 +840,20 @@ unsigned int get_next_ino(void)
63540 unsigned int *p = &get_cpu_var(last_ino);
63541 unsigned int res = *p;
63542
63543+start:
63544+
63545 #ifdef CONFIG_SMP
63546 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
63547- static atomic_t shared_last_ino;
63548- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
63549+ static atomic_unchecked_t shared_last_ino;
63550+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
63551
63552 res = next - LAST_INO_BATCH;
63553 }
63554 #endif
63555
63556- *p = ++res;
63557+ if (unlikely(!++res))
63558+ goto start; /* never zero */
63559+ *p = res;
63560 put_cpu_var(last_ino);
63561 return res;
63562 }
63563diff --git a/fs/isofs/rock.c b/fs/isofs/rock.c
63564index f488bba..735d752 100644
63565--- a/fs/isofs/rock.c
63566+++ b/fs/isofs/rock.c
63567@@ -30,6 +30,7 @@ struct rock_state {
63568 int cont_size;
63569 int cont_extent;
63570 int cont_offset;
63571+ int cont_loops;
63572 struct inode *inode;
63573 };
63574
63575@@ -73,6 +74,9 @@ static void init_rock_state(struct rock_state *rs, struct inode *inode)
63576 rs->inode = inode;
63577 }
63578
63579+/* Maximum number of Rock Ridge continuation entries */
63580+#define RR_MAX_CE_ENTRIES 32
63581+
63582 /*
63583 * Returns 0 if the caller should continue scanning, 1 if the scan must end
63584 * and -ve on error.
63585@@ -105,6 +109,8 @@ static int rock_continue(struct rock_state *rs)
63586 goto out;
63587 }
63588 ret = -EIO;
63589+ if (++rs->cont_loops >= RR_MAX_CE_ENTRIES)
63590+ goto out;
63591 bh = sb_bread(rs->inode->i_sb, rs->cont_extent);
63592 if (bh) {
63593 memcpy(rs->buffer, bh->b_data + rs->cont_offset,
63594@@ -356,6 +362,9 @@ repeat:
63595 rs.cont_size = isonum_733(rr->u.CE.size);
63596 break;
63597 case SIG('E', 'R'):
63598+ /* Invalid length of ER tag id? */
63599+ if (rr->u.ER.len_id + offsetof(struct rock_ridge, u.ER.data) > rr->len)
63600+ goto out;
63601 ISOFS_SB(inode->i_sb)->s_rock = 1;
63602 printk(KERN_DEBUG "ISO 9660 Extensions: ");
63603 {
63604diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
63605index 4a6cf28..d3a29d3 100644
63606--- a/fs/jffs2/erase.c
63607+++ b/fs/jffs2/erase.c
63608@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
63609 struct jffs2_unknown_node marker = {
63610 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
63611 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
63612- .totlen = cpu_to_je32(c->cleanmarker_size)
63613+ .totlen = cpu_to_je32(c->cleanmarker_size),
63614+ .hdr_crc = cpu_to_je32(0)
63615 };
63616
63617 jffs2_prealloc_raw_node_refs(c, jeb, 1);
63618diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
63619index 09ed551..45684f8 100644
63620--- a/fs/jffs2/wbuf.c
63621+++ b/fs/jffs2/wbuf.c
63622@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
63623 {
63624 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
63625 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
63626- .totlen = constant_cpu_to_je32(8)
63627+ .totlen = constant_cpu_to_je32(8),
63628+ .hdr_crc = constant_cpu_to_je32(0)
63629 };
63630
63631 /*
63632diff --git a/fs/jfs/super.c b/fs/jfs/super.c
63633index 93e897e..a863de4 100644
63634--- a/fs/jfs/super.c
63635+++ b/fs/jfs/super.c
63636@@ -893,7 +893,7 @@ static int __init init_jfs_fs(void)
63637
63638 jfs_inode_cachep =
63639 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
63640- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
63641+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
63642 init_once);
63643 if (jfs_inode_cachep == NULL)
63644 return -ENOMEM;
63645diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
63646index 1c77193..5cfb7b57 100644
63647--- a/fs/kernfs/dir.c
63648+++ b/fs/kernfs/dir.c
63649@@ -182,7 +182,7 @@ struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
63650 *
63651 * Returns 31 bit hash of ns + name (so it fits in an off_t )
63652 */
63653-static unsigned int kernfs_name_hash(const char *name, const void *ns)
63654+static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
63655 {
63656 unsigned long hash = init_name_hash();
63657 unsigned int len = strlen(name);
63658@@ -829,6 +829,10 @@ static int kernfs_iop_mkdir(struct inode *dir, struct dentry *dentry,
63659 ret = scops->mkdir(parent, dentry->d_name.name, mode);
63660
63661 kernfs_put_active(parent);
63662+
63663+ if (!ret)
63664+ ret = kernfs_iop_lookup(dir, dentry, 0);
63665+
63666 return ret;
63667 }
63668
63669diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
63670index 4429d6d..9831f52 100644
63671--- a/fs/kernfs/file.c
63672+++ b/fs/kernfs/file.c
63673@@ -34,7 +34,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
63674
63675 struct kernfs_open_node {
63676 atomic_t refcnt;
63677- atomic_t event;
63678+ atomic_unchecked_t event;
63679 wait_queue_head_t poll;
63680 struct list_head files; /* goes through kernfs_open_file.list */
63681 };
63682@@ -163,7 +163,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
63683 {
63684 struct kernfs_open_file *of = sf->private;
63685
63686- of->event = atomic_read(&of->kn->attr.open->event);
63687+ of->event = atomic_read_unchecked(&of->kn->attr.open->event);
63688
63689 return of->kn->attr.ops->seq_show(sf, v);
63690 }
63691@@ -375,12 +375,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
63692 return ret;
63693 }
63694
63695-static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
63696- void *buf, int len, int write)
63697+static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
63698+ void *buf, size_t len, int write)
63699 {
63700 struct file *file = vma->vm_file;
63701 struct kernfs_open_file *of = kernfs_of(file);
63702- int ret;
63703+ ssize_t ret;
63704
63705 if (!of->vm_ops)
63706 return -EINVAL;
63707@@ -581,7 +581,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
63708 return -ENOMEM;
63709
63710 atomic_set(&new_on->refcnt, 0);
63711- atomic_set(&new_on->event, 1);
63712+ atomic_set_unchecked(&new_on->event, 1);
63713 init_waitqueue_head(&new_on->poll);
63714 INIT_LIST_HEAD(&new_on->files);
63715 goto retry;
63716@@ -787,7 +787,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
63717
63718 kernfs_put_active(kn);
63719
63720- if (of->event != atomic_read(&on->event))
63721+ if (of->event != atomic_read_unchecked(&on->event))
63722 goto trigger;
63723
63724 return DEFAULT_POLLMASK;
63725@@ -818,7 +818,7 @@ repeat:
63726
63727 on = kn->attr.open;
63728 if (on) {
63729- atomic_inc(&on->event);
63730+ atomic_inc_unchecked(&on->event);
63731 wake_up_interruptible(&on->poll);
63732 }
63733
63734diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
63735index 8a19889..4c3069a 100644
63736--- a/fs/kernfs/symlink.c
63737+++ b/fs/kernfs/symlink.c
63738@@ -128,7 +128,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
63739 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
63740 void *cookie)
63741 {
63742- char *page = nd_get_link(nd);
63743+ const char *page = nd_get_link(nd);
63744 if (!IS_ERR(page))
63745 free_page((unsigned long)page);
63746 }
63747diff --git a/fs/libfs.c b/fs/libfs.c
63748index 005843c..06c4191 100644
63749--- a/fs/libfs.c
63750+++ b/fs/libfs.c
63751@@ -160,6 +160,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
63752
63753 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
63754 struct dentry *next = list_entry(p, struct dentry, d_child);
63755+ char d_name[sizeof(next->d_iname)];
63756+ const unsigned char *name;
63757+
63758 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
63759 if (!simple_positive(next)) {
63760 spin_unlock(&next->d_lock);
63761@@ -168,7 +171,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
63762
63763 spin_unlock(&next->d_lock);
63764 spin_unlock(&dentry->d_lock);
63765- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
63766+ name = next->d_name.name;
63767+ if (name == next->d_iname) {
63768+ memcpy(d_name, name, next->d_name.len);
63769+ name = d_name;
63770+ }
63771+ if (!dir_emit(ctx, name, next->d_name.len,
63772 next->d_inode->i_ino, dt_type(next->d_inode)))
63773 return 0;
63774 spin_lock(&dentry->d_lock);
63775@@ -1027,7 +1035,7 @@ EXPORT_SYMBOL(noop_fsync);
63776 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
63777 void *cookie)
63778 {
63779- char *s = nd_get_link(nd);
63780+ const char *s = nd_get_link(nd);
63781 if (!IS_ERR(s))
63782 kfree(s);
63783 }
63784diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
63785index acd3947..1f896e2 100644
63786--- a/fs/lockd/clntproc.c
63787+++ b/fs/lockd/clntproc.c
63788@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
63789 /*
63790 * Cookie counter for NLM requests
63791 */
63792-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
63793+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
63794
63795 void nlmclnt_next_cookie(struct nlm_cookie *c)
63796 {
63797- u32 cookie = atomic_inc_return(&nlm_cookie);
63798+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
63799
63800 memcpy(c->data, &cookie, 4);
63801 c->len=4;
63802diff --git a/fs/locks.c b/fs/locks.c
63803index 735b8d3..dfc44a2 100644
63804--- a/fs/locks.c
63805+++ b/fs/locks.c
63806@@ -2374,7 +2374,7 @@ void locks_remove_file(struct file *filp)
63807 locks_remove_posix(filp, filp);
63808
63809 if (filp->f_op->flock) {
63810- struct file_lock fl = {
63811+ struct file_lock flock = {
63812 .fl_owner = filp,
63813 .fl_pid = current->tgid,
63814 .fl_file = filp,
63815@@ -2382,9 +2382,9 @@ void locks_remove_file(struct file *filp)
63816 .fl_type = F_UNLCK,
63817 .fl_end = OFFSET_MAX,
63818 };
63819- filp->f_op->flock(filp, F_SETLKW, &fl);
63820- if (fl.fl_ops && fl.fl_ops->fl_release_private)
63821- fl.fl_ops->fl_release_private(&fl);
63822+ filp->f_op->flock(filp, F_SETLKW, &flock);
63823+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
63824+ flock.fl_ops->fl_release_private(&flock);
63825 }
63826
63827 spin_lock(&inode->i_lock);
63828diff --git a/fs/mount.h b/fs/mount.h
63829index f82c628..9492b99 100644
63830--- a/fs/mount.h
63831+++ b/fs/mount.h
63832@@ -11,7 +11,7 @@ struct mnt_namespace {
63833 u64 seq; /* Sequence number to prevent loops */
63834 wait_queue_head_t poll;
63835 u64 event;
63836-};
63837+} __randomize_layout;
63838
63839 struct mnt_pcp {
63840 int mnt_count;
63841@@ -62,7 +62,7 @@ struct mount {
63842 int mnt_expiry_mark; /* true if marked for expiry */
63843 struct hlist_head mnt_pins;
63844 struct path mnt_ex_mountpoint;
63845-};
63846+} __randomize_layout;
63847
63848 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
63849
63850diff --git a/fs/namei.c b/fs/namei.c
63851index db5fe86..d3dcc14 100644
63852--- a/fs/namei.c
63853+++ b/fs/namei.c
63854@@ -331,17 +331,32 @@ int generic_permission(struct inode *inode, int mask)
63855 if (ret != -EACCES)
63856 return ret;
63857
63858+#ifdef CONFIG_GRKERNSEC
63859+ /* we'll block if we have to log due to a denied capability use */
63860+ if (mask & MAY_NOT_BLOCK)
63861+ return -ECHILD;
63862+#endif
63863+
63864 if (S_ISDIR(inode->i_mode)) {
63865 /* DACs are overridable for directories */
63866- if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
63867- return 0;
63868 if (!(mask & MAY_WRITE))
63869- if (capable_wrt_inode_uidgid(inode,
63870- CAP_DAC_READ_SEARCH))
63871+ if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
63872+ capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
63873 return 0;
63874+ if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
63875+ return 0;
63876 return -EACCES;
63877 }
63878 /*
63879+ * Searching includes executable on directories, else just read.
63880+ */
63881+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
63882+ if (mask == MAY_READ)
63883+ if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
63884+ capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
63885+ return 0;
63886+
63887+ /*
63888 * Read/write DACs are always overridable.
63889 * Executable DACs are overridable when there is
63890 * at least one exec bit set.
63891@@ -350,14 +365,6 @@ int generic_permission(struct inode *inode, int mask)
63892 if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
63893 return 0;
63894
63895- /*
63896- * Searching includes executable on directories, else just read.
63897- */
63898- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
63899- if (mask == MAY_READ)
63900- if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
63901- return 0;
63902-
63903 return -EACCES;
63904 }
63905 EXPORT_SYMBOL(generic_permission);
63906@@ -824,7 +831,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
63907 {
63908 struct dentry *dentry = link->dentry;
63909 int error;
63910- char *s;
63911+ const char *s;
63912
63913 BUG_ON(nd->flags & LOOKUP_RCU);
63914
63915@@ -845,6 +852,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
63916 if (error)
63917 goto out_put_nd_path;
63918
63919+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
63920+ dentry->d_inode, dentry, nd->path.mnt)) {
63921+ error = -EACCES;
63922+ goto out_put_nd_path;
63923+ }
63924+
63925 nd->last_type = LAST_BIND;
63926 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
63927 error = PTR_ERR(*p);
63928@@ -1608,6 +1621,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
63929 if (res)
63930 break;
63931 res = walk_component(nd, path, LOOKUP_FOLLOW);
63932+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
63933+ res = -EACCES;
63934 put_link(nd, &link, cookie);
63935 } while (res > 0);
63936
63937@@ -1680,7 +1695,7 @@ EXPORT_SYMBOL(full_name_hash);
63938 static inline u64 hash_name(const char *name)
63939 {
63940 unsigned long a, b, adata, bdata, mask, hash, len;
63941- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
63942+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
63943
63944 hash = a = 0;
63945 len = -sizeof(unsigned long);
63946@@ -1969,6 +1984,8 @@ static int path_lookupat(int dfd, const char *name,
63947 if (err)
63948 break;
63949 err = lookup_last(nd, &path);
63950+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
63951+ err = -EACCES;
63952 put_link(nd, &link, cookie);
63953 }
63954 }
63955@@ -1976,6 +1993,13 @@ static int path_lookupat(int dfd, const char *name,
63956 if (!err)
63957 err = complete_walk(nd);
63958
63959+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
63960+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
63961+ path_put(&nd->path);
63962+ err = -ENOENT;
63963+ }
63964+ }
63965+
63966 if (!err && nd->flags & LOOKUP_DIRECTORY) {
63967 if (!d_can_lookup(nd->path.dentry)) {
63968 path_put(&nd->path);
63969@@ -2004,8 +2028,15 @@ static int filename_lookup(int dfd, struct filename *name,
63970 retval = path_lookupat(dfd, name->name,
63971 flags | LOOKUP_REVAL, nd);
63972
63973- if (likely(!retval))
63974+ if (likely(!retval)) {
63975 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
63976+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
63977+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
63978+ path_put(&nd->path);
63979+ return -ENOENT;
63980+ }
63981+ }
63982+ }
63983 return retval;
63984 }
63985
63986@@ -2582,6 +2613,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
63987 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
63988 return -EPERM;
63989
63990+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
63991+ return -EPERM;
63992+ if (gr_handle_rawio(inode))
63993+ return -EPERM;
63994+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
63995+ return -EACCES;
63996+
63997 return 0;
63998 }
63999
64000@@ -2813,7 +2851,7 @@ looked_up:
64001 * cleared otherwise prior to returning.
64002 */
64003 static int lookup_open(struct nameidata *nd, struct path *path,
64004- struct file *file,
64005+ struct path *link, struct file *file,
64006 const struct open_flags *op,
64007 bool got_write, int *opened)
64008 {
64009@@ -2848,6 +2886,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
64010 /* Negative dentry, just create the file */
64011 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
64012 umode_t mode = op->mode;
64013+
64014+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
64015+ error = -EACCES;
64016+ goto out_dput;
64017+ }
64018+
64019+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
64020+ error = -EACCES;
64021+ goto out_dput;
64022+ }
64023+
64024 if (!IS_POSIXACL(dir->d_inode))
64025 mode &= ~current_umask();
64026 /*
64027@@ -2869,6 +2918,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
64028 nd->flags & LOOKUP_EXCL);
64029 if (error)
64030 goto out_dput;
64031+ else
64032+ gr_handle_create(dentry, nd->path.mnt);
64033 }
64034 out_no_open:
64035 path->dentry = dentry;
64036@@ -2883,7 +2934,7 @@ out_dput:
64037 /*
64038 * Handle the last step of open()
64039 */
64040-static int do_last(struct nameidata *nd, struct path *path,
64041+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
64042 struct file *file, const struct open_flags *op,
64043 int *opened, struct filename *name)
64044 {
64045@@ -2933,6 +2984,15 @@ static int do_last(struct nameidata *nd, struct path *path,
64046 if (error)
64047 return error;
64048
64049+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
64050+ error = -ENOENT;
64051+ goto out;
64052+ }
64053+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
64054+ error = -EACCES;
64055+ goto out;
64056+ }
64057+
64058 audit_inode(name, dir, LOOKUP_PARENT);
64059 error = -EISDIR;
64060 /* trailing slashes? */
64061@@ -2952,7 +3012,7 @@ retry_lookup:
64062 */
64063 }
64064 mutex_lock(&dir->d_inode->i_mutex);
64065- error = lookup_open(nd, path, file, op, got_write, opened);
64066+ error = lookup_open(nd, path, link, file, op, got_write, opened);
64067 mutex_unlock(&dir->d_inode->i_mutex);
64068
64069 if (error <= 0) {
64070@@ -2976,11 +3036,28 @@ retry_lookup:
64071 goto finish_open_created;
64072 }
64073
64074+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
64075+ error = -ENOENT;
64076+ goto exit_dput;
64077+ }
64078+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
64079+ error = -EACCES;
64080+ goto exit_dput;
64081+ }
64082+
64083 /*
64084 * create/update audit record if it already exists.
64085 */
64086- if (d_is_positive(path->dentry))
64087+ if (d_is_positive(path->dentry)) {
64088+ /* only check if O_CREAT is specified, all other checks need to go
64089+ into may_open */
64090+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
64091+ error = -EACCES;
64092+ goto exit_dput;
64093+ }
64094+
64095 audit_inode(name, path->dentry, 0);
64096+ }
64097
64098 /*
64099 * If atomic_open() acquired write access it is dropped now due to
64100@@ -3021,6 +3098,11 @@ finish_lookup:
64101 }
64102 }
64103 BUG_ON(inode != path->dentry->d_inode);
64104+ /* if we're resolving a symlink to another symlink */
64105+ if (link && gr_handle_symlink_owner(link, inode)) {
64106+ error = -EACCES;
64107+ goto out;
64108+ }
64109 return 1;
64110 }
64111
64112@@ -3040,7 +3122,18 @@ finish_open:
64113 path_put(&save_parent);
64114 return error;
64115 }
64116+
64117+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
64118+ error = -ENOENT;
64119+ goto out;
64120+ }
64121+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
64122+ error = -EACCES;
64123+ goto out;
64124+ }
64125+
64126 audit_inode(name, nd->path.dentry, 0);
64127+
64128 error = -EISDIR;
64129 if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
64130 goto out;
64131@@ -3207,7 +3300,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
64132 if (unlikely(error))
64133 goto out;
64134
64135- error = do_last(nd, &path, file, op, &opened, pathname);
64136+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
64137 while (unlikely(error > 0)) { /* trailing symlink */
64138 struct path link = path;
64139 void *cookie;
64140@@ -3225,7 +3318,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
64141 error = follow_link(&link, nd, &cookie);
64142 if (unlikely(error))
64143 break;
64144- error = do_last(nd, &path, file, op, &opened, pathname);
64145+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
64146 put_link(nd, &link, cookie);
64147 }
64148 out:
64149@@ -3325,9 +3418,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
64150 goto unlock;
64151
64152 error = -EEXIST;
64153- if (d_is_positive(dentry))
64154+ if (d_is_positive(dentry)) {
64155+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
64156+ error = -ENOENT;
64157 goto fail;
64158-
64159+ }
64160 /*
64161 * Special case - lookup gave negative, but... we had foo/bar/
64162 * From the vfs_mknod() POV we just have a negative dentry -
64163@@ -3379,6 +3474,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
64164 }
64165 EXPORT_SYMBOL(user_path_create);
64166
64167+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
64168+{
64169+ struct filename *tmp = getname(pathname);
64170+ struct dentry *res;
64171+ if (IS_ERR(tmp))
64172+ return ERR_CAST(tmp);
64173+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
64174+ if (IS_ERR(res))
64175+ putname(tmp);
64176+ else
64177+ *to = tmp;
64178+ return res;
64179+}
64180+
64181 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
64182 {
64183 int error = may_create(dir, dentry);
64184@@ -3442,6 +3551,17 @@ retry:
64185
64186 if (!IS_POSIXACL(path.dentry->d_inode))
64187 mode &= ~current_umask();
64188+
64189+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
64190+ error = -EPERM;
64191+ goto out;
64192+ }
64193+
64194+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
64195+ error = -EACCES;
64196+ goto out;
64197+ }
64198+
64199 error = security_path_mknod(&path, dentry, mode, dev);
64200 if (error)
64201 goto out;
64202@@ -3457,6 +3577,8 @@ retry:
64203 error = vfs_mknod(path.dentry->d_inode,dentry,mode,0);
64204 break;
64205 }
64206+ if (!error)
64207+ gr_handle_create(dentry, path.mnt);
64208 out:
64209 done_path_create(&path, dentry);
64210 if (retry_estale(error, lookup_flags)) {
64211@@ -3511,9 +3633,16 @@ retry:
64212
64213 if (!IS_POSIXACL(path.dentry->d_inode))
64214 mode &= ~current_umask();
64215+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
64216+ error = -EACCES;
64217+ goto out;
64218+ }
64219 error = security_path_mkdir(&path, dentry, mode);
64220 if (!error)
64221 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
64222+ if (!error)
64223+ gr_handle_create(dentry, path.mnt);
64224+out:
64225 done_path_create(&path, dentry);
64226 if (retry_estale(error, lookup_flags)) {
64227 lookup_flags |= LOOKUP_REVAL;
64228@@ -3597,6 +3726,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
64229 struct filename *name;
64230 struct dentry *dentry;
64231 struct nameidata nd;
64232+ ino_t saved_ino = 0;
64233+ dev_t saved_dev = 0;
64234 unsigned int lookup_flags = 0;
64235 retry:
64236 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
64237@@ -3629,10 +3760,21 @@ retry:
64238 error = -ENOENT;
64239 goto exit3;
64240 }
64241+
64242+ saved_ino = dentry->d_inode->i_ino;
64243+ saved_dev = gr_get_dev_from_dentry(dentry);
64244+
64245+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
64246+ error = -EACCES;
64247+ goto exit3;
64248+ }
64249+
64250 error = security_path_rmdir(&nd.path, dentry);
64251 if (error)
64252 goto exit3;
64253 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
64254+ if (!error && (saved_dev || saved_ino))
64255+ gr_handle_delete(saved_ino, saved_dev);
64256 exit3:
64257 dput(dentry);
64258 exit2:
64259@@ -3725,6 +3867,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
64260 struct nameidata nd;
64261 struct inode *inode = NULL;
64262 struct inode *delegated_inode = NULL;
64263+ ino_t saved_ino = 0;
64264+ dev_t saved_dev = 0;
64265 unsigned int lookup_flags = 0;
64266 retry:
64267 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
64268@@ -3751,10 +3895,22 @@ retry_deleg:
64269 if (d_is_negative(dentry))
64270 goto slashes;
64271 ihold(inode);
64272+
64273+ if (inode->i_nlink <= 1) {
64274+ saved_ino = inode->i_ino;
64275+ saved_dev = gr_get_dev_from_dentry(dentry);
64276+ }
64277+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
64278+ error = -EACCES;
64279+ goto exit2;
64280+ }
64281+
64282 error = security_path_unlink(&nd.path, dentry);
64283 if (error)
64284 goto exit2;
64285 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
64286+ if (!error && (saved_ino || saved_dev))
64287+ gr_handle_delete(saved_ino, saved_dev);
64288 exit2:
64289 dput(dentry);
64290 }
64291@@ -3843,9 +3999,17 @@ retry:
64292 if (IS_ERR(dentry))
64293 goto out_putname;
64294
64295+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
64296+ error = -EACCES;
64297+ goto out;
64298+ }
64299+
64300 error = security_path_symlink(&path, dentry, from->name);
64301 if (!error)
64302 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
64303+ if (!error)
64304+ gr_handle_create(dentry, path.mnt);
64305+out:
64306 done_path_create(&path, dentry);
64307 if (retry_estale(error, lookup_flags)) {
64308 lookup_flags |= LOOKUP_REVAL;
64309@@ -3949,6 +4113,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
64310 struct dentry *new_dentry;
64311 struct path old_path, new_path;
64312 struct inode *delegated_inode = NULL;
64313+ struct filename *to = NULL;
64314 int how = 0;
64315 int error;
64316
64317@@ -3972,7 +4137,7 @@ retry:
64318 if (error)
64319 return error;
64320
64321- new_dentry = user_path_create(newdfd, newname, &new_path,
64322+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
64323 (how & LOOKUP_REVAL));
64324 error = PTR_ERR(new_dentry);
64325 if (IS_ERR(new_dentry))
64326@@ -3984,11 +4149,28 @@ retry:
64327 error = may_linkat(&old_path);
64328 if (unlikely(error))
64329 goto out_dput;
64330+
64331+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
64332+ old_path.dentry->d_inode,
64333+ old_path.dentry->d_inode->i_mode, to)) {
64334+ error = -EACCES;
64335+ goto out_dput;
64336+ }
64337+
64338+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
64339+ old_path.dentry, old_path.mnt, to)) {
64340+ error = -EACCES;
64341+ goto out_dput;
64342+ }
64343+
64344 error = security_path_link(old_path.dentry, &new_path, new_dentry);
64345 if (error)
64346 goto out_dput;
64347 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
64348+ if (!error)
64349+ gr_handle_create(new_dentry, new_path.mnt);
64350 out_dput:
64351+ putname(to);
64352 done_path_create(&new_path, new_dentry);
64353 if (delegated_inode) {
64354 error = break_deleg_wait(&delegated_inode);
64355@@ -4304,6 +4486,12 @@ retry_deleg:
64356 if (new_dentry == trap)
64357 goto exit5;
64358
64359+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
64360+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
64361+ to, flags);
64362+ if (error)
64363+ goto exit5;
64364+
64365 error = security_path_rename(&oldnd.path, old_dentry,
64366 &newnd.path, new_dentry, flags);
64367 if (error)
64368@@ -4311,6 +4499,9 @@ retry_deleg:
64369 error = vfs_rename(old_dir->d_inode, old_dentry,
64370 new_dir->d_inode, new_dentry,
64371 &delegated_inode, flags);
64372+ if (!error)
64373+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
64374+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0, flags);
64375 exit5:
64376 dput(new_dentry);
64377 exit4:
64378@@ -4367,14 +4558,24 @@ EXPORT_SYMBOL(vfs_whiteout);
64379
64380 int readlink_copy(char __user *buffer, int buflen, const char *link)
64381 {
64382+ char tmpbuf[64];
64383+ const char *newlink;
64384 int len = PTR_ERR(link);
64385+
64386 if (IS_ERR(link))
64387 goto out;
64388
64389 len = strlen(link);
64390 if (len > (unsigned) buflen)
64391 len = buflen;
64392- if (copy_to_user(buffer, link, len))
64393+
64394+ if (len < sizeof(tmpbuf)) {
64395+ memcpy(tmpbuf, link, len);
64396+ newlink = tmpbuf;
64397+ } else
64398+ newlink = link;
64399+
64400+ if (copy_to_user(buffer, newlink, len))
64401 len = -EFAULT;
64402 out:
64403 return len;
64404diff --git a/fs/namespace.c b/fs/namespace.c
64405index 5b66b2b..4d8290d 100644
64406--- a/fs/namespace.c
64407+++ b/fs/namespace.c
64408@@ -1369,6 +1369,8 @@ void umount_tree(struct mount *mnt, int how)
64409 }
64410 if (last) {
64411 last->mnt_hash.next = unmounted.first;
64412+ if (unmounted.first)
64413+ unmounted.first->pprev = &last->mnt_hash.next;
64414 unmounted.first = tmp_list.first;
64415 unmounted.first->pprev = &unmounted.first;
64416 }
64417@@ -1445,6 +1447,9 @@ static int do_umount(struct mount *mnt, int flags)
64418 if (!(sb->s_flags & MS_RDONLY))
64419 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
64420 up_write(&sb->s_umount);
64421+
64422+ gr_log_remount(mnt->mnt_devname, retval);
64423+
64424 return retval;
64425 }
64426
64427@@ -1467,6 +1472,9 @@ static int do_umount(struct mount *mnt, int flags)
64428 }
64429 unlock_mount_hash();
64430 namespace_unlock();
64431+
64432+ gr_log_unmount(mnt->mnt_devname, retval);
64433+
64434 return retval;
64435 }
64436
64437@@ -1517,7 +1525,7 @@ static inline bool may_mount(void)
64438 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
64439 */
64440
64441-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
64442+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
64443 {
64444 struct path path;
64445 struct mount *mnt;
64446@@ -1559,7 +1567,7 @@ out:
64447 /*
64448 * The 2.0 compatible umount. No flags.
64449 */
64450-SYSCALL_DEFINE1(oldumount, char __user *, name)
64451+SYSCALL_DEFINE1(oldumount, const char __user *, name)
64452 {
64453 return sys_umount(name, 0);
64454 }
64455@@ -2621,6 +2629,16 @@ long do_mount(const char *dev_name, const char __user *dir_name,
64456 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
64457 MS_STRICTATIME);
64458
64459+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
64460+ retval = -EPERM;
64461+ goto dput_out;
64462+ }
64463+
64464+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
64465+ retval = -EPERM;
64466+ goto dput_out;
64467+ }
64468+
64469 if (flags & MS_REMOUNT)
64470 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
64471 data_page);
64472@@ -2634,7 +2652,10 @@ long do_mount(const char *dev_name, const char __user *dir_name,
64473 retval = do_new_mount(&path, type_page, flags, mnt_flags,
64474 dev_name, data_page);
64475 dput_out:
64476+ gr_log_mount(dev_name, &path, retval);
64477+
64478 path_put(&path);
64479+
64480 return retval;
64481 }
64482
64483@@ -2652,7 +2673,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
64484 * number incrementing at 10Ghz will take 12,427 years to wrap which
64485 * is effectively never, so we can ignore the possibility.
64486 */
64487-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
64488+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
64489
64490 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64491 {
64492@@ -2667,7 +2688,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64493 kfree(new_ns);
64494 return ERR_PTR(ret);
64495 }
64496- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
64497+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
64498 atomic_set(&new_ns->count, 1);
64499 new_ns->root = NULL;
64500 INIT_LIST_HEAD(&new_ns->list);
64501@@ -2677,7 +2698,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64502 return new_ns;
64503 }
64504
64505-struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
64506+__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
64507 struct user_namespace *user_ns, struct fs_struct *new_fs)
64508 {
64509 struct mnt_namespace *new_ns;
64510@@ -2798,8 +2819,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
64511 }
64512 EXPORT_SYMBOL(mount_subtree);
64513
64514-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
64515- char __user *, type, unsigned long, flags, void __user *, data)
64516+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
64517+ const char __user *, type, unsigned long, flags, void __user *, data)
64518 {
64519 int ret;
64520 char *kernel_type;
64521@@ -2905,6 +2926,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
64522 if (error)
64523 goto out2;
64524
64525+ if (gr_handle_chroot_pivot()) {
64526+ error = -EPERM;
64527+ goto out2;
64528+ }
64529+
64530 get_fs_root(current->fs, &root);
64531 old_mp = lock_mount(&old);
64532 error = PTR_ERR(old_mp);
64533@@ -3176,7 +3202,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
64534 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
64535 return -EPERM;
64536
64537- if (fs->users != 1)
64538+ if (atomic_read(&fs->users) != 1)
64539 return -EINVAL;
64540
64541 get_mnt_ns(mnt_ns);
64542diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
64543index f4ccfe6..a5cf064 100644
64544--- a/fs/nfs/callback_xdr.c
64545+++ b/fs/nfs/callback_xdr.c
64546@@ -51,7 +51,7 @@ struct callback_op {
64547 callback_decode_arg_t decode_args;
64548 callback_encode_res_t encode_res;
64549 long res_maxsize;
64550-};
64551+} __do_const;
64552
64553 static struct callback_op callback_ops[];
64554
64555diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
64556index 00689a8..b162632 100644
64557--- a/fs/nfs/inode.c
64558+++ b/fs/nfs/inode.c
64559@@ -1232,16 +1232,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
64560 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
64561 }
64562
64563-static atomic_long_t nfs_attr_generation_counter;
64564+static atomic_long_unchecked_t nfs_attr_generation_counter;
64565
64566 static unsigned long nfs_read_attr_generation_counter(void)
64567 {
64568- return atomic_long_read(&nfs_attr_generation_counter);
64569+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
64570 }
64571
64572 unsigned long nfs_inc_attr_generation_counter(void)
64573 {
64574- return atomic_long_inc_return(&nfs_attr_generation_counter);
64575+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
64576 }
64577
64578 void nfs_fattr_init(struct nfs_fattr *fattr)
64579diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
64580index 0beb023..3f685ec 100644
64581--- a/fs/nfsd/nfs4proc.c
64582+++ b/fs/nfsd/nfs4proc.c
64583@@ -1198,7 +1198,7 @@ struct nfsd4_operation {
64584 nfsd4op_rsize op_rsize_bop;
64585 stateid_getter op_get_currentstateid;
64586 stateid_setter op_set_currentstateid;
64587-};
64588+} __do_const;
64589
64590 static struct nfsd4_operation nfsd4_ops[];
64591
64592diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
64593index eeea7a9..f3ba422 100644
64594--- a/fs/nfsd/nfs4xdr.c
64595+++ b/fs/nfsd/nfs4xdr.c
64596@@ -1543,7 +1543,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
64597
64598 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
64599
64600-static nfsd4_dec nfsd4_dec_ops[] = {
64601+static const nfsd4_dec nfsd4_dec_ops[] = {
64602 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
64603 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
64604 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
64605diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
64606index 122f691..a00e2e0 100644
64607--- a/fs/nfsd/nfscache.c
64608+++ b/fs/nfsd/nfscache.c
64609@@ -537,7 +537,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
64610 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
64611 u32 hash;
64612 struct nfsd_drc_bucket *b;
64613- int len;
64614+ long len;
64615 size_t bufsize = 0;
64616
64617 if (!rp)
64618@@ -546,11 +546,14 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
64619 hash = nfsd_cache_hash(rp->c_xid);
64620 b = &drc_hashtbl[hash];
64621
64622- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
64623- len >>= 2;
64624+ if (statp) {
64625+ len = (char*)statp - (char*)resv->iov_base;
64626+ len = resv->iov_len - len;
64627+ len >>= 2;
64628+ }
64629
64630 /* Don't cache excessive amounts of data and XDR failures */
64631- if (!statp || len > (256 >> 2)) {
64632+ if (!statp || len > (256 >> 2) || len < 0) {
64633 nfsd_reply_cache_free(b, rp);
64634 return;
64635 }
64636@@ -558,7 +561,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
64637 switch (cachetype) {
64638 case RC_REPLSTAT:
64639 if (len != 1)
64640- printk("nfsd: RC_REPLSTAT/reply len %d!\n",len);
64641+ printk("nfsd: RC_REPLSTAT/reply len %ld!\n",len);
64642 rp->c_replstat = *statp;
64643 break;
64644 case RC_REPLBUFF:
64645diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
64646index 989129e..42e019e 100644
64647--- a/fs/nfsd/vfs.c
64648+++ b/fs/nfsd/vfs.c
64649@@ -872,7 +872,7 @@ __be32 nfsd_readv(struct file *file, loff_t offset, struct kvec *vec, int vlen,
64650
64651 oldfs = get_fs();
64652 set_fs(KERNEL_DS);
64653- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
64654+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
64655 set_fs(oldfs);
64656 return nfsd_finish_read(file, count, host_err);
64657 }
64658@@ -960,7 +960,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
64659
64660 /* Write the data. */
64661 oldfs = get_fs(); set_fs(KERNEL_DS);
64662- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
64663+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
64664 set_fs(oldfs);
64665 if (host_err < 0)
64666 goto out_nfserr;
64667@@ -1502,7 +1502,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
64668 */
64669
64670 oldfs = get_fs(); set_fs(KERNEL_DS);
64671- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
64672+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
64673 set_fs(oldfs);
64674
64675 if (host_err < 0)
64676diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
64677index 52ccd34..7a6b202 100644
64678--- a/fs/nls/nls_base.c
64679+++ b/fs/nls/nls_base.c
64680@@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
64681
64682 int __register_nls(struct nls_table *nls, struct module *owner)
64683 {
64684- struct nls_table ** tmp = &tables;
64685+ struct nls_table *tmp = tables;
64686
64687 if (nls->next)
64688 return -EBUSY;
64689
64690- nls->owner = owner;
64691+ pax_open_kernel();
64692+ *(void **)&nls->owner = owner;
64693+ pax_close_kernel();
64694 spin_lock(&nls_lock);
64695- while (*tmp) {
64696- if (nls == *tmp) {
64697+ while (tmp) {
64698+ if (nls == tmp) {
64699 spin_unlock(&nls_lock);
64700 return -EBUSY;
64701 }
64702- tmp = &(*tmp)->next;
64703+ tmp = tmp->next;
64704 }
64705- nls->next = tables;
64706+ pax_open_kernel();
64707+ *(struct nls_table **)&nls->next = tables;
64708+ pax_close_kernel();
64709 tables = nls;
64710 spin_unlock(&nls_lock);
64711 return 0;
64712@@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
64713
64714 int unregister_nls(struct nls_table * nls)
64715 {
64716- struct nls_table ** tmp = &tables;
64717+ struct nls_table * const * tmp = &tables;
64718
64719 spin_lock(&nls_lock);
64720 while (*tmp) {
64721 if (nls == *tmp) {
64722- *tmp = nls->next;
64723+ pax_open_kernel();
64724+ *(struct nls_table **)tmp = nls->next;
64725+ pax_close_kernel();
64726 spin_unlock(&nls_lock);
64727 return 0;
64728 }
64729@@ -272,7 +278,7 @@ int unregister_nls(struct nls_table * nls)
64730 return -EINVAL;
64731 }
64732
64733-static struct nls_table *find_nls(char *charset)
64734+static struct nls_table *find_nls(const char *charset)
64735 {
64736 struct nls_table *nls;
64737 spin_lock(&nls_lock);
64738@@ -288,7 +294,7 @@ static struct nls_table *find_nls(char *charset)
64739 return nls;
64740 }
64741
64742-struct nls_table *load_nls(char *charset)
64743+struct nls_table *load_nls(const char *charset)
64744 {
64745 return try_then_request_module(find_nls(charset), "nls_%s", charset);
64746 }
64747diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
64748index 162b3f1..6076a7c 100644
64749--- a/fs/nls/nls_euc-jp.c
64750+++ b/fs/nls/nls_euc-jp.c
64751@@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
64752 p_nls = load_nls("cp932");
64753
64754 if (p_nls) {
64755- table.charset2upper = p_nls->charset2upper;
64756- table.charset2lower = p_nls->charset2lower;
64757+ pax_open_kernel();
64758+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
64759+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
64760+ pax_close_kernel();
64761 return register_nls(&table);
64762 }
64763
64764diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
64765index a80a741..7b96e1b 100644
64766--- a/fs/nls/nls_koi8-ru.c
64767+++ b/fs/nls/nls_koi8-ru.c
64768@@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
64769 p_nls = load_nls("koi8-u");
64770
64771 if (p_nls) {
64772- table.charset2upper = p_nls->charset2upper;
64773- table.charset2lower = p_nls->charset2lower;
64774+ pax_open_kernel();
64775+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
64776+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
64777+ pax_close_kernel();
64778 return register_nls(&table);
64779 }
64780
64781diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
64782index c991616..5ae51af 100644
64783--- a/fs/notify/fanotify/fanotify_user.c
64784+++ b/fs/notify/fanotify/fanotify_user.c
64785@@ -216,8 +216,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
64786
64787 fd = fanotify_event_metadata.fd;
64788 ret = -EFAULT;
64789- if (copy_to_user(buf, &fanotify_event_metadata,
64790- fanotify_event_metadata.event_len))
64791+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
64792+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
64793 goto out_close_fd;
64794
64795 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
64796diff --git a/fs/notify/notification.c b/fs/notify/notification.c
64797index a95d8e0..a91a5fd 100644
64798--- a/fs/notify/notification.c
64799+++ b/fs/notify/notification.c
64800@@ -48,7 +48,7 @@
64801 #include <linux/fsnotify_backend.h>
64802 #include "fsnotify.h"
64803
64804-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
64805+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
64806
64807 /**
64808 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
64809@@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
64810 */
64811 u32 fsnotify_get_cookie(void)
64812 {
64813- return atomic_inc_return(&fsnotify_sync_cookie);
64814+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
64815 }
64816 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
64817
64818diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
64819index 9e38daf..5727cae 100644
64820--- a/fs/ntfs/dir.c
64821+++ b/fs/ntfs/dir.c
64822@@ -1310,7 +1310,7 @@ find_next_index_buffer:
64823 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
64824 ~(s64)(ndir->itype.index.block_size - 1)));
64825 /* Bounds checks. */
64826- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
64827+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
64828 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
64829 "inode 0x%lx or driver bug.", vdir->i_ino);
64830 goto err_out;
64831diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
64832index 643faa4..ef9027e 100644
64833--- a/fs/ntfs/file.c
64834+++ b/fs/ntfs/file.c
64835@@ -1280,7 +1280,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
64836 char *addr;
64837 size_t total = 0;
64838 unsigned len;
64839- int left;
64840+ unsigned left;
64841
64842 do {
64843 len = PAGE_CACHE_SIZE - ofs;
64844diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
64845index 9e1e112..241a52a 100644
64846--- a/fs/ntfs/super.c
64847+++ b/fs/ntfs/super.c
64848@@ -688,7 +688,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
64849 if (!silent)
64850 ntfs_error(sb, "Primary boot sector is invalid.");
64851 } else if (!silent)
64852- ntfs_error(sb, read_err_str, "primary");
64853+ ntfs_error(sb, read_err_str, "%s", "primary");
64854 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
64855 if (bh_primary)
64856 brelse(bh_primary);
64857@@ -704,7 +704,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
64858 goto hotfix_primary_boot_sector;
64859 brelse(bh_backup);
64860 } else if (!silent)
64861- ntfs_error(sb, read_err_str, "backup");
64862+ ntfs_error(sb, read_err_str, "%s", "backup");
64863 /* Try to read NT3.51- backup boot sector. */
64864 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
64865 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
64866@@ -715,7 +715,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
64867 "sector.");
64868 brelse(bh_backup);
64869 } else if (!silent)
64870- ntfs_error(sb, read_err_str, "backup");
64871+ ntfs_error(sb, read_err_str, "%s", "backup");
64872 /* We failed. Cleanup and return. */
64873 if (bh_primary)
64874 brelse(bh_primary);
64875diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
64876index 0440134..d52c93a 100644
64877--- a/fs/ocfs2/localalloc.c
64878+++ b/fs/ocfs2/localalloc.c
64879@@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
64880 goto bail;
64881 }
64882
64883- atomic_inc(&osb->alloc_stats.moves);
64884+ atomic_inc_unchecked(&osb->alloc_stats.moves);
64885
64886 bail:
64887 if (handle)
64888diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
64889index bbec539..7b266d5 100644
64890--- a/fs/ocfs2/ocfs2.h
64891+++ b/fs/ocfs2/ocfs2.h
64892@@ -236,11 +236,11 @@ enum ocfs2_vol_state
64893
64894 struct ocfs2_alloc_stats
64895 {
64896- atomic_t moves;
64897- atomic_t local_data;
64898- atomic_t bitmap_data;
64899- atomic_t bg_allocs;
64900- atomic_t bg_extends;
64901+ atomic_unchecked_t moves;
64902+ atomic_unchecked_t local_data;
64903+ atomic_unchecked_t bitmap_data;
64904+ atomic_unchecked_t bg_allocs;
64905+ atomic_unchecked_t bg_extends;
64906 };
64907
64908 enum ocfs2_local_alloc_state
64909diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
64910index 0cb889a..6a26b24 100644
64911--- a/fs/ocfs2/suballoc.c
64912+++ b/fs/ocfs2/suballoc.c
64913@@ -867,7 +867,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
64914 mlog_errno(status);
64915 goto bail;
64916 }
64917- atomic_inc(&osb->alloc_stats.bg_extends);
64918+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
64919
64920 /* You should never ask for this much metadata */
64921 BUG_ON(bits_wanted >
64922@@ -2014,7 +2014,7 @@ int ocfs2_claim_metadata(handle_t *handle,
64923 mlog_errno(status);
64924 goto bail;
64925 }
64926- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
64927+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
64928
64929 *suballoc_loc = res.sr_bg_blkno;
64930 *suballoc_bit_start = res.sr_bit_offset;
64931@@ -2180,7 +2180,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
64932 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
64933 res->sr_bits);
64934
64935- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
64936+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
64937
64938 BUG_ON(res->sr_bits != 1);
64939
64940@@ -2222,7 +2222,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
64941 mlog_errno(status);
64942 goto bail;
64943 }
64944- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
64945+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
64946
64947 BUG_ON(res.sr_bits != 1);
64948
64949@@ -2326,7 +2326,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
64950 cluster_start,
64951 num_clusters);
64952 if (!status)
64953- atomic_inc(&osb->alloc_stats.local_data);
64954+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
64955 } else {
64956 if (min_clusters > (osb->bitmap_cpg - 1)) {
64957 /* The only paths asking for contiguousness
64958@@ -2352,7 +2352,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
64959 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
64960 res.sr_bg_blkno,
64961 res.sr_bit_offset);
64962- atomic_inc(&osb->alloc_stats.bitmap_data);
64963+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
64964 *num_clusters = res.sr_bits;
64965 }
64966 }
64967diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
64968index 93c85bc..02f68a4 100644
64969--- a/fs/ocfs2/super.c
64970+++ b/fs/ocfs2/super.c
64971@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
64972 "%10s => GlobalAllocs: %d LocalAllocs: %d "
64973 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
64974 "Stats",
64975- atomic_read(&osb->alloc_stats.bitmap_data),
64976- atomic_read(&osb->alloc_stats.local_data),
64977- atomic_read(&osb->alloc_stats.bg_allocs),
64978- atomic_read(&osb->alloc_stats.moves),
64979- atomic_read(&osb->alloc_stats.bg_extends));
64980+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
64981+ atomic_read_unchecked(&osb->alloc_stats.local_data),
64982+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
64983+ atomic_read_unchecked(&osb->alloc_stats.moves),
64984+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
64985
64986 out += snprintf(buf + out, len - out,
64987 "%10s => State: %u Descriptor: %llu Size: %u bits "
64988@@ -2104,11 +2104,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
64989
64990 mutex_init(&osb->system_file_mutex);
64991
64992- atomic_set(&osb->alloc_stats.moves, 0);
64993- atomic_set(&osb->alloc_stats.local_data, 0);
64994- atomic_set(&osb->alloc_stats.bitmap_data, 0);
64995- atomic_set(&osb->alloc_stats.bg_allocs, 0);
64996- atomic_set(&osb->alloc_stats.bg_extends, 0);
64997+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
64998+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
64999+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
65000+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
65001+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
65002
65003 /* Copy the blockcheck stats from the superblock probe */
65004 osb->osb_ecc_stats = *stats;
65005diff --git a/fs/open.c b/fs/open.c
65006index de92c13..52d2a6c 100644
65007--- a/fs/open.c
65008+++ b/fs/open.c
65009@@ -32,6 +32,8 @@
65010 #include <linux/dnotify.h>
65011 #include <linux/compat.h>
65012
65013+#define CREATE_TRACE_POINTS
65014+#include <trace/events/fs.h>
65015 #include "internal.h"
65016
65017 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
65018@@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
65019 error = locks_verify_truncate(inode, NULL, length);
65020 if (!error)
65021 error = security_path_truncate(path);
65022+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
65023+ error = -EACCES;
65024 if (!error)
65025 error = do_truncate(path->dentry, length, 0, NULL);
65026
65027@@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
65028 error = locks_verify_truncate(inode, f.file, length);
65029 if (!error)
65030 error = security_path_truncate(&f.file->f_path);
65031+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
65032+ error = -EACCES;
65033 if (!error)
65034 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
65035 sb_end_write(inode->i_sb);
65036@@ -380,6 +386,9 @@ retry:
65037 if (__mnt_is_readonly(path.mnt))
65038 res = -EROFS;
65039
65040+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
65041+ res = -EACCES;
65042+
65043 out_path_release:
65044 path_put(&path);
65045 if (retry_estale(res, lookup_flags)) {
65046@@ -411,6 +420,8 @@ retry:
65047 if (error)
65048 goto dput_and_out;
65049
65050+ gr_log_chdir(path.dentry, path.mnt);
65051+
65052 set_fs_pwd(current->fs, &path);
65053
65054 dput_and_out:
65055@@ -440,6 +451,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
65056 goto out_putf;
65057
65058 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
65059+
65060+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
65061+ error = -EPERM;
65062+
65063+ if (!error)
65064+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
65065+
65066 if (!error)
65067 set_fs_pwd(current->fs, &f.file->f_path);
65068 out_putf:
65069@@ -469,7 +487,13 @@ retry:
65070 if (error)
65071 goto dput_and_out;
65072
65073+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
65074+ goto dput_and_out;
65075+
65076 set_fs_root(current->fs, &path);
65077+
65078+ gr_handle_chroot_chdir(&path);
65079+
65080 error = 0;
65081 dput_and_out:
65082 path_put(&path);
65083@@ -493,6 +517,16 @@ static int chmod_common(struct path *path, umode_t mode)
65084 return error;
65085 retry_deleg:
65086 mutex_lock(&inode->i_mutex);
65087+
65088+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
65089+ error = -EACCES;
65090+ goto out_unlock;
65091+ }
65092+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
65093+ error = -EACCES;
65094+ goto out_unlock;
65095+ }
65096+
65097 error = security_path_chmod(path, mode);
65098 if (error)
65099 goto out_unlock;
65100@@ -558,6 +592,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
65101 uid = make_kuid(current_user_ns(), user);
65102 gid = make_kgid(current_user_ns(), group);
65103
65104+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
65105+ return -EACCES;
65106+
65107 newattrs.ia_valid = ATTR_CTIME;
65108 if (user != (uid_t) -1) {
65109 if (!uid_valid(uid))
65110@@ -1002,6 +1039,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
65111 } else {
65112 fsnotify_open(f);
65113 fd_install(fd, f);
65114+ trace_do_sys_open(tmp->name, flags, mode);
65115 }
65116 }
65117 putname(tmp);
65118diff --git a/fs/pipe.c b/fs/pipe.c
65119index 21981e5..3d5f55c 100644
65120--- a/fs/pipe.c
65121+++ b/fs/pipe.c
65122@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
65123
65124 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
65125 {
65126- if (pipe->files)
65127+ if (atomic_read(&pipe->files))
65128 mutex_lock_nested(&pipe->mutex, subclass);
65129 }
65130
65131@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
65132
65133 void pipe_unlock(struct pipe_inode_info *pipe)
65134 {
65135- if (pipe->files)
65136+ if (atomic_read(&pipe->files))
65137 mutex_unlock(&pipe->mutex);
65138 }
65139 EXPORT_SYMBOL(pipe_unlock);
65140@@ -292,9 +292,9 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
65141 }
65142 if (bufs) /* More to do? */
65143 continue;
65144- if (!pipe->writers)
65145+ if (!atomic_read(&pipe->writers))
65146 break;
65147- if (!pipe->waiting_writers) {
65148+ if (!atomic_read(&pipe->waiting_writers)) {
65149 /* syscall merging: Usually we must not sleep
65150 * if O_NONBLOCK is set, or if we got some data.
65151 * But if a writer sleeps in kernel space, then
65152@@ -351,7 +351,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65153
65154 __pipe_lock(pipe);
65155
65156- if (!pipe->readers) {
65157+ if (!atomic_read(&pipe->readers)) {
65158 send_sig(SIGPIPE, current, 0);
65159 ret = -EPIPE;
65160 goto out;
65161@@ -387,7 +387,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65162 for (;;) {
65163 int bufs;
65164
65165- if (!pipe->readers) {
65166+ if (!atomic_read(&pipe->readers)) {
65167 send_sig(SIGPIPE, current, 0);
65168 if (!ret)
65169 ret = -EPIPE;
65170@@ -455,9 +455,9 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65171 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
65172 do_wakeup = 0;
65173 }
65174- pipe->waiting_writers++;
65175+ atomic_inc(&pipe->waiting_writers);
65176 pipe_wait(pipe);
65177- pipe->waiting_writers--;
65178+ atomic_dec(&pipe->waiting_writers);
65179 }
65180 out:
65181 __pipe_unlock(pipe);
65182@@ -512,7 +512,7 @@ pipe_poll(struct file *filp, poll_table *wait)
65183 mask = 0;
65184 if (filp->f_mode & FMODE_READ) {
65185 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
65186- if (!pipe->writers && filp->f_version != pipe->w_counter)
65187+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
65188 mask |= POLLHUP;
65189 }
65190
65191@@ -522,7 +522,7 @@ pipe_poll(struct file *filp, poll_table *wait)
65192 * Most Unices do not set POLLERR for FIFOs but on Linux they
65193 * behave exactly like pipes for poll().
65194 */
65195- if (!pipe->readers)
65196+ if (!atomic_read(&pipe->readers))
65197 mask |= POLLERR;
65198 }
65199
65200@@ -534,7 +534,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
65201 int kill = 0;
65202
65203 spin_lock(&inode->i_lock);
65204- if (!--pipe->files) {
65205+ if (atomic_dec_and_test(&pipe->files)) {
65206 inode->i_pipe = NULL;
65207 kill = 1;
65208 }
65209@@ -551,11 +551,11 @@ pipe_release(struct inode *inode, struct file *file)
65210
65211 __pipe_lock(pipe);
65212 if (file->f_mode & FMODE_READ)
65213- pipe->readers--;
65214+ atomic_dec(&pipe->readers);
65215 if (file->f_mode & FMODE_WRITE)
65216- pipe->writers--;
65217+ atomic_dec(&pipe->writers);
65218
65219- if (pipe->readers || pipe->writers) {
65220+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
65221 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
65222 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
65223 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
65224@@ -620,7 +620,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
65225 kfree(pipe);
65226 }
65227
65228-static struct vfsmount *pipe_mnt __read_mostly;
65229+struct vfsmount *pipe_mnt __read_mostly;
65230
65231 /*
65232 * pipefs_dname() is called from d_path().
65233@@ -650,8 +650,9 @@ static struct inode * get_pipe_inode(void)
65234 goto fail_iput;
65235
65236 inode->i_pipe = pipe;
65237- pipe->files = 2;
65238- pipe->readers = pipe->writers = 1;
65239+ atomic_set(&pipe->files, 2);
65240+ atomic_set(&pipe->readers, 1);
65241+ atomic_set(&pipe->writers, 1);
65242 inode->i_fop = &pipefifo_fops;
65243
65244 /*
65245@@ -830,17 +831,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
65246 spin_lock(&inode->i_lock);
65247 if (inode->i_pipe) {
65248 pipe = inode->i_pipe;
65249- pipe->files++;
65250+ atomic_inc(&pipe->files);
65251 spin_unlock(&inode->i_lock);
65252 } else {
65253 spin_unlock(&inode->i_lock);
65254 pipe = alloc_pipe_info();
65255 if (!pipe)
65256 return -ENOMEM;
65257- pipe->files = 1;
65258+ atomic_set(&pipe->files, 1);
65259 spin_lock(&inode->i_lock);
65260 if (unlikely(inode->i_pipe)) {
65261- inode->i_pipe->files++;
65262+ atomic_inc(&inode->i_pipe->files);
65263 spin_unlock(&inode->i_lock);
65264 free_pipe_info(pipe);
65265 pipe = inode->i_pipe;
65266@@ -865,10 +866,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
65267 * opened, even when there is no process writing the FIFO.
65268 */
65269 pipe->r_counter++;
65270- if (pipe->readers++ == 0)
65271+ if (atomic_inc_return(&pipe->readers) == 1)
65272 wake_up_partner(pipe);
65273
65274- if (!is_pipe && !pipe->writers) {
65275+ if (!is_pipe && !atomic_read(&pipe->writers)) {
65276 if ((filp->f_flags & O_NONBLOCK)) {
65277 /* suppress POLLHUP until we have
65278 * seen a writer */
65279@@ -887,14 +888,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
65280 * errno=ENXIO when there is no process reading the FIFO.
65281 */
65282 ret = -ENXIO;
65283- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
65284+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
65285 goto err;
65286
65287 pipe->w_counter++;
65288- if (!pipe->writers++)
65289+ if (atomic_inc_return(&pipe->writers) == 1)
65290 wake_up_partner(pipe);
65291
65292- if (!is_pipe && !pipe->readers) {
65293+ if (!is_pipe && !atomic_read(&pipe->readers)) {
65294 if (wait_for_partner(pipe, &pipe->r_counter))
65295 goto err_wr;
65296 }
65297@@ -908,11 +909,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
65298 * the process can at least talk to itself.
65299 */
65300
65301- pipe->readers++;
65302- pipe->writers++;
65303+ atomic_inc(&pipe->readers);
65304+ atomic_inc(&pipe->writers);
65305 pipe->r_counter++;
65306 pipe->w_counter++;
65307- if (pipe->readers == 1 || pipe->writers == 1)
65308+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
65309 wake_up_partner(pipe);
65310 break;
65311
65312@@ -926,13 +927,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
65313 return 0;
65314
65315 err_rd:
65316- if (!--pipe->readers)
65317+ if (atomic_dec_and_test(&pipe->readers))
65318 wake_up_interruptible(&pipe->wait);
65319 ret = -ERESTARTSYS;
65320 goto err;
65321
65322 err_wr:
65323- if (!--pipe->writers)
65324+ if (atomic_dec_and_test(&pipe->writers))
65325 wake_up_interruptible(&pipe->wait);
65326 ret = -ERESTARTSYS;
65327 goto err;
65328diff --git a/fs/posix_acl.c b/fs/posix_acl.c
65329index 0855f77..6787d50 100644
65330--- a/fs/posix_acl.c
65331+++ b/fs/posix_acl.c
65332@@ -20,6 +20,7 @@
65333 #include <linux/xattr.h>
65334 #include <linux/export.h>
65335 #include <linux/user_namespace.h>
65336+#include <linux/grsecurity.h>
65337
65338 struct posix_acl **acl_by_type(struct inode *inode, int type)
65339 {
65340@@ -277,7 +278,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
65341 }
65342 }
65343 if (mode_p)
65344- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
65345+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
65346 return not_equiv;
65347 }
65348 EXPORT_SYMBOL(posix_acl_equiv_mode);
65349@@ -427,7 +428,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
65350 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
65351 }
65352
65353- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
65354+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
65355 return not_equiv;
65356 }
65357
65358@@ -485,6 +486,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
65359 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
65360 int err = -ENOMEM;
65361 if (clone) {
65362+ *mode_p &= ~gr_acl_umask();
65363+
65364 err = posix_acl_create_masq(clone, mode_p);
65365 if (err < 0) {
65366 posix_acl_release(clone);
65367@@ -659,11 +662,12 @@ struct posix_acl *
65368 posix_acl_from_xattr(struct user_namespace *user_ns,
65369 const void *value, size_t size)
65370 {
65371- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
65372- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
65373+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
65374+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
65375 int count;
65376 struct posix_acl *acl;
65377 struct posix_acl_entry *acl_e;
65378+ umode_t umask = gr_acl_umask();
65379
65380 if (!value)
65381 return NULL;
65382@@ -689,12 +693,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65383
65384 switch(acl_e->e_tag) {
65385 case ACL_USER_OBJ:
65386+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65387+ break;
65388 case ACL_GROUP_OBJ:
65389 case ACL_MASK:
65390+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65391+ break;
65392 case ACL_OTHER:
65393+ acl_e->e_perm &= ~(umask & S_IRWXO);
65394 break;
65395
65396 case ACL_USER:
65397+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65398 acl_e->e_uid =
65399 make_kuid(user_ns,
65400 le32_to_cpu(entry->e_id));
65401@@ -702,6 +712,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65402 goto fail;
65403 break;
65404 case ACL_GROUP:
65405+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65406 acl_e->e_gid =
65407 make_kgid(user_ns,
65408 le32_to_cpu(entry->e_id));
65409diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
65410index 2183fcf..3c32a98 100644
65411--- a/fs/proc/Kconfig
65412+++ b/fs/proc/Kconfig
65413@@ -30,7 +30,7 @@ config PROC_FS
65414
65415 config PROC_KCORE
65416 bool "/proc/kcore support" if !ARM
65417- depends on PROC_FS && MMU
65418+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
65419 help
65420 Provides a virtual ELF core file of the live kernel. This can
65421 be read with gdb and other ELF tools. No modifications can be
65422@@ -38,8 +38,8 @@ config PROC_KCORE
65423
65424 config PROC_VMCORE
65425 bool "/proc/vmcore support"
65426- depends on PROC_FS && CRASH_DUMP
65427- default y
65428+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
65429+ default n
65430 help
65431 Exports the dump image of crashed kernel in ELF format.
65432
65433@@ -63,8 +63,8 @@ config PROC_SYSCTL
65434 limited in memory.
65435
65436 config PROC_PAGE_MONITOR
65437- default y
65438- depends on PROC_FS && MMU
65439+ default n
65440+ depends on PROC_FS && MMU && !GRKERNSEC
65441 bool "Enable /proc page monitoring" if EXPERT
65442 help
65443 Various /proc files exist to monitor process memory utilization:
65444diff --git a/fs/proc/array.c b/fs/proc/array.c
65445index cd3653e..9b9b79a 100644
65446--- a/fs/proc/array.c
65447+++ b/fs/proc/array.c
65448@@ -60,6 +60,7 @@
65449 #include <linux/tty.h>
65450 #include <linux/string.h>
65451 #include <linux/mman.h>
65452+#include <linux/grsecurity.h>
65453 #include <linux/proc_fs.h>
65454 #include <linux/ioport.h>
65455 #include <linux/uaccess.h>
65456@@ -347,6 +348,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
65457 seq_putc(m, '\n');
65458 }
65459
65460+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65461+static inline void task_pax(struct seq_file *m, struct task_struct *p)
65462+{
65463+ if (p->mm)
65464+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
65465+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
65466+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
65467+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
65468+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
65469+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
65470+ else
65471+ seq_printf(m, "PaX:\t-----\n");
65472+}
65473+#endif
65474+
65475 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
65476 struct pid *pid, struct task_struct *task)
65477 {
65478@@ -365,9 +381,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
65479 task_cpus_allowed(m, task);
65480 cpuset_task_status_allowed(m, task);
65481 task_context_switch_counts(m, task);
65482+
65483+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65484+ task_pax(m, task);
65485+#endif
65486+
65487+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
65488+ task_grsec_rbac(m, task);
65489+#endif
65490+
65491 return 0;
65492 }
65493
65494+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65495+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
65496+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
65497+ _mm->pax_flags & MF_PAX_SEGMEXEC))
65498+#endif
65499+
65500 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65501 struct pid *pid, struct task_struct *task, int whole)
65502 {
65503@@ -389,6 +420,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65504 char tcomm[sizeof(task->comm)];
65505 unsigned long flags;
65506
65507+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65508+ if (current->exec_id != m->exec_id) {
65509+ gr_log_badprocpid("stat");
65510+ return 0;
65511+ }
65512+#endif
65513+
65514 state = *get_task_state(task);
65515 vsize = eip = esp = 0;
65516 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
65517@@ -459,6 +497,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65518 gtime = task_gtime(task);
65519 }
65520
65521+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65522+ if (PAX_RAND_FLAGS(mm)) {
65523+ eip = 0;
65524+ esp = 0;
65525+ wchan = 0;
65526+ }
65527+#endif
65528+#ifdef CONFIG_GRKERNSEC_HIDESYM
65529+ wchan = 0;
65530+ eip =0;
65531+ esp =0;
65532+#endif
65533+
65534 /* scale priority and nice values from timeslices to -20..20 */
65535 /* to make it look like a "normal" Unix priority/nice value */
65536 priority = task_prio(task);
65537@@ -490,9 +541,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65538 seq_put_decimal_ull(m, ' ', vsize);
65539 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
65540 seq_put_decimal_ull(m, ' ', rsslim);
65541+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65542+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
65543+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
65544+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
65545+#else
65546 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
65547 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
65548 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
65549+#endif
65550 seq_put_decimal_ull(m, ' ', esp);
65551 seq_put_decimal_ull(m, ' ', eip);
65552 /* The signal information here is obsolete.
65553@@ -514,7 +571,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65554 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
65555 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
65556
65557- if (mm && permitted) {
65558+ if (mm && permitted
65559+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65560+ && !PAX_RAND_FLAGS(mm)
65561+#endif
65562+ ) {
65563 seq_put_decimal_ull(m, ' ', mm->start_data);
65564 seq_put_decimal_ull(m, ' ', mm->end_data);
65565 seq_put_decimal_ull(m, ' ', mm->start_brk);
65566@@ -552,8 +613,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
65567 struct pid *pid, struct task_struct *task)
65568 {
65569 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
65570- struct mm_struct *mm = get_task_mm(task);
65571+ struct mm_struct *mm;
65572
65573+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65574+ if (current->exec_id != m->exec_id) {
65575+ gr_log_badprocpid("statm");
65576+ return 0;
65577+ }
65578+#endif
65579+ mm = get_task_mm(task);
65580 if (mm) {
65581 size = task_statm(mm, &shared, &text, &data, &resident);
65582 mmput(mm);
65583@@ -576,6 +644,20 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
65584 return 0;
65585 }
65586
65587+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
65588+int proc_pid_ipaddr(struct seq_file *m, struct pid_namespace *ns, struct pid *pid, struct task_struct *task)
65589+{
65590+ unsigned long flags;
65591+ u32 curr_ip = 0;
65592+
65593+ if (lock_task_sighand(task, &flags)) {
65594+ curr_ip = task->signal->curr_ip;
65595+ unlock_task_sighand(task, &flags);
65596+ }
65597+ return seq_printf(m, "%pI4\n", &curr_ip);
65598+}
65599+#endif
65600+
65601 #ifdef CONFIG_CHECKPOINT_RESTORE
65602 static struct pid *
65603 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
65604diff --git a/fs/proc/base.c b/fs/proc/base.c
65605index 772efa4..e7f1a5c 100644
65606--- a/fs/proc/base.c
65607+++ b/fs/proc/base.c
65608@@ -113,6 +113,14 @@ struct pid_entry {
65609 union proc_op op;
65610 };
65611
65612+struct getdents_callback {
65613+ struct linux_dirent __user * current_dir;
65614+ struct linux_dirent __user * previous;
65615+ struct file * file;
65616+ int count;
65617+ int error;
65618+};
65619+
65620 #define NOD(NAME, MODE, IOP, FOP, OP) { \
65621 .name = (NAME), \
65622 .len = sizeof(NAME) - 1, \
65623@@ -208,12 +216,28 @@ static int proc_pid_cmdline(struct seq_file *m, struct pid_namespace *ns,
65624 return 0;
65625 }
65626
65627+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65628+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
65629+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
65630+ _mm->pax_flags & MF_PAX_SEGMEXEC))
65631+#endif
65632+
65633 static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns,
65634 struct pid *pid, struct task_struct *task)
65635 {
65636 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
65637 if (mm && !IS_ERR(mm)) {
65638 unsigned int nwords = 0;
65639+
65640+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65641+ /* allow if we're currently ptracing this task */
65642+ if (PAX_RAND_FLAGS(mm) &&
65643+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
65644+ mmput(mm);
65645+ return 0;
65646+ }
65647+#endif
65648+
65649 do {
65650 nwords += 2;
65651 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
65652@@ -225,7 +249,7 @@ static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns,
65653 }
65654
65655
65656-#ifdef CONFIG_KALLSYMS
65657+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65658 /*
65659 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
65660 * Returns the resolved symbol. If that fails, simply return the address.
65661@@ -265,7 +289,7 @@ static void unlock_trace(struct task_struct *task)
65662 mutex_unlock(&task->signal->cred_guard_mutex);
65663 }
65664
65665-#ifdef CONFIG_STACKTRACE
65666+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65667
65668 #define MAX_STACK_TRACE_DEPTH 64
65669
65670@@ -456,7 +480,7 @@ static int proc_pid_limits(struct seq_file *m, struct pid_namespace *ns,
65671 return 0;
65672 }
65673
65674-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
65675+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
65676 static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
65677 struct pid *pid, struct task_struct *task)
65678 {
65679@@ -486,7 +510,7 @@ static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
65680 /************************************************************************/
65681
65682 /* permission checks */
65683-static int proc_fd_access_allowed(struct inode *inode)
65684+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
65685 {
65686 struct task_struct *task;
65687 int allowed = 0;
65688@@ -496,7 +520,10 @@ static int proc_fd_access_allowed(struct inode *inode)
65689 */
65690 task = get_proc_task(inode);
65691 if (task) {
65692- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
65693+ if (log)
65694+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
65695+ else
65696+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
65697 put_task_struct(task);
65698 }
65699 return allowed;
65700@@ -527,10 +554,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
65701 struct task_struct *task,
65702 int hide_pid_min)
65703 {
65704+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
65705+ return false;
65706+
65707+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65708+ rcu_read_lock();
65709+ {
65710+ const struct cred *tmpcred = current_cred();
65711+ const struct cred *cred = __task_cred(task);
65712+
65713+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
65714+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
65715+ || in_group_p(grsec_proc_gid)
65716+#endif
65717+ ) {
65718+ rcu_read_unlock();
65719+ return true;
65720+ }
65721+ }
65722+ rcu_read_unlock();
65723+
65724+ if (!pid->hide_pid)
65725+ return false;
65726+#endif
65727+
65728 if (pid->hide_pid < hide_pid_min)
65729 return true;
65730 if (in_group_p(pid->pid_gid))
65731 return true;
65732+
65733 return ptrace_may_access(task, PTRACE_MODE_READ);
65734 }
65735
65736@@ -548,7 +600,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
65737 put_task_struct(task);
65738
65739 if (!has_perms) {
65740+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65741+ {
65742+#else
65743 if (pid->hide_pid == 2) {
65744+#endif
65745 /*
65746 * Let's make getdents(), stat(), and open()
65747 * consistent with each other. If a process
65748@@ -609,6 +665,8 @@ struct mm_struct *proc_mem_open(struct inode *inode, unsigned int mode)
65749
65750 if (task) {
65751 mm = mm_access(task, mode);
65752+ if (gr_acl_handle_procpidmem(task))
65753+ mm = ERR_PTR(-EPERM);
65754 put_task_struct(task);
65755
65756 if (!IS_ERR_OR_NULL(mm)) {
65757@@ -630,6 +688,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
65758 return PTR_ERR(mm);
65759
65760 file->private_data = mm;
65761+
65762+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65763+ file->f_version = current->exec_id;
65764+#endif
65765+
65766 return 0;
65767 }
65768
65769@@ -651,6 +714,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
65770 ssize_t copied;
65771 char *page;
65772
65773+#ifdef CONFIG_GRKERNSEC
65774+ if (write)
65775+ return -EPERM;
65776+#endif
65777+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65778+ if (file->f_version != current->exec_id) {
65779+ gr_log_badprocpid("mem");
65780+ return 0;
65781+ }
65782+#endif
65783+
65784 if (!mm)
65785 return 0;
65786
65787@@ -663,7 +737,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
65788 goto free;
65789
65790 while (count > 0) {
65791- int this_len = min_t(int, count, PAGE_SIZE);
65792+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
65793
65794 if (write && copy_from_user(page, buf, this_len)) {
65795 copied = -EFAULT;
65796@@ -755,6 +829,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
65797 if (!mm)
65798 return 0;
65799
65800+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65801+ if (file->f_version != current->exec_id) {
65802+ gr_log_badprocpid("environ");
65803+ return 0;
65804+ }
65805+#endif
65806+
65807 page = (char *)__get_free_page(GFP_TEMPORARY);
65808 if (!page)
65809 return -ENOMEM;
65810@@ -764,7 +845,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
65811 goto free;
65812 while (count > 0) {
65813 size_t this_len, max_len;
65814- int retval;
65815+ ssize_t retval;
65816
65817 if (src >= (mm->env_end - mm->env_start))
65818 break;
65819@@ -1378,7 +1459,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
65820 int error = -EACCES;
65821
65822 /* Are we allowed to snoop on the tasks file descriptors? */
65823- if (!proc_fd_access_allowed(inode))
65824+ if (!proc_fd_access_allowed(inode, 0))
65825 goto out;
65826
65827 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
65828@@ -1422,8 +1503,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
65829 struct path path;
65830
65831 /* Are we allowed to snoop on the tasks file descriptors? */
65832- if (!proc_fd_access_allowed(inode))
65833- goto out;
65834+ /* logging this is needed for learning on chromium to work properly,
65835+ but we don't want to flood the logs from 'ps' which does a readlink
65836+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
65837+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
65838+ */
65839+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
65840+ if (!proc_fd_access_allowed(inode,0))
65841+ goto out;
65842+ } else {
65843+ if (!proc_fd_access_allowed(inode,1))
65844+ goto out;
65845+ }
65846
65847 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
65848 if (error)
65849@@ -1473,7 +1564,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
65850 rcu_read_lock();
65851 cred = __task_cred(task);
65852 inode->i_uid = cred->euid;
65853+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
65854+ inode->i_gid = grsec_proc_gid;
65855+#else
65856 inode->i_gid = cred->egid;
65857+#endif
65858 rcu_read_unlock();
65859 }
65860 security_task_to_inode(task, inode);
65861@@ -1509,10 +1604,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
65862 return -ENOENT;
65863 }
65864 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
65865+#ifdef CONFIG_GRKERNSEC_PROC_USER
65866+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
65867+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65868+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
65869+#endif
65870 task_dumpable(task)) {
65871 cred = __task_cred(task);
65872 stat->uid = cred->euid;
65873+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
65874+ stat->gid = grsec_proc_gid;
65875+#else
65876 stat->gid = cred->egid;
65877+#endif
65878 }
65879 }
65880 rcu_read_unlock();
65881@@ -1550,11 +1654,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
65882
65883 if (task) {
65884 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
65885+#ifdef CONFIG_GRKERNSEC_PROC_USER
65886+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
65887+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65888+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
65889+#endif
65890 task_dumpable(task)) {
65891 rcu_read_lock();
65892 cred = __task_cred(task);
65893 inode->i_uid = cred->euid;
65894+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
65895+ inode->i_gid = grsec_proc_gid;
65896+#else
65897 inode->i_gid = cred->egid;
65898+#endif
65899 rcu_read_unlock();
65900 } else {
65901 inode->i_uid = GLOBAL_ROOT_UID;
65902@@ -2085,6 +2198,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
65903 if (!task)
65904 goto out_no_task;
65905
65906+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
65907+ goto out;
65908+
65909 /*
65910 * Yes, it does not scale. And it should not. Don't add
65911 * new entries into /proc/<tgid>/ without very good reasons.
65912@@ -2115,6 +2231,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
65913 if (!task)
65914 return -ENOENT;
65915
65916+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
65917+ goto out;
65918+
65919 if (!dir_emit_dots(file, ctx))
65920 goto out;
65921
65922@@ -2506,7 +2625,7 @@ static const struct pid_entry tgid_base_stuff[] = {
65923 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
65924 #endif
65925 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
65926-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
65927+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
65928 ONE("syscall", S_IRUSR, proc_pid_syscall),
65929 #endif
65930 ONE("cmdline", S_IRUGO, proc_pid_cmdline),
65931@@ -2531,10 +2650,10 @@ static const struct pid_entry tgid_base_stuff[] = {
65932 #ifdef CONFIG_SECURITY
65933 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
65934 #endif
65935-#ifdef CONFIG_KALLSYMS
65936+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65937 ONE("wchan", S_IRUGO, proc_pid_wchan),
65938 #endif
65939-#ifdef CONFIG_STACKTRACE
65940+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65941 ONE("stack", S_IRUSR, proc_pid_stack),
65942 #endif
65943 #ifdef CONFIG_SCHEDSTATS
65944@@ -2568,6 +2687,9 @@ static const struct pid_entry tgid_base_stuff[] = {
65945 #ifdef CONFIG_HARDWALL
65946 ONE("hardwall", S_IRUGO, proc_pid_hardwall),
65947 #endif
65948+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
65949+ ONE("ipaddr", S_IRUSR, proc_pid_ipaddr),
65950+#endif
65951 #ifdef CONFIG_USER_NS
65952 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
65953 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
65954@@ -2696,7 +2818,14 @@ static int proc_pid_instantiate(struct inode *dir,
65955 if (!inode)
65956 goto out;
65957
65958+#ifdef CONFIG_GRKERNSEC_PROC_USER
65959+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
65960+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65961+ inode->i_gid = grsec_proc_gid;
65962+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
65963+#else
65964 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
65965+#endif
65966 inode->i_op = &proc_tgid_base_inode_operations;
65967 inode->i_fop = &proc_tgid_base_operations;
65968 inode->i_flags|=S_IMMUTABLE;
65969@@ -2734,7 +2863,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
65970 if (!task)
65971 goto out;
65972
65973+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
65974+ goto out_put_task;
65975+
65976 result = proc_pid_instantiate(dir, dentry, task, NULL);
65977+out_put_task:
65978 put_task_struct(task);
65979 out:
65980 return ERR_PTR(result);
65981@@ -2848,7 +2981,7 @@ static const struct pid_entry tid_base_stuff[] = {
65982 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
65983 #endif
65984 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
65985-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
65986+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
65987 ONE("syscall", S_IRUSR, proc_pid_syscall),
65988 #endif
65989 ONE("cmdline", S_IRUGO, proc_pid_cmdline),
65990@@ -2875,10 +3008,10 @@ static const struct pid_entry tid_base_stuff[] = {
65991 #ifdef CONFIG_SECURITY
65992 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
65993 #endif
65994-#ifdef CONFIG_KALLSYMS
65995+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65996 ONE("wchan", S_IRUGO, proc_pid_wchan),
65997 #endif
65998-#ifdef CONFIG_STACKTRACE
65999+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66000 ONE("stack", S_IRUSR, proc_pid_stack),
66001 #endif
66002 #ifdef CONFIG_SCHEDSTATS
66003diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
66004index cbd82df..c0407d2 100644
66005--- a/fs/proc/cmdline.c
66006+++ b/fs/proc/cmdline.c
66007@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
66008
66009 static int __init proc_cmdline_init(void)
66010 {
66011+#ifdef CONFIG_GRKERNSEC_PROC_ADD
66012+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
66013+#else
66014 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
66015+#endif
66016 return 0;
66017 }
66018 fs_initcall(proc_cmdline_init);
66019diff --git a/fs/proc/devices.c b/fs/proc/devices.c
66020index 50493ed..248166b 100644
66021--- a/fs/proc/devices.c
66022+++ b/fs/proc/devices.c
66023@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
66024
66025 static int __init proc_devices_init(void)
66026 {
66027+#ifdef CONFIG_GRKERNSEC_PROC_ADD
66028+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
66029+#else
66030 proc_create("devices", 0, NULL, &proc_devinfo_operations);
66031+#endif
66032 return 0;
66033 }
66034 fs_initcall(proc_devices_init);
66035diff --git a/fs/proc/fd.c b/fs/proc/fd.c
66036index e11d7c5..9128ce06 100644
66037--- a/fs/proc/fd.c
66038+++ b/fs/proc/fd.c
66039@@ -26,7 +26,8 @@ static int seq_show(struct seq_file *m, void *v)
66040 if (!task)
66041 return -ENOENT;
66042
66043- files = get_files_struct(task);
66044+ if (!gr_acl_handle_procpidmem(task))
66045+ files = get_files_struct(task);
66046 put_task_struct(task);
66047
66048 if (files) {
66049@@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
66050 */
66051 int proc_fd_permission(struct inode *inode, int mask)
66052 {
66053+ struct task_struct *task;
66054 int rv = generic_permission(inode, mask);
66055- if (rv == 0)
66056- return 0;
66057+
66058 if (task_tgid(current) == proc_pid(inode))
66059 rv = 0;
66060+
66061+ task = get_proc_task(inode);
66062+ if (task == NULL)
66063+ return rv;
66064+
66065+ if (gr_acl_handle_procpidmem(task))
66066+ rv = -EACCES;
66067+
66068+ put_task_struct(task);
66069+
66070 return rv;
66071 }
66072
66073diff --git a/fs/proc/generic.c b/fs/proc/generic.c
66074index 317b726..e329aed 100644
66075--- a/fs/proc/generic.c
66076+++ b/fs/proc/generic.c
66077@@ -23,6 +23,7 @@
66078 #include <linux/bitops.h>
66079 #include <linux/spinlock.h>
66080 #include <linux/completion.h>
66081+#include <linux/grsecurity.h>
66082 #include <asm/uaccess.h>
66083
66084 #include "internal.h"
66085@@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
66086 return proc_lookup_de(PDE(dir), dir, dentry);
66087 }
66088
66089+struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
66090+ unsigned int flags)
66091+{
66092+ if (gr_proc_is_restricted())
66093+ return ERR_PTR(-EACCES);
66094+
66095+ return proc_lookup_de(PDE(dir), dir, dentry);
66096+}
66097+
66098 /*
66099 * This returns non-zero if at EOF, so that the /proc
66100 * root directory can use this and check if it should
66101@@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
66102 return proc_readdir_de(PDE(inode), file, ctx);
66103 }
66104
66105+int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
66106+{
66107+ struct inode *inode = file_inode(file);
66108+
66109+ if (gr_proc_is_restricted())
66110+ return -EACCES;
66111+
66112+ return proc_readdir_de(PDE(inode), file, ctx);
66113+}
66114+
66115 /*
66116 * These are the generic /proc directory operations. They
66117 * use the in-memory "struct proc_dir_entry" tree to parse
66118@@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
66119 .iterate = proc_readdir,
66120 };
66121
66122+static const struct file_operations proc_dir_restricted_operations = {
66123+ .llseek = generic_file_llseek,
66124+ .read = generic_read_dir,
66125+ .iterate = proc_readdir_restrict,
66126+};
66127+
66128 /*
66129 * proc directories can do almost nothing..
66130 */
66131@@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
66132 .setattr = proc_notify_change,
66133 };
66134
66135+static const struct inode_operations proc_dir_restricted_inode_operations = {
66136+ .lookup = proc_lookup_restrict,
66137+ .getattr = proc_getattr,
66138+ .setattr = proc_notify_change,
66139+};
66140+
66141 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
66142 {
66143 struct proc_dir_entry *tmp;
66144@@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
66145 return ret;
66146
66147 if (S_ISDIR(dp->mode)) {
66148- dp->proc_fops = &proc_dir_operations;
66149- dp->proc_iops = &proc_dir_inode_operations;
66150+ if (dp->restricted) {
66151+ dp->proc_fops = &proc_dir_restricted_operations;
66152+ dp->proc_iops = &proc_dir_restricted_inode_operations;
66153+ } else {
66154+ dp->proc_fops = &proc_dir_operations;
66155+ dp->proc_iops = &proc_dir_inode_operations;
66156+ }
66157 dir->nlink++;
66158 } else if (S_ISLNK(dp->mode)) {
66159 dp->proc_iops = &proc_link_inode_operations;
66160@@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
66161 }
66162 EXPORT_SYMBOL_GPL(proc_mkdir_data);
66163
66164+struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
66165+ struct proc_dir_entry *parent, void *data)
66166+{
66167+ struct proc_dir_entry *ent;
66168+
66169+ if (mode == 0)
66170+ mode = S_IRUGO | S_IXUGO;
66171+
66172+ ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
66173+ if (ent) {
66174+ ent->data = data;
66175+ ent->restricted = 1;
66176+ if (proc_register(parent, ent) < 0) {
66177+ kfree(ent);
66178+ ent = NULL;
66179+ }
66180+ }
66181+ return ent;
66182+}
66183+EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
66184+
66185 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
66186 struct proc_dir_entry *parent)
66187 {
66188@@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
66189 }
66190 EXPORT_SYMBOL(proc_mkdir);
66191
66192+struct proc_dir_entry *proc_mkdir_restrict(const char *name,
66193+ struct proc_dir_entry *parent)
66194+{
66195+ return proc_mkdir_data_restrict(name, 0, parent, NULL);
66196+}
66197+EXPORT_SYMBOL(proc_mkdir_restrict);
66198+
66199 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
66200 struct proc_dir_entry *parent,
66201 const struct file_operations *proc_fops,
66202diff --git a/fs/proc/inode.c b/fs/proc/inode.c
66203index 333080d..0a35ec4 100644
66204--- a/fs/proc/inode.c
66205+++ b/fs/proc/inode.c
66206@@ -23,11 +23,17 @@
66207 #include <linux/slab.h>
66208 #include <linux/mount.h>
66209 #include <linux/magic.h>
66210+#include <linux/grsecurity.h>
66211
66212 #include <asm/uaccess.h>
66213
66214 #include "internal.h"
66215
66216+#ifdef CONFIG_PROC_SYSCTL
66217+extern const struct inode_operations proc_sys_inode_operations;
66218+extern const struct inode_operations proc_sys_dir_operations;
66219+#endif
66220+
66221 static void proc_evict_inode(struct inode *inode)
66222 {
66223 struct proc_dir_entry *de;
66224@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
66225 ns = PROC_I(inode)->ns.ns;
66226 if (ns_ops && ns)
66227 ns_ops->put(ns);
66228+
66229+#ifdef CONFIG_PROC_SYSCTL
66230+ if (inode->i_op == &proc_sys_inode_operations ||
66231+ inode->i_op == &proc_sys_dir_operations)
66232+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
66233+#endif
66234+
66235 }
66236
66237 static struct kmem_cache * proc_inode_cachep;
66238@@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
66239 if (de->mode) {
66240 inode->i_mode = de->mode;
66241 inode->i_uid = de->uid;
66242+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66243+ inode->i_gid = grsec_proc_gid;
66244+#else
66245 inode->i_gid = de->gid;
66246+#endif
66247 }
66248 if (de->size)
66249 inode->i_size = de->size;
66250diff --git a/fs/proc/internal.h b/fs/proc/internal.h
66251index aa7a0ee..f2318df 100644
66252--- a/fs/proc/internal.h
66253+++ b/fs/proc/internal.h
66254@@ -46,9 +46,10 @@ struct proc_dir_entry {
66255 struct completion *pde_unload_completion;
66256 struct list_head pde_openers; /* who did ->open, but not ->release */
66257 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
66258+ u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
66259 u8 namelen;
66260 char name[];
66261-};
66262+} __randomize_layout;
66263
66264 union proc_op {
66265 int (*proc_get_link)(struct dentry *, struct path *);
66266@@ -66,7 +67,7 @@ struct proc_inode {
66267 struct ctl_table *sysctl_entry;
66268 struct proc_ns ns;
66269 struct inode vfs_inode;
66270-};
66271+} __randomize_layout;
66272
66273 /*
66274 * General functions
66275@@ -154,6 +155,10 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
66276 struct pid *, struct task_struct *);
66277 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
66278 struct pid *, struct task_struct *);
66279+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66280+extern int proc_pid_ipaddr(struct seq_file *, struct pid_namespace *,
66281+ struct pid *, struct task_struct *);
66282+#endif
66283
66284 /*
66285 * base.c
66286@@ -178,9 +183,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
66287 * generic.c
66288 */
66289 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
66290+extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
66291 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
66292 struct dentry *);
66293 extern int proc_readdir(struct file *, struct dir_context *);
66294+extern int proc_readdir_restrict(struct file *, struct dir_context *);
66295 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
66296
66297 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
66298diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
66299index a352d57..cb94a5c 100644
66300--- a/fs/proc/interrupts.c
66301+++ b/fs/proc/interrupts.c
66302@@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
66303
66304 static int __init proc_interrupts_init(void)
66305 {
66306+#ifdef CONFIG_GRKERNSEC_PROC_ADD
66307+ proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
66308+#else
66309 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
66310+#endif
66311 return 0;
66312 }
66313 fs_initcall(proc_interrupts_init);
66314diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
66315index 91a4e64..cb007c0 100644
66316--- a/fs/proc/kcore.c
66317+++ b/fs/proc/kcore.c
66318@@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66319 * the addresses in the elf_phdr on our list.
66320 */
66321 start = kc_offset_to_vaddr(*fpos - elf_buflen);
66322- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
66323+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
66324+ if (tsz > buflen)
66325 tsz = buflen;
66326-
66327+
66328 while (buflen) {
66329 struct kcore_list *m;
66330
66331@@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66332 kfree(elf_buf);
66333 } else {
66334 if (kern_addr_valid(start)) {
66335- unsigned long n;
66336+ char *elf_buf;
66337+ mm_segment_t oldfs;
66338
66339- n = copy_to_user(buffer, (char *)start, tsz);
66340- /*
66341- * We cannot distinguish between fault on source
66342- * and fault on destination. When this happens
66343- * we clear too and hope it will trigger the
66344- * EFAULT again.
66345- */
66346- if (n) {
66347- if (clear_user(buffer + tsz - n,
66348- n))
66349+ elf_buf = kmalloc(tsz, GFP_KERNEL);
66350+ if (!elf_buf)
66351+ return -ENOMEM;
66352+ oldfs = get_fs();
66353+ set_fs(KERNEL_DS);
66354+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
66355+ set_fs(oldfs);
66356+ if (copy_to_user(buffer, elf_buf, tsz)) {
66357+ kfree(elf_buf);
66358 return -EFAULT;
66359+ }
66360 }
66361+ set_fs(oldfs);
66362+ kfree(elf_buf);
66363 } else {
66364 if (clear_user(buffer, tsz))
66365 return -EFAULT;
66366@@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66367
66368 static int open_kcore(struct inode *inode, struct file *filp)
66369 {
66370+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66371+ return -EPERM;
66372+#endif
66373 if (!capable(CAP_SYS_RAWIO))
66374 return -EPERM;
66375 if (kcore_need_update)
66376diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
66377index aa1eee0..03dda72 100644
66378--- a/fs/proc/meminfo.c
66379+++ b/fs/proc/meminfo.c
66380@@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
66381 vmi.used >> 10,
66382 vmi.largest_chunk >> 10
66383 #ifdef CONFIG_MEMORY_FAILURE
66384- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
66385+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
66386 #endif
66387 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
66388 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
66389diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
66390index d4a3574..b421ce9 100644
66391--- a/fs/proc/nommu.c
66392+++ b/fs/proc/nommu.c
66393@@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
66394
66395 if (file) {
66396 seq_pad(m, ' ');
66397- seq_path(m, &file->f_path, "");
66398+ seq_path(m, &file->f_path, "\n\\");
66399 }
66400
66401 seq_putc(m, '\n');
66402diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
66403index a63af3e..b4f262a 100644
66404--- a/fs/proc/proc_net.c
66405+++ b/fs/proc/proc_net.c
66406@@ -23,9 +23,27 @@
66407 #include <linux/nsproxy.h>
66408 #include <net/net_namespace.h>
66409 #include <linux/seq_file.h>
66410+#include <linux/grsecurity.h>
66411
66412 #include "internal.h"
66413
66414+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
66415+static struct seq_operations *ipv6_seq_ops_addr;
66416+
66417+void register_ipv6_seq_ops_addr(struct seq_operations *addr)
66418+{
66419+ ipv6_seq_ops_addr = addr;
66420+}
66421+
66422+void unregister_ipv6_seq_ops_addr(void)
66423+{
66424+ ipv6_seq_ops_addr = NULL;
66425+}
66426+
66427+EXPORT_SYMBOL_GPL(register_ipv6_seq_ops_addr);
66428+EXPORT_SYMBOL_GPL(unregister_ipv6_seq_ops_addr);
66429+#endif
66430+
66431 static inline struct net *PDE_NET(struct proc_dir_entry *pde)
66432 {
66433 return pde->parent->data;
66434@@ -36,6 +54,8 @@ static struct net *get_proc_net(const struct inode *inode)
66435 return maybe_get_net(PDE_NET(PDE(inode)));
66436 }
66437
66438+extern const struct seq_operations dev_seq_ops;
66439+
66440 int seq_open_net(struct inode *ino, struct file *f,
66441 const struct seq_operations *ops, int size)
66442 {
66443@@ -44,6 +64,14 @@ int seq_open_net(struct inode *ino, struct file *f,
66444
66445 BUG_ON(size < sizeof(*p));
66446
66447+ /* only permit access to /proc/net/dev */
66448+ if (
66449+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
66450+ ops != ipv6_seq_ops_addr &&
66451+#endif
66452+ ops != &dev_seq_ops && gr_proc_is_restricted())
66453+ return -EACCES;
66454+
66455 net = get_proc_net(ino);
66456 if (net == NULL)
66457 return -ENXIO;
66458@@ -66,6 +94,9 @@ int single_open_net(struct inode *inode, struct file *file,
66459 int err;
66460 struct net *net;
66461
66462+ if (gr_proc_is_restricted())
66463+ return -EACCES;
66464+
66465 err = -ENXIO;
66466 net = get_proc_net(inode);
66467 if (net == NULL)
66468diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
66469index f92d5dd..26398ac 100644
66470--- a/fs/proc/proc_sysctl.c
66471+++ b/fs/proc/proc_sysctl.c
66472@@ -11,13 +11,21 @@
66473 #include <linux/namei.h>
66474 #include <linux/mm.h>
66475 #include <linux/module.h>
66476+#include <linux/nsproxy.h>
66477+#ifdef CONFIG_GRKERNSEC
66478+#include <net/net_namespace.h>
66479+#endif
66480 #include "internal.h"
66481
66482+extern int gr_handle_chroot_sysctl(const int op);
66483+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
66484+ const int op);
66485+
66486 static const struct dentry_operations proc_sys_dentry_operations;
66487 static const struct file_operations proc_sys_file_operations;
66488-static const struct inode_operations proc_sys_inode_operations;
66489+const struct inode_operations proc_sys_inode_operations;
66490 static const struct file_operations proc_sys_dir_file_operations;
66491-static const struct inode_operations proc_sys_dir_operations;
66492+const struct inode_operations proc_sys_dir_operations;
66493
66494 void proc_sys_poll_notify(struct ctl_table_poll *poll)
66495 {
66496@@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
66497
66498 err = NULL;
66499 d_set_d_op(dentry, &proc_sys_dentry_operations);
66500+
66501+ gr_handle_proc_create(dentry, inode);
66502+
66503 d_add(dentry, inode);
66504
66505 out:
66506@@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66507 struct inode *inode = file_inode(filp);
66508 struct ctl_table_header *head = grab_header(inode);
66509 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
66510+ int op = write ? MAY_WRITE : MAY_READ;
66511 ssize_t error;
66512 size_t res;
66513
66514@@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66515 * and won't be until we finish.
66516 */
66517 error = -EPERM;
66518- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
66519+ if (sysctl_perm(head, table, op))
66520 goto out;
66521
66522 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
66523@@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66524 if (!table->proc_handler)
66525 goto out;
66526
66527+#ifdef CONFIG_GRKERNSEC
66528+ error = -EPERM;
66529+ if (gr_handle_chroot_sysctl(op))
66530+ goto out;
66531+ dget(filp->f_path.dentry);
66532+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
66533+ dput(filp->f_path.dentry);
66534+ goto out;
66535+ }
66536+ dput(filp->f_path.dentry);
66537+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
66538+ goto out;
66539+ if (write) {
66540+ if (current->nsproxy->net_ns != table->extra2) {
66541+ if (!capable(CAP_SYS_ADMIN))
66542+ goto out;
66543+ } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
66544+ goto out;
66545+ }
66546+#endif
66547+
66548 /* careful: calling conventions are nasty here */
66549 res = count;
66550 error = table->proc_handler(table, write, buf, &res, ppos);
66551@@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
66552 return false;
66553 } else {
66554 d_set_d_op(child, &proc_sys_dentry_operations);
66555+
66556+ gr_handle_proc_create(child, inode);
66557+
66558 d_add(child, inode);
66559 }
66560 } else {
66561@@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, struct ctl_table *table,
66562 if ((*pos)++ < ctx->pos)
66563 return true;
66564
66565+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
66566+ return 0;
66567+
66568 if (unlikely(S_ISLNK(table->mode)))
66569 res = proc_sys_link_fill_cache(file, ctx, head, table);
66570 else
66571@@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
66572 if (IS_ERR(head))
66573 return PTR_ERR(head);
66574
66575+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
66576+ return -ENOENT;
66577+
66578 generic_fillattr(inode, stat);
66579 if (table)
66580 stat->mode = (stat->mode & S_IFMT) | table->mode;
66581@@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
66582 .llseek = generic_file_llseek,
66583 };
66584
66585-static const struct inode_operations proc_sys_inode_operations = {
66586+const struct inode_operations proc_sys_inode_operations = {
66587 .permission = proc_sys_permission,
66588 .setattr = proc_sys_setattr,
66589 .getattr = proc_sys_getattr,
66590 };
66591
66592-static const struct inode_operations proc_sys_dir_operations = {
66593+const struct inode_operations proc_sys_dir_operations = {
66594 .lookup = proc_sys_lookup,
66595 .permission = proc_sys_permission,
66596 .setattr = proc_sys_setattr,
66597@@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
66598 static struct ctl_dir *new_dir(struct ctl_table_set *set,
66599 const char *name, int namelen)
66600 {
66601- struct ctl_table *table;
66602+ ctl_table_no_const *table;
66603 struct ctl_dir *new;
66604 struct ctl_node *node;
66605 char *new_name;
66606@@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
66607 return NULL;
66608
66609 node = (struct ctl_node *)(new + 1);
66610- table = (struct ctl_table *)(node + 1);
66611+ table = (ctl_table_no_const *)(node + 1);
66612 new_name = (char *)(table + 2);
66613 memcpy(new_name, name, namelen);
66614 new_name[namelen] = '\0';
66615@@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
66616 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
66617 struct ctl_table_root *link_root)
66618 {
66619- struct ctl_table *link_table, *entry, *link;
66620+ ctl_table_no_const *link_table, *link;
66621+ struct ctl_table *entry;
66622 struct ctl_table_header *links;
66623 struct ctl_node *node;
66624 char *link_name;
66625@@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
66626 return NULL;
66627
66628 node = (struct ctl_node *)(links + 1);
66629- link_table = (struct ctl_table *)(node + nr_entries);
66630+ link_table = (ctl_table_no_const *)(node + nr_entries);
66631 link_name = (char *)&link_table[nr_entries + 1];
66632
66633 for (link = link_table, entry = table; entry->procname; link++, entry++) {
66634@@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
66635 struct ctl_table_header ***subheader, struct ctl_table_set *set,
66636 struct ctl_table *table)
66637 {
66638- struct ctl_table *ctl_table_arg = NULL;
66639- struct ctl_table *entry, *files;
66640+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
66641+ struct ctl_table *entry;
66642 int nr_files = 0;
66643 int nr_dirs = 0;
66644 int err = -ENOMEM;
66645@@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
66646 nr_files++;
66647 }
66648
66649- files = table;
66650 /* If there are mixed files and directories we need a new table */
66651 if (nr_dirs && nr_files) {
66652- struct ctl_table *new;
66653+ ctl_table_no_const *new;
66654 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
66655 GFP_KERNEL);
66656 if (!files)
66657@@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
66658 /* Register everything except a directory full of subdirectories */
66659 if (nr_files || !nr_dirs) {
66660 struct ctl_table_header *header;
66661- header = __register_sysctl_table(set, path, files);
66662+ header = __register_sysctl_table(set, path, files ? files : table);
66663 if (!header) {
66664 kfree(ctl_table_arg);
66665 goto out;
66666diff --git a/fs/proc/root.c b/fs/proc/root.c
66667index 094e44d..085a877 100644
66668--- a/fs/proc/root.c
66669+++ b/fs/proc/root.c
66670@@ -188,7 +188,15 @@ void __init proc_root_init(void)
66671 proc_mkdir("openprom", NULL);
66672 #endif
66673 proc_tty_init();
66674+#ifdef CONFIG_GRKERNSEC_PROC_ADD
66675+#ifdef CONFIG_GRKERNSEC_PROC_USER
66676+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
66677+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66678+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
66679+#endif
66680+#else
66681 proc_mkdir("bus", NULL);
66682+#endif
66683 proc_sys_init();
66684 }
66685
66686diff --git a/fs/proc/stat.c b/fs/proc/stat.c
66687index bf2d03f..f058f9c 100644
66688--- a/fs/proc/stat.c
66689+++ b/fs/proc/stat.c
66690@@ -11,6 +11,7 @@
66691 #include <linux/irqnr.h>
66692 #include <linux/cputime.h>
66693 #include <linux/tick.h>
66694+#include <linux/grsecurity.h>
66695
66696 #ifndef arch_irq_stat_cpu
66697 #define arch_irq_stat_cpu(cpu) 0
66698@@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
66699 u64 sum_softirq = 0;
66700 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
66701 struct timespec boottime;
66702+ int unrestricted = 1;
66703+
66704+#ifdef CONFIG_GRKERNSEC_PROC_ADD
66705+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66706+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
66707+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66708+ && !in_group_p(grsec_proc_gid)
66709+#endif
66710+ )
66711+ unrestricted = 0;
66712+#endif
66713+#endif
66714
66715 user = nice = system = idle = iowait =
66716 irq = softirq = steal = 0;
66717@@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
66718 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
66719 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
66720 idle += get_idle_time(i);
66721- iowait += get_iowait_time(i);
66722- irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
66723- softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
66724- steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
66725- guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
66726- guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
66727- sum += kstat_cpu_irqs_sum(i);
66728- sum += arch_irq_stat_cpu(i);
66729+ if (unrestricted) {
66730+ iowait += get_iowait_time(i);
66731+ irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
66732+ softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
66733+ steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
66734+ guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
66735+ guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
66736+ sum += kstat_cpu_irqs_sum(i);
66737+ sum += arch_irq_stat_cpu(i);
66738+ for (j = 0; j < NR_SOFTIRQS; j++) {
66739+ unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
66740
66741- for (j = 0; j < NR_SOFTIRQS; j++) {
66742- unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
66743-
66744- per_softirq_sums[j] += softirq_stat;
66745- sum_softirq += softirq_stat;
66746+ per_softirq_sums[j] += softirq_stat;
66747+ sum_softirq += softirq_stat;
66748+ }
66749 }
66750 }
66751- sum += arch_irq_stat();
66752+ if (unrestricted)
66753+ sum += arch_irq_stat();
66754
66755 seq_puts(p, "cpu ");
66756 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
66757@@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
66758 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
66759 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
66760 idle = get_idle_time(i);
66761- iowait = get_iowait_time(i);
66762- irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
66763- softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
66764- steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
66765- guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
66766- guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
66767+ if (unrestricted) {
66768+ iowait = get_iowait_time(i);
66769+ irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
66770+ softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
66771+ steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
66772+ guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
66773+ guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
66774+ }
66775 seq_printf(p, "cpu%d", i);
66776 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
66777 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
66778@@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
66779
66780 /* sum again ? it could be updated? */
66781 for_each_irq_nr(j)
66782- seq_put_decimal_ull(p, ' ', kstat_irqs(j));
66783+ seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
66784
66785 seq_printf(p,
66786 "\nctxt %llu\n"
66787@@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
66788 "processes %lu\n"
66789 "procs_running %lu\n"
66790 "procs_blocked %lu\n",
66791- nr_context_switches(),
66792+ unrestricted ? nr_context_switches() : 0ULL,
66793 (unsigned long)jif,
66794- total_forks,
66795- nr_running(),
66796- nr_iowait());
66797+ unrestricted ? total_forks : 0UL,
66798+ unrestricted ? nr_running() : 0UL,
66799+ unrestricted ? nr_iowait() : 0UL);
66800
66801 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
66802
66803diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
66804index 4e0388c..fc6a0e1 100644
66805--- a/fs/proc/task_mmu.c
66806+++ b/fs/proc/task_mmu.c
66807@@ -13,12 +13,19 @@
66808 #include <linux/swap.h>
66809 #include <linux/swapops.h>
66810 #include <linux/mmu_notifier.h>
66811+#include <linux/grsecurity.h>
66812
66813 #include <asm/elf.h>
66814 #include <asm/uaccess.h>
66815 #include <asm/tlbflush.h>
66816 #include "internal.h"
66817
66818+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66819+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
66820+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
66821+ _mm->pax_flags & MF_PAX_SEGMEXEC))
66822+#endif
66823+
66824 void task_mem(struct seq_file *m, struct mm_struct *mm)
66825 {
66826 unsigned long data, text, lib, swap;
66827@@ -54,8 +61,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
66828 "VmExe:\t%8lu kB\n"
66829 "VmLib:\t%8lu kB\n"
66830 "VmPTE:\t%8lu kB\n"
66831- "VmSwap:\t%8lu kB\n",
66832- hiwater_vm << (PAGE_SHIFT-10),
66833+ "VmSwap:\t%8lu kB\n"
66834+
66835+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
66836+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
66837+#endif
66838+
66839+ ,hiwater_vm << (PAGE_SHIFT-10),
66840 total_vm << (PAGE_SHIFT-10),
66841 mm->locked_vm << (PAGE_SHIFT-10),
66842 mm->pinned_vm << (PAGE_SHIFT-10),
66843@@ -65,7 +77,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
66844 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
66845 (PTRS_PER_PTE * sizeof(pte_t) *
66846 atomic_long_read(&mm->nr_ptes)) >> 10,
66847- swap << (PAGE_SHIFT-10));
66848+ swap << (PAGE_SHIFT-10)
66849+
66850+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
66851+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66852+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
66853+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
66854+#else
66855+ , mm->context.user_cs_base
66856+ , mm->context.user_cs_limit
66857+#endif
66858+#endif
66859+
66860+ );
66861 }
66862
66863 unsigned long task_vsize(struct mm_struct *mm)
66864@@ -282,13 +306,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
66865 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
66866 }
66867
66868- /* We don't show the stack guard page in /proc/maps */
66869+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66870+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
66871+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
66872+#else
66873 start = vma->vm_start;
66874- if (stack_guard_page_start(vma, start))
66875- start += PAGE_SIZE;
66876 end = vma->vm_end;
66877- if (stack_guard_page_end(vma, end))
66878- end -= PAGE_SIZE;
66879+#endif
66880
66881 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
66882 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
66883@@ -298,7 +322,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
66884 flags & VM_WRITE ? 'w' : '-',
66885 flags & VM_EXEC ? 'x' : '-',
66886 flags & VM_MAYSHARE ? 's' : 'p',
66887+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66888+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
66889+#else
66890 pgoff,
66891+#endif
66892 MAJOR(dev), MINOR(dev), ino);
66893
66894 /*
66895@@ -307,7 +335,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
66896 */
66897 if (file) {
66898 seq_pad(m, ' ');
66899- seq_path(m, &file->f_path, "\n");
66900+ seq_path(m, &file->f_path, "\n\\");
66901 goto done;
66902 }
66903
66904@@ -338,8 +366,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
66905 * Thread stack in /proc/PID/task/TID/maps or
66906 * the main process stack.
66907 */
66908- if (!is_pid || (vma->vm_start <= mm->start_stack &&
66909- vma->vm_end >= mm->start_stack)) {
66910+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
66911+ (vma->vm_start <= mm->start_stack &&
66912+ vma->vm_end >= mm->start_stack)) {
66913 name = "[stack]";
66914 } else {
66915 /* Thread stack in /proc/PID/maps */
66916@@ -359,6 +388,12 @@ done:
66917
66918 static int show_map(struct seq_file *m, void *v, int is_pid)
66919 {
66920+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66921+ if (current->exec_id != m->exec_id) {
66922+ gr_log_badprocpid("maps");
66923+ return 0;
66924+ }
66925+#endif
66926 show_map_vma(m, v, is_pid);
66927 m_cache_vma(m, v);
66928 return 0;
66929@@ -594,12 +629,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
66930 .private = &mss,
66931 };
66932
66933+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66934+ if (current->exec_id != m->exec_id) {
66935+ gr_log_badprocpid("smaps");
66936+ return 0;
66937+ }
66938+#endif
66939 memset(&mss, 0, sizeof mss);
66940- mss.vma = vma;
66941- /* mmap_sem is held in m_start */
66942- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
66943- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
66944-
66945+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66946+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
66947+#endif
66948+ mss.vma = vma;
66949+ /* mmap_sem is held in m_start */
66950+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
66951+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
66952+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66953+ }
66954+#endif
66955 show_map_vma(m, vma, is_pid);
66956
66957 seq_printf(m,
66958@@ -617,7 +663,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
66959 "KernelPageSize: %8lu kB\n"
66960 "MMUPageSize: %8lu kB\n"
66961 "Locked: %8lu kB\n",
66962+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66963+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
66964+#else
66965 (vma->vm_end - vma->vm_start) >> 10,
66966+#endif
66967 mss.resident >> 10,
66968 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
66969 mss.shared_clean >> 10,
66970@@ -1447,6 +1497,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
66971 char buffer[64];
66972 int nid;
66973
66974+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66975+ if (current->exec_id != m->exec_id) {
66976+ gr_log_badprocpid("numa_maps");
66977+ return 0;
66978+ }
66979+#endif
66980+
66981 if (!mm)
66982 return 0;
66983
66984@@ -1468,11 +1525,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
66985 mpol_to_str(buffer, sizeof(buffer), proc_priv->task_mempolicy);
66986 }
66987
66988+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66989+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
66990+#else
66991 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
66992+#endif
66993
66994 if (file) {
66995 seq_puts(m, " file=");
66996- seq_path(m, &file->f_path, "\n\t= ");
66997+ seq_path(m, &file->f_path, "\n\t\\= ");
66998 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
66999 seq_puts(m, " heap");
67000 } else {
67001diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
67002index 599ec2e..f1413ae 100644
67003--- a/fs/proc/task_nommu.c
67004+++ b/fs/proc/task_nommu.c
67005@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67006 else
67007 bytes += kobjsize(mm);
67008
67009- if (current->fs && current->fs->users > 1)
67010+ if (current->fs && atomic_read(&current->fs->users) > 1)
67011 sbytes += kobjsize(current->fs);
67012 else
67013 bytes += kobjsize(current->fs);
67014@@ -180,7 +180,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
67015
67016 if (file) {
67017 seq_pad(m, ' ');
67018- seq_path(m, &file->f_path, "");
67019+ seq_path(m, &file->f_path, "\n\\");
67020 } else if (mm) {
67021 pid_t tid = pid_of_stack(priv, vma, is_pid);
67022
67023diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
67024index a90d6d35..d08047c 100644
67025--- a/fs/proc/vmcore.c
67026+++ b/fs/proc/vmcore.c
67027@@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
67028 nr_bytes = count;
67029
67030 /* If pfn is not ram, return zeros for sparse dump files */
67031- if (pfn_is_ram(pfn) == 0)
67032- memset(buf, 0, nr_bytes);
67033- else {
67034+ if (pfn_is_ram(pfn) == 0) {
67035+ if (userbuf) {
67036+ if (clear_user((char __force_user *)buf, nr_bytes))
67037+ return -EFAULT;
67038+ } else
67039+ memset(buf, 0, nr_bytes);
67040+ } else {
67041 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
67042 offset, userbuf);
67043 if (tmp < 0)
67044@@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
67045 static int copy_to(void *target, void *src, size_t size, int userbuf)
67046 {
67047 if (userbuf) {
67048- if (copy_to_user((char __user *) target, src, size))
67049+ if (copy_to_user((char __force_user *) target, src, size))
67050 return -EFAULT;
67051 } else {
67052 memcpy(target, src, size);
67053@@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
67054 if (*fpos < m->offset + m->size) {
67055 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
67056 start = m->paddr + *fpos - m->offset;
67057- tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
67058+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
67059 if (tmp < 0)
67060 return tmp;
67061 buflen -= tsz;
67062@@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
67063 static ssize_t read_vmcore(struct file *file, char __user *buffer,
67064 size_t buflen, loff_t *fpos)
67065 {
67066- return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
67067+ return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
67068 }
67069
67070 /*
67071diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
67072index d3fb2b6..43a8140 100644
67073--- a/fs/qnx6/qnx6.h
67074+++ b/fs/qnx6/qnx6.h
67075@@ -74,7 +74,7 @@ enum {
67076 BYTESEX_BE,
67077 };
67078
67079-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
67080+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
67081 {
67082 if (sbi->s_bytesex == BYTESEX_LE)
67083 return le64_to_cpu((__force __le64)n);
67084@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
67085 return (__force __fs64)cpu_to_be64(n);
67086 }
67087
67088-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
67089+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
67090 {
67091 if (sbi->s_bytesex == BYTESEX_LE)
67092 return le32_to_cpu((__force __le32)n);
67093diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
67094index bb2869f..d34ada8 100644
67095--- a/fs/quota/netlink.c
67096+++ b/fs/quota/netlink.c
67097@@ -44,7 +44,7 @@ static struct genl_family quota_genl_family = {
67098 void quota_send_warning(struct kqid qid, dev_t dev,
67099 const char warntype)
67100 {
67101- static atomic_t seq;
67102+ static atomic_unchecked_t seq;
67103 struct sk_buff *skb;
67104 void *msg_head;
67105 int ret;
67106@@ -60,7 +60,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
67107 "VFS: Not enough memory to send quota warning.\n");
67108 return;
67109 }
67110- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
67111+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
67112 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
67113 if (!msg_head) {
67114 printk(KERN_ERR
67115diff --git a/fs/read_write.c b/fs/read_write.c
67116index 7d9318c..51b336f 100644
67117--- a/fs/read_write.c
67118+++ b/fs/read_write.c
67119@@ -495,7 +495,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
67120
67121 old_fs = get_fs();
67122 set_fs(get_ds());
67123- p = (__force const char __user *)buf;
67124+ p = (const char __force_user *)buf;
67125 if (count > MAX_RW_COUNT)
67126 count = MAX_RW_COUNT;
67127 if (file->f_op->write)
67128diff --git a/fs/readdir.c b/fs/readdir.c
67129index 33fd922..e0d6094 100644
67130--- a/fs/readdir.c
67131+++ b/fs/readdir.c
67132@@ -18,6 +18,7 @@
67133 #include <linux/security.h>
67134 #include <linux/syscalls.h>
67135 #include <linux/unistd.h>
67136+#include <linux/namei.h>
67137
67138 #include <asm/uaccess.h>
67139
67140@@ -71,6 +72,7 @@ struct old_linux_dirent {
67141 struct readdir_callback {
67142 struct dir_context ctx;
67143 struct old_linux_dirent __user * dirent;
67144+ struct file * file;
67145 int result;
67146 };
67147
67148@@ -88,6 +90,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
67149 buf->result = -EOVERFLOW;
67150 return -EOVERFLOW;
67151 }
67152+
67153+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67154+ return 0;
67155+
67156 buf->result++;
67157 dirent = buf->dirent;
67158 if (!access_ok(VERIFY_WRITE, dirent,
67159@@ -119,6 +125,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
67160 if (!f.file)
67161 return -EBADF;
67162
67163+ buf.file = f.file;
67164 error = iterate_dir(f.file, &buf.ctx);
67165 if (buf.result)
67166 error = buf.result;
67167@@ -144,6 +151,7 @@ struct getdents_callback {
67168 struct dir_context ctx;
67169 struct linux_dirent __user * current_dir;
67170 struct linux_dirent __user * previous;
67171+ struct file * file;
67172 int count;
67173 int error;
67174 };
67175@@ -165,6 +173,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
67176 buf->error = -EOVERFLOW;
67177 return -EOVERFLOW;
67178 }
67179+
67180+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67181+ return 0;
67182+
67183 dirent = buf->previous;
67184 if (dirent) {
67185 if (__put_user(offset, &dirent->d_off))
67186@@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
67187 if (!f.file)
67188 return -EBADF;
67189
67190+ buf.file = f.file;
67191 error = iterate_dir(f.file, &buf.ctx);
67192 if (error >= 0)
67193 error = buf.error;
67194@@ -228,6 +241,7 @@ struct getdents_callback64 {
67195 struct dir_context ctx;
67196 struct linux_dirent64 __user * current_dir;
67197 struct linux_dirent64 __user * previous;
67198+ struct file *file;
67199 int count;
67200 int error;
67201 };
67202@@ -243,6 +257,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
67203 buf->error = -EINVAL; /* only used if we fail.. */
67204 if (reclen > buf->count)
67205 return -EINVAL;
67206+
67207+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67208+ return 0;
67209+
67210 dirent = buf->previous;
67211 if (dirent) {
67212 if (__put_user(offset, &dirent->d_off))
67213@@ -290,6 +308,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
67214 if (!f.file)
67215 return -EBADF;
67216
67217+ buf.file = f.file;
67218 error = iterate_dir(f.file, &buf.ctx);
67219 if (error >= 0)
67220 error = buf.error;
67221diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
67222index 9c02d96..6562c10 100644
67223--- a/fs/reiserfs/do_balan.c
67224+++ b/fs/reiserfs/do_balan.c
67225@@ -1887,7 +1887,7 @@ void do_balance(struct tree_balance *tb, struct item_head *ih,
67226 return;
67227 }
67228
67229- atomic_inc(&fs_generation(tb->tb_sb));
67230+ atomic_inc_unchecked(&fs_generation(tb->tb_sb));
67231 do_balance_starts(tb);
67232
67233 /*
67234diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
67235index aca73dd..e3c558d 100644
67236--- a/fs/reiserfs/item_ops.c
67237+++ b/fs/reiserfs/item_ops.c
67238@@ -724,18 +724,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
67239 }
67240
67241 static struct item_operations errcatch_ops = {
67242- errcatch_bytes_number,
67243- errcatch_decrement_key,
67244- errcatch_is_left_mergeable,
67245- errcatch_print_item,
67246- errcatch_check_item,
67247+ .bytes_number = errcatch_bytes_number,
67248+ .decrement_key = errcatch_decrement_key,
67249+ .is_left_mergeable = errcatch_is_left_mergeable,
67250+ .print_item = errcatch_print_item,
67251+ .check_item = errcatch_check_item,
67252
67253- errcatch_create_vi,
67254- errcatch_check_left,
67255- errcatch_check_right,
67256- errcatch_part_size,
67257- errcatch_unit_num,
67258- errcatch_print_vi
67259+ .create_vi = errcatch_create_vi,
67260+ .check_left = errcatch_check_left,
67261+ .check_right = errcatch_check_right,
67262+ .part_size = errcatch_part_size,
67263+ .unit_num = errcatch_unit_num,
67264+ .print_vi = errcatch_print_vi
67265 };
67266
67267 #if ! (TYPE_STAT_DATA == 0 && TYPE_INDIRECT == 1 && TYPE_DIRECT == 2 && TYPE_DIRENTRY == 3)
67268diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
67269index 621b9f3..af527fd 100644
67270--- a/fs/reiserfs/procfs.c
67271+++ b/fs/reiserfs/procfs.c
67272@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
67273 "SMALL_TAILS " : "NO_TAILS ",
67274 replay_only(sb) ? "REPLAY_ONLY " : "",
67275 convert_reiserfs(sb) ? "CONV " : "",
67276- atomic_read(&r->s_generation_counter),
67277+ atomic_read_unchecked(&r->s_generation_counter),
67278 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
67279 SF(s_do_balance), SF(s_unneeded_left_neighbor),
67280 SF(s_good_search_by_key_reada), SF(s_bmaps),
67281diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
67282index 1894d96..1dfd1c2 100644
67283--- a/fs/reiserfs/reiserfs.h
67284+++ b/fs/reiserfs/reiserfs.h
67285@@ -576,7 +576,7 @@ struct reiserfs_sb_info {
67286 /* Comment? -Hans */
67287 wait_queue_head_t s_wait;
67288 /* increased by one every time the tree gets re-balanced */
67289- atomic_t s_generation_counter;
67290+ atomic_unchecked_t s_generation_counter;
67291
67292 /* File system properties. Currently holds on-disk FS format */
67293 unsigned long s_properties;
67294@@ -2297,7 +2297,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
67295 #define REISERFS_USER_MEM 1 /* user memory mode */
67296
67297 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
67298-#define get_generation(s) atomic_read (&fs_generation(s))
67299+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
67300 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
67301 #define __fs_changed(gen,s) (gen != get_generation (s))
67302 #define fs_changed(gen,s) \
67303diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
67304index f1376c9..f9378e9 100644
67305--- a/fs/reiserfs/super.c
67306+++ b/fs/reiserfs/super.c
67307@@ -1857,6 +1857,10 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
67308 sbi->s_mount_opt |= (1 << REISERFS_SMALLTAIL);
67309 sbi->s_mount_opt |= (1 << REISERFS_ERROR_RO);
67310 sbi->s_mount_opt |= (1 << REISERFS_BARRIER_FLUSH);
67311+#ifdef CONFIG_REISERFS_FS_XATTR
67312+ /* turn on user xattrs by default */
67313+ sbi->s_mount_opt |= (1 << REISERFS_XATTRS_USER);
67314+#endif
67315 /* no preallocation minimum, be smart in reiserfs_file_write instead */
67316 sbi->s_alloc_options.preallocmin = 0;
67317 /* Preallocate by 16 blocks (17-1) at once */
67318diff --git a/fs/select.c b/fs/select.c
67319index 467bb1c..cf9d65a 100644
67320--- a/fs/select.c
67321+++ b/fs/select.c
67322@@ -20,6 +20,7 @@
67323 #include <linux/export.h>
67324 #include <linux/slab.h>
67325 #include <linux/poll.h>
67326+#include <linux/security.h>
67327 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
67328 #include <linux/file.h>
67329 #include <linux/fdtable.h>
67330@@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
67331 struct poll_list *walk = head;
67332 unsigned long todo = nfds;
67333
67334+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
67335 if (nfds > rlimit(RLIMIT_NOFILE))
67336 return -EINVAL;
67337
67338diff --git a/fs/seq_file.c b/fs/seq_file.c
67339index 3857b72..0b7281e 100644
67340--- a/fs/seq_file.c
67341+++ b/fs/seq_file.c
67342@@ -12,6 +12,8 @@
67343 #include <linux/slab.h>
67344 #include <linux/cred.h>
67345 #include <linux/mm.h>
67346+#include <linux/sched.h>
67347+#include <linux/grsecurity.h>
67348
67349 #include <asm/uaccess.h>
67350 #include <asm/page.h>
67351@@ -34,12 +36,7 @@ static void seq_set_overflow(struct seq_file *m)
67352
67353 static void *seq_buf_alloc(unsigned long size)
67354 {
67355- void *buf;
67356-
67357- buf = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
67358- if (!buf && size > PAGE_SIZE)
67359- buf = vmalloc(size);
67360- return buf;
67361+ return kmalloc(size, GFP_KERNEL | GFP_USERCOPY);
67362 }
67363
67364 /**
67365@@ -72,6 +69,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
67366 #ifdef CONFIG_USER_NS
67367 p->user_ns = file->f_cred->user_ns;
67368 #endif
67369+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67370+ p->exec_id = current->exec_id;
67371+#endif
67372
67373 /*
67374 * Wrappers around seq_open(e.g. swaps_open) need to be
67375@@ -94,6 +94,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
67376 }
67377 EXPORT_SYMBOL(seq_open);
67378
67379+
67380+int seq_open_restrict(struct file *file, const struct seq_operations *op)
67381+{
67382+ if (gr_proc_is_restricted())
67383+ return -EACCES;
67384+
67385+ return seq_open(file, op);
67386+}
67387+EXPORT_SYMBOL(seq_open_restrict);
67388+
67389 static int traverse(struct seq_file *m, loff_t offset)
67390 {
67391 loff_t pos = 0, index;
67392@@ -165,7 +175,7 @@ Eoverflow:
67393 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
67394 {
67395 struct seq_file *m = file->private_data;
67396- size_t copied = 0;
67397+ ssize_t copied = 0;
67398 loff_t pos;
67399 size_t n;
67400 void *p;
67401@@ -596,7 +606,7 @@ static void single_stop(struct seq_file *p, void *v)
67402 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
67403 void *data)
67404 {
67405- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
67406+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
67407 int res = -ENOMEM;
67408
67409 if (op) {
67410@@ -632,6 +642,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
67411 }
67412 EXPORT_SYMBOL(single_open_size);
67413
67414+int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
67415+ void *data)
67416+{
67417+ if (gr_proc_is_restricted())
67418+ return -EACCES;
67419+
67420+ return single_open(file, show, data);
67421+}
67422+EXPORT_SYMBOL(single_open_restrict);
67423+
67424+
67425 int single_release(struct inode *inode, struct file *file)
67426 {
67427 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
67428diff --git a/fs/splice.c b/fs/splice.c
67429index 75c6058..770d40c 100644
67430--- a/fs/splice.c
67431+++ b/fs/splice.c
67432@@ -193,7 +193,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67433 pipe_lock(pipe);
67434
67435 for (;;) {
67436- if (!pipe->readers) {
67437+ if (!atomic_read(&pipe->readers)) {
67438 send_sig(SIGPIPE, current, 0);
67439 if (!ret)
67440 ret = -EPIPE;
67441@@ -216,7 +216,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67442 page_nr++;
67443 ret += buf->len;
67444
67445- if (pipe->files)
67446+ if (atomic_read(&pipe->files))
67447 do_wakeup = 1;
67448
67449 if (!--spd->nr_pages)
67450@@ -247,9 +247,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67451 do_wakeup = 0;
67452 }
67453
67454- pipe->waiting_writers++;
67455+ atomic_inc(&pipe->waiting_writers);
67456 pipe_wait(pipe);
67457- pipe->waiting_writers--;
67458+ atomic_dec(&pipe->waiting_writers);
67459 }
67460
67461 pipe_unlock(pipe);
67462@@ -576,7 +576,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
67463 old_fs = get_fs();
67464 set_fs(get_ds());
67465 /* The cast to a user pointer is valid due to the set_fs() */
67466- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
67467+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
67468 set_fs(old_fs);
67469
67470 return res;
67471@@ -591,7 +591,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
67472 old_fs = get_fs();
67473 set_fs(get_ds());
67474 /* The cast to a user pointer is valid due to the set_fs() */
67475- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
67476+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
67477 set_fs(old_fs);
67478
67479 return res;
67480@@ -644,7 +644,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
67481 goto err;
67482
67483 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
67484- vec[i].iov_base = (void __user *) page_address(page);
67485+ vec[i].iov_base = (void __force_user *) page_address(page);
67486 vec[i].iov_len = this_len;
67487 spd.pages[i] = page;
67488 spd.nr_pages++;
67489@@ -783,7 +783,7 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
67490 ops->release(pipe, buf);
67491 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
67492 pipe->nrbufs--;
67493- if (pipe->files)
67494+ if (atomic_read(&pipe->files))
67495 sd->need_wakeup = true;
67496 }
67497
67498@@ -807,10 +807,10 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
67499 static int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
67500 {
67501 while (!pipe->nrbufs) {
67502- if (!pipe->writers)
67503+ if (!atomic_read(&pipe->writers))
67504 return 0;
67505
67506- if (!pipe->waiting_writers && sd->num_spliced)
67507+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
67508 return 0;
67509
67510 if (sd->flags & SPLICE_F_NONBLOCK)
67511@@ -1040,7 +1040,7 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
67512 ops->release(pipe, buf);
67513 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
67514 pipe->nrbufs--;
67515- if (pipe->files)
67516+ if (atomic_read(&pipe->files))
67517 sd.need_wakeup = true;
67518 } else {
67519 buf->offset += ret;
67520@@ -1200,7 +1200,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
67521 * out of the pipe right after the splice_to_pipe(). So set
67522 * PIPE_READERS appropriately.
67523 */
67524- pipe->readers = 1;
67525+ atomic_set(&pipe->readers, 1);
67526
67527 current->splice_pipe = pipe;
67528 }
67529@@ -1497,6 +1497,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
67530
67531 partial[buffers].offset = off;
67532 partial[buffers].len = plen;
67533+ partial[buffers].private = 0;
67534
67535 off = 0;
67536 len -= plen;
67537@@ -1733,9 +1734,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67538 ret = -ERESTARTSYS;
67539 break;
67540 }
67541- if (!pipe->writers)
67542+ if (!atomic_read(&pipe->writers))
67543 break;
67544- if (!pipe->waiting_writers) {
67545+ if (!atomic_read(&pipe->waiting_writers)) {
67546 if (flags & SPLICE_F_NONBLOCK) {
67547 ret = -EAGAIN;
67548 break;
67549@@ -1767,7 +1768,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67550 pipe_lock(pipe);
67551
67552 while (pipe->nrbufs >= pipe->buffers) {
67553- if (!pipe->readers) {
67554+ if (!atomic_read(&pipe->readers)) {
67555 send_sig(SIGPIPE, current, 0);
67556 ret = -EPIPE;
67557 break;
67558@@ -1780,9 +1781,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67559 ret = -ERESTARTSYS;
67560 break;
67561 }
67562- pipe->waiting_writers++;
67563+ atomic_inc(&pipe->waiting_writers);
67564 pipe_wait(pipe);
67565- pipe->waiting_writers--;
67566+ atomic_dec(&pipe->waiting_writers);
67567 }
67568
67569 pipe_unlock(pipe);
67570@@ -1818,14 +1819,14 @@ retry:
67571 pipe_double_lock(ipipe, opipe);
67572
67573 do {
67574- if (!opipe->readers) {
67575+ if (!atomic_read(&opipe->readers)) {
67576 send_sig(SIGPIPE, current, 0);
67577 if (!ret)
67578 ret = -EPIPE;
67579 break;
67580 }
67581
67582- if (!ipipe->nrbufs && !ipipe->writers)
67583+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
67584 break;
67585
67586 /*
67587@@ -1922,7 +1923,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
67588 pipe_double_lock(ipipe, opipe);
67589
67590 do {
67591- if (!opipe->readers) {
67592+ if (!atomic_read(&opipe->readers)) {
67593 send_sig(SIGPIPE, current, 0);
67594 if (!ret)
67595 ret = -EPIPE;
67596@@ -1967,7 +1968,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
67597 * return EAGAIN if we have the potential of some data in the
67598 * future, otherwise just return 0
67599 */
67600- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
67601+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
67602 ret = -EAGAIN;
67603
67604 pipe_unlock(ipipe);
67605diff --git a/fs/stat.c b/fs/stat.c
67606index ae0c3ce..9ee641c 100644
67607--- a/fs/stat.c
67608+++ b/fs/stat.c
67609@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
67610 stat->gid = inode->i_gid;
67611 stat->rdev = inode->i_rdev;
67612 stat->size = i_size_read(inode);
67613- stat->atime = inode->i_atime;
67614- stat->mtime = inode->i_mtime;
67615+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
67616+ stat->atime = inode->i_ctime;
67617+ stat->mtime = inode->i_ctime;
67618+ } else {
67619+ stat->atime = inode->i_atime;
67620+ stat->mtime = inode->i_mtime;
67621+ }
67622 stat->ctime = inode->i_ctime;
67623 stat->blksize = (1 << inode->i_blkbits);
67624 stat->blocks = inode->i_blocks;
67625@@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
67626 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
67627 {
67628 struct inode *inode = path->dentry->d_inode;
67629+ int retval;
67630
67631- if (inode->i_op->getattr)
67632- return inode->i_op->getattr(path->mnt, path->dentry, stat);
67633+ if (inode->i_op->getattr) {
67634+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
67635+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
67636+ stat->atime = stat->ctime;
67637+ stat->mtime = stat->ctime;
67638+ }
67639+ return retval;
67640+ }
67641
67642 generic_fillattr(inode, stat);
67643 return 0;
67644diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
67645index 0b45ff4..847de5b 100644
67646--- a/fs/sysfs/dir.c
67647+++ b/fs/sysfs/dir.c
67648@@ -41,9 +41,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
67649 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
67650 {
67651 struct kernfs_node *parent, *kn;
67652+ const char *name;
67653+ umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
67654+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
67655+ const char *parent_name;
67656+#endif
67657
67658 BUG_ON(!kobj);
67659
67660+ name = kobject_name(kobj);
67661+
67662 if (kobj->parent)
67663 parent = kobj->parent->sd;
67664 else
67665@@ -52,11 +59,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
67666 if (!parent)
67667 return -ENOENT;
67668
67669- kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
67670- S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
67671+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
67672+ parent_name = parent->name;
67673+ mode = S_IRWXU;
67674+
67675+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
67676+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
67677+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
67678+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
67679+ mode = S_IRWXU | S_IRUGO | S_IXUGO;
67680+#endif
67681+
67682+ kn = kernfs_create_dir_ns(parent, name,
67683+ mode, kobj, ns);
67684 if (IS_ERR(kn)) {
67685 if (PTR_ERR(kn) == -EEXIST)
67686- sysfs_warn_dup(parent, kobject_name(kobj));
67687+ sysfs_warn_dup(parent, name);
67688 return PTR_ERR(kn);
67689 }
67690
67691diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
67692index 69d4889..a810bd4 100644
67693--- a/fs/sysv/sysv.h
67694+++ b/fs/sysv/sysv.h
67695@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
67696 #endif
67697 }
67698
67699-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
67700+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
67701 {
67702 if (sbi->s_bytesex == BYTESEX_PDP)
67703 return PDP_swab((__force __u32)n);
67704diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
67705index fb08b0c..65fcc7e 100644
67706--- a/fs/ubifs/io.c
67707+++ b/fs/ubifs/io.c
67708@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
67709 return err;
67710 }
67711
67712-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
67713+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
67714 {
67715 int err;
67716
67717diff --git a/fs/udf/dir.c b/fs/udf/dir.c
67718index a012c51..a7690b4 100644
67719--- a/fs/udf/dir.c
67720+++ b/fs/udf/dir.c
67721@@ -167,7 +167,8 @@ static int udf_readdir(struct file *file, struct dir_context *ctx)
67722 continue;
67723 }
67724
67725- flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi);
67726+ flen = udf_get_filename(dir->i_sb, nameptr, lfi, fname,
67727+ UDF_NAME_LEN);
67728 if (!flen)
67729 continue;
67730
67731diff --git a/fs/udf/inode.c b/fs/udf/inode.c
67732index c9b4df5..5bc71d9 100644
67733--- a/fs/udf/inode.c
67734+++ b/fs/udf/inode.c
67735@@ -1489,6 +1489,20 @@ reread:
67736 }
67737 inode->i_generation = iinfo->i_unique;
67738
67739+ /* Sanity checks for files in ICB so that we don't get confused later */
67740+ if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
67741+ /*
67742+ * For file in ICB data is stored in allocation descriptor
67743+ * so sizes should match
67744+ */
67745+ if (iinfo->i_lenAlloc != inode->i_size)
67746+ goto out;
67747+ /* File in ICB has to fit in there... */
67748+ if (inode->i_size > inode->i_sb->s_blocksize -
67749+ udf_file_entry_alloc_offset(inode))
67750+ goto out;
67751+ }
67752+
67753 switch (fe->icbTag.fileType) {
67754 case ICBTAG_FILE_TYPE_DIRECTORY:
67755 inode->i_op = &udf_dir_inode_operations;
67756diff --git a/fs/udf/misc.c b/fs/udf/misc.c
67757index c175b4d..8f36a16 100644
67758--- a/fs/udf/misc.c
67759+++ b/fs/udf/misc.c
67760@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
67761
67762 u8 udf_tag_checksum(const struct tag *t)
67763 {
67764- u8 *data = (u8 *)t;
67765+ const u8 *data = (const u8 *)t;
67766 u8 checksum = 0;
67767 int i;
67768 for (i = 0; i < sizeof(struct tag); ++i)
67769diff --git a/fs/udf/namei.c b/fs/udf/namei.c
67770index c12e260..6ff19b5 100644
67771--- a/fs/udf/namei.c
67772+++ b/fs/udf/namei.c
67773@@ -233,7 +233,8 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
67774 if (!lfi)
67775 continue;
67776
67777- flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi);
67778+ flen = udf_get_filename(dir->i_sb, nameptr, lfi, fname,
67779+ UDF_NAME_LEN);
67780 if (flen && udf_match(flen, fname, child->len, child->name))
67781 goto out_ok;
67782 }
67783diff --git a/fs/udf/symlink.c b/fs/udf/symlink.c
67784index 6fb7945..ac10ca9 100644
67785--- a/fs/udf/symlink.c
67786+++ b/fs/udf/symlink.c
67787@@ -30,49 +30,73 @@
67788 #include <linux/buffer_head.h>
67789 #include "udf_i.h"
67790
67791-static void udf_pc_to_char(struct super_block *sb, unsigned char *from,
67792- int fromlen, unsigned char *to)
67793+static int udf_pc_to_char(struct super_block *sb, unsigned char *from,
67794+ int fromlen, unsigned char *to, int tolen)
67795 {
67796 struct pathComponent *pc;
67797 int elen = 0;
67798+ int comp_len;
67799 unsigned char *p = to;
67800
67801+ /* Reserve one byte for terminating \0 */
67802+ tolen--;
67803 while (elen < fromlen) {
67804 pc = (struct pathComponent *)(from + elen);
67805+ elen += sizeof(struct pathComponent);
67806 switch (pc->componentType) {
67807 case 1:
67808 /*
67809 * Symlink points to some place which should be agreed
67810 * upon between originator and receiver of the media. Ignore.
67811 */
67812- if (pc->lengthComponentIdent > 0)
67813+ if (pc->lengthComponentIdent > 0) {
67814+ elen += pc->lengthComponentIdent;
67815 break;
67816+ }
67817 /* Fall through */
67818 case 2:
67819+ if (tolen == 0)
67820+ return -ENAMETOOLONG;
67821 p = to;
67822 *p++ = '/';
67823+ tolen--;
67824 break;
67825 case 3:
67826+ if (tolen < 3)
67827+ return -ENAMETOOLONG;
67828 memcpy(p, "../", 3);
67829 p += 3;
67830+ tolen -= 3;
67831 break;
67832 case 4:
67833+ if (tolen < 2)
67834+ return -ENAMETOOLONG;
67835 memcpy(p, "./", 2);
67836 p += 2;
67837+ tolen -= 2;
67838 /* that would be . - just ignore */
67839 break;
67840 case 5:
67841- p += udf_get_filename(sb, pc->componentIdent, p,
67842- pc->lengthComponentIdent);
67843+ elen += pc->lengthComponentIdent;
67844+ if (elen > fromlen)
67845+ return -EIO;
67846+ comp_len = udf_get_filename(sb, pc->componentIdent,
67847+ pc->lengthComponentIdent,
67848+ p, tolen);
67849+ p += comp_len;
67850+ tolen -= comp_len;
67851+ if (tolen == 0)
67852+ return -ENAMETOOLONG;
67853 *p++ = '/';
67854+ tolen--;
67855 break;
67856 }
67857- elen += sizeof(struct pathComponent) + pc->lengthComponentIdent;
67858 }
67859 if (p > to + 1)
67860 p[-1] = '\0';
67861 else
67862 p[0] = '\0';
67863+ return 0;
67864 }
67865
67866 static int udf_symlink_filler(struct file *file, struct page *page)
67867@@ -80,11 +104,17 @@ static int udf_symlink_filler(struct file *file, struct page *page)
67868 struct inode *inode = page->mapping->host;
67869 struct buffer_head *bh = NULL;
67870 unsigned char *symlink;
67871- int err = -EIO;
67872+ int err;
67873 unsigned char *p = kmap(page);
67874 struct udf_inode_info *iinfo;
67875 uint32_t pos;
67876
67877+ /* We don't support symlinks longer than one block */
67878+ if (inode->i_size > inode->i_sb->s_blocksize) {
67879+ err = -ENAMETOOLONG;
67880+ goto out_unmap;
67881+ }
67882+
67883 iinfo = UDF_I(inode);
67884 pos = udf_block_map(inode, 0);
67885
67886@@ -94,14 +124,18 @@ static int udf_symlink_filler(struct file *file, struct page *page)
67887 } else {
67888 bh = sb_bread(inode->i_sb, pos);
67889
67890- if (!bh)
67891- goto out;
67892+ if (!bh) {
67893+ err = -EIO;
67894+ goto out_unlock_inode;
67895+ }
67896
67897 symlink = bh->b_data;
67898 }
67899
67900- udf_pc_to_char(inode->i_sb, symlink, inode->i_size, p);
67901+ err = udf_pc_to_char(inode->i_sb, symlink, inode->i_size, p, PAGE_SIZE);
67902 brelse(bh);
67903+ if (err)
67904+ goto out_unlock_inode;
67905
67906 up_read(&iinfo->i_data_sem);
67907 SetPageUptodate(page);
67908@@ -109,9 +143,10 @@ static int udf_symlink_filler(struct file *file, struct page *page)
67909 unlock_page(page);
67910 return 0;
67911
67912-out:
67913+out_unlock_inode:
67914 up_read(&iinfo->i_data_sem);
67915 SetPageError(page);
67916+out_unmap:
67917 kunmap(page);
67918 unlock_page(page);
67919 return err;
67920diff --git a/fs/udf/udfdecl.h b/fs/udf/udfdecl.h
67921index 1cc3c99..47bb3f5 100644
67922--- a/fs/udf/udfdecl.h
67923+++ b/fs/udf/udfdecl.h
67924@@ -211,7 +211,8 @@ udf_get_lb_pblock(struct super_block *sb, struct kernel_lb_addr *loc,
67925 }
67926
67927 /* unicode.c */
67928-extern int udf_get_filename(struct super_block *, uint8_t *, uint8_t *, int);
67929+extern int udf_get_filename(struct super_block *, uint8_t *, int, uint8_t *,
67930+ int);
67931 extern int udf_put_filename(struct super_block *, const uint8_t *, uint8_t *,
67932 int);
67933 extern int udf_build_ustr(struct ustr *, dstring *, int);
67934diff --git a/fs/udf/unicode.c b/fs/udf/unicode.c
67935index afd470e..b84fee3 100644
67936--- a/fs/udf/unicode.c
67937+++ b/fs/udf/unicode.c
67938@@ -28,7 +28,8 @@
67939
67940 #include "udf_sb.h"
67941
67942-static int udf_translate_to_linux(uint8_t *, uint8_t *, int, uint8_t *, int);
67943+static int udf_translate_to_linux(uint8_t *, int, uint8_t *, int, uint8_t *,
67944+ int);
67945
67946 static int udf_char_to_ustr(struct ustr *dest, const uint8_t *src, int strlen)
67947 {
67948@@ -333,8 +334,8 @@ try_again:
67949 return u_len + 1;
67950 }
67951
67952-int udf_get_filename(struct super_block *sb, uint8_t *sname, uint8_t *dname,
67953- int flen)
67954+int udf_get_filename(struct super_block *sb, uint8_t *sname, int slen,
67955+ uint8_t *dname, int dlen)
67956 {
67957 struct ustr *filename, *unifilename;
67958 int len = 0;
67959@@ -347,7 +348,7 @@ int udf_get_filename(struct super_block *sb, uint8_t *sname, uint8_t *dname,
67960 if (!unifilename)
67961 goto out1;
67962
67963- if (udf_build_ustr_exact(unifilename, sname, flen))
67964+ if (udf_build_ustr_exact(unifilename, sname, slen))
67965 goto out2;
67966
67967 if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) {
67968@@ -366,7 +367,8 @@ int udf_get_filename(struct super_block *sb, uint8_t *sname, uint8_t *dname,
67969 } else
67970 goto out2;
67971
67972- len = udf_translate_to_linux(dname, filename->u_name, filename->u_len,
67973+ len = udf_translate_to_linux(dname, dlen,
67974+ filename->u_name, filename->u_len,
67975 unifilename->u_name, unifilename->u_len);
67976 out2:
67977 kfree(unifilename);
67978@@ -403,10 +405,12 @@ int udf_put_filename(struct super_block *sb, const uint8_t *sname,
67979 #define EXT_MARK '.'
67980 #define CRC_MARK '#'
67981 #define EXT_SIZE 5
67982+/* Number of chars we need to store generated CRC to make filename unique */
67983+#define CRC_LEN 5
67984
67985-static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName,
67986- int udfLen, uint8_t *fidName,
67987- int fidNameLen)
67988+static int udf_translate_to_linux(uint8_t *newName, int newLen,
67989+ uint8_t *udfName, int udfLen,
67990+ uint8_t *fidName, int fidNameLen)
67991 {
67992 int index, newIndex = 0, needsCRC = 0;
67993 int extIndex = 0, newExtIndex = 0, hasExt = 0;
67994@@ -439,7 +443,7 @@ static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName,
67995 newExtIndex = newIndex;
67996 }
67997 }
67998- if (newIndex < 256)
67999+ if (newIndex < newLen)
68000 newName[newIndex++] = curr;
68001 else
68002 needsCRC = 1;
68003@@ -467,13 +471,13 @@ static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName,
68004 }
68005 ext[localExtIndex++] = curr;
68006 }
68007- maxFilenameLen = 250 - localExtIndex;
68008+ maxFilenameLen = newLen - CRC_LEN - localExtIndex;
68009 if (newIndex > maxFilenameLen)
68010 newIndex = maxFilenameLen;
68011 else
68012 newIndex = newExtIndex;
68013- } else if (newIndex > 250)
68014- newIndex = 250;
68015+ } else if (newIndex > newLen - CRC_LEN)
68016+ newIndex = newLen - CRC_LEN;
68017 newName[newIndex++] = CRC_MARK;
68018 valueCRC = crc_itu_t(0, fidName, fidNameLen);
68019 newName[newIndex++] = hex_asc_upper_hi(valueCRC >> 8);
68020diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
68021index 8d974c4..b82f6ec 100644
68022--- a/fs/ufs/swab.h
68023+++ b/fs/ufs/swab.h
68024@@ -22,7 +22,7 @@ enum {
68025 BYTESEX_BE
68026 };
68027
68028-static inline u64
68029+static inline u64 __intentional_overflow(-1)
68030 fs64_to_cpu(struct super_block *sbp, __fs64 n)
68031 {
68032 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
68033@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
68034 return (__force __fs64)cpu_to_be64(n);
68035 }
68036
68037-static inline u32
68038+static inline u32 __intentional_overflow(-1)
68039 fs32_to_cpu(struct super_block *sbp, __fs32 n)
68040 {
68041 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
68042diff --git a/fs/utimes.c b/fs/utimes.c
68043index aa138d6..5f3a811 100644
68044--- a/fs/utimes.c
68045+++ b/fs/utimes.c
68046@@ -1,6 +1,7 @@
68047 #include <linux/compiler.h>
68048 #include <linux/file.h>
68049 #include <linux/fs.h>
68050+#include <linux/security.h>
68051 #include <linux/linkage.h>
68052 #include <linux/mount.h>
68053 #include <linux/namei.h>
68054@@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
68055 }
68056 }
68057 retry_deleg:
68058+
68059+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
68060+ error = -EACCES;
68061+ goto mnt_drop_write_and_out;
68062+ }
68063+
68064 mutex_lock(&inode->i_mutex);
68065 error = notify_change(path->dentry, &newattrs, &delegated_inode);
68066 mutex_unlock(&inode->i_mutex);
68067diff --git a/fs/xattr.c b/fs/xattr.c
68068index 64e83ef..b6be154 100644
68069--- a/fs/xattr.c
68070+++ b/fs/xattr.c
68071@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
68072 return rc;
68073 }
68074
68075+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
68076+ssize_t
68077+pax_getxattr(struct dentry *dentry, void *value, size_t size)
68078+{
68079+ struct inode *inode = dentry->d_inode;
68080+ ssize_t error;
68081+
68082+ error = inode_permission(inode, MAY_EXEC);
68083+ if (error)
68084+ return error;
68085+
68086+ if (inode->i_op->getxattr)
68087+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
68088+ else
68089+ error = -EOPNOTSUPP;
68090+
68091+ return error;
68092+}
68093+EXPORT_SYMBOL(pax_getxattr);
68094+#endif
68095+
68096 ssize_t
68097 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
68098 {
68099@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
68100 * Extended attribute SET operations
68101 */
68102 static long
68103-setxattr(struct dentry *d, const char __user *name, const void __user *value,
68104+setxattr(struct path *path, const char __user *name, const void __user *value,
68105 size_t size, int flags)
68106 {
68107 int error;
68108@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
68109 posix_acl_fix_xattr_from_user(kvalue, size);
68110 }
68111
68112- error = vfs_setxattr(d, kname, kvalue, size, flags);
68113+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
68114+ error = -EACCES;
68115+ goto out;
68116+ }
68117+
68118+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
68119 out:
68120 if (vvalue)
68121 vfree(vvalue);
68122@@ -376,7 +402,7 @@ retry:
68123 return error;
68124 error = mnt_want_write(path.mnt);
68125 if (!error) {
68126- error = setxattr(path.dentry, name, value, size, flags);
68127+ error = setxattr(&path, name, value, size, flags);
68128 mnt_drop_write(path.mnt);
68129 }
68130 path_put(&path);
68131@@ -405,16 +431,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
68132 const void __user *,value, size_t, size, int, flags)
68133 {
68134 struct fd f = fdget(fd);
68135- struct dentry *dentry;
68136 int error = -EBADF;
68137
68138 if (!f.file)
68139 return error;
68140- dentry = f.file->f_path.dentry;
68141- audit_inode(NULL, dentry, 0);
68142+ audit_inode(NULL, f.file->f_path.dentry, 0);
68143 error = mnt_want_write_file(f.file);
68144 if (!error) {
68145- error = setxattr(dentry, name, value, size, flags);
68146+ error = setxattr(&f.file->f_path, name, value, size, flags);
68147 mnt_drop_write_file(f.file);
68148 }
68149 fdput(f);
68150@@ -600,7 +624,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
68151 * Extended attribute REMOVE operations
68152 */
68153 static long
68154-removexattr(struct dentry *d, const char __user *name)
68155+removexattr(struct path *path, const char __user *name)
68156 {
68157 int error;
68158 char kname[XATTR_NAME_MAX + 1];
68159@@ -611,7 +635,10 @@ removexattr(struct dentry *d, const char __user *name)
68160 if (error < 0)
68161 return error;
68162
68163- return vfs_removexattr(d, kname);
68164+ if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
68165+ return -EACCES;
68166+
68167+ return vfs_removexattr(path->dentry, kname);
68168 }
68169
68170 static int path_removexattr(const char __user *pathname,
68171@@ -625,7 +652,7 @@ retry:
68172 return error;
68173 error = mnt_want_write(path.mnt);
68174 if (!error) {
68175- error = removexattr(path.dentry, name);
68176+ error = removexattr(&path, name);
68177 mnt_drop_write(path.mnt);
68178 }
68179 path_put(&path);
68180@@ -651,16 +678,16 @@ SYSCALL_DEFINE2(lremovexattr, const char __user *, pathname,
68181 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
68182 {
68183 struct fd f = fdget(fd);
68184- struct dentry *dentry;
68185+ struct path *path;
68186 int error = -EBADF;
68187
68188 if (!f.file)
68189 return error;
68190- dentry = f.file->f_path.dentry;
68191- audit_inode(NULL, dentry, 0);
68192+ path = &f.file->f_path;
68193+ audit_inode(NULL, path->dentry, 0);
68194 error = mnt_want_write_file(f.file);
68195 if (!error) {
68196- error = removexattr(dentry, name);
68197+ error = removexattr(path, name);
68198 mnt_drop_write_file(f.file);
68199 }
68200 fdput(f);
68201diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
68202index 79c9819..22226b4 100644
68203--- a/fs/xfs/libxfs/xfs_bmap.c
68204+++ b/fs/xfs/libxfs/xfs_bmap.c
68205@@ -583,7 +583,7 @@ xfs_bmap_validate_ret(
68206
68207 #else
68208 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
68209-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
68210+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
68211 #endif /* DEBUG */
68212
68213 /*
68214diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
68215index f1b69ed..3d0222f 100644
68216--- a/fs/xfs/xfs_dir2_readdir.c
68217+++ b/fs/xfs/xfs_dir2_readdir.c
68218@@ -159,7 +159,12 @@ xfs_dir2_sf_getdents(
68219 ino = dp->d_ops->sf_get_ino(sfp, sfep);
68220 filetype = dp->d_ops->sf_get_ftype(sfep);
68221 ctx->pos = off & 0x7fffffff;
68222- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
68223+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
68224+ char name[sfep->namelen];
68225+ memcpy(name, sfep->name, sfep->namelen);
68226+ if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(dp->i_mount, filetype)))
68227+ return 0;
68228+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
68229 xfs_dir3_get_dtype(dp->i_mount, filetype)))
68230 return 0;
68231 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
68232diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
68233index 24c926b6..8726af88 100644
68234--- a/fs/xfs/xfs_ioctl.c
68235+++ b/fs/xfs/xfs_ioctl.c
68236@@ -122,7 +122,7 @@ xfs_find_handle(
68237 }
68238
68239 error = -EFAULT;
68240- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
68241+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
68242 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
68243 goto out_put;
68244
68245diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h
68246index 6a51619..9592e1b 100644
68247--- a/fs/xfs/xfs_linux.h
68248+++ b/fs/xfs/xfs_linux.h
68249@@ -234,7 +234,7 @@ static inline kgid_t xfs_gid_to_kgid(__uint32_t gid)
68250 * of the compiler which do not like us using do_div in the middle
68251 * of large functions.
68252 */
68253-static inline __u32 xfs_do_div(void *a, __u32 b, int n)
68254+static inline __u32 __intentional_overflow(-1) xfs_do_div(void *a, __u32 b, int n)
68255 {
68256 __u32 mod;
68257
68258@@ -290,7 +290,7 @@ static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
68259 return 0;
68260 }
68261 #else
68262-static inline __u32 xfs_do_div(void *a, __u32 b, int n)
68263+static inline __u32 __intentional_overflow(-1) xfs_do_div(void *a, __u32 b, int n)
68264 {
68265 __u32 mod;
68266
68267diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
68268new file mode 100644
68269index 0000000..f27264e
68270--- /dev/null
68271+++ b/grsecurity/Kconfig
68272@@ -0,0 +1,1166 @@
68273+#
68274+# grecurity configuration
68275+#
68276+menu "Memory Protections"
68277+depends on GRKERNSEC
68278+
68279+config GRKERNSEC_KMEM
68280+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
68281+ default y if GRKERNSEC_CONFIG_AUTO
68282+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
68283+ help
68284+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
68285+ be written to or read from to modify or leak the contents of the running
68286+ kernel. /dev/port will also not be allowed to be opened, writing to
68287+ /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
68288+ If you have module support disabled, enabling this will close up several
68289+ ways that are currently used to insert malicious code into the running
68290+ kernel.
68291+
68292+ Even with this feature enabled, we still highly recommend that
68293+ you use the RBAC system, as it is still possible for an attacker to
68294+ modify the running kernel through other more obscure methods.
68295+
68296+ It is highly recommended that you say Y here if you meet all the
68297+ conditions above.
68298+
68299+config GRKERNSEC_VM86
68300+ bool "Restrict VM86 mode"
68301+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68302+ depends on X86_32
68303+
68304+ help
68305+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
68306+ make use of a special execution mode on 32bit x86 processors called
68307+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
68308+ video cards and will still work with this option enabled. The purpose
68309+ of the option is to prevent exploitation of emulation errors in
68310+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
68311+ Nearly all users should be able to enable this option.
68312+
68313+config GRKERNSEC_IO
68314+ bool "Disable privileged I/O"
68315+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68316+ depends on X86
68317+ select RTC_CLASS
68318+ select RTC_INTF_DEV
68319+ select RTC_DRV_CMOS
68320+
68321+ help
68322+ If you say Y here, all ioperm and iopl calls will return an error.
68323+ Ioperm and iopl can be used to modify the running kernel.
68324+ Unfortunately, some programs need this access to operate properly,
68325+ the most notable of which are XFree86 and hwclock. hwclock can be
68326+ remedied by having RTC support in the kernel, so real-time
68327+ clock support is enabled if this option is enabled, to ensure
68328+ that hwclock operates correctly. If hwclock still does not work,
68329+ either update udev or symlink /dev/rtc to /dev/rtc0.
68330+
68331+ If you're using XFree86 or a version of Xorg from 2012 or earlier,
68332+ you may not be able to boot into a graphical environment with this
68333+ option enabled. In this case, you should use the RBAC system instead.
68334+
68335+config GRKERNSEC_BPF_HARDEN
68336+ bool "Harden BPF interpreter"
68337+ default y if GRKERNSEC_CONFIG_AUTO
68338+ help
68339+ Unlike previous versions of grsecurity that hardened both the BPF
68340+ interpreted code against corruption at rest as well as the JIT code
68341+ against JIT-spray attacks and attacker-controlled immediate values
68342+ for ROP, this feature will enforce disabling of the new eBPF JIT engine
68343+ and will ensure the interpreted code is read-only at rest. This feature
68344+ may be removed at a later time when eBPF stabilizes to entirely revert
68345+ back to the more secure pre-3.16 BPF interpreter/JIT.
68346+
68347+ If you're using KERNEXEC, it's recommended that you enable this option
68348+ to supplement the hardening of the kernel.
68349+
68350+config GRKERNSEC_PERF_HARDEN
68351+ bool "Disable unprivileged PERF_EVENTS usage by default"
68352+ default y if GRKERNSEC_CONFIG_AUTO
68353+ depends on PERF_EVENTS
68354+ help
68355+ If you say Y here, the range of acceptable values for the
68356+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
68357+ default to a new value: 3. When the sysctl is set to this value, no
68358+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
68359+
68360+ Though PERF_EVENTS can be used legitimately for performance monitoring
68361+ and low-level application profiling, it is forced on regardless of
68362+ configuration, has been at fault for several vulnerabilities, and
68363+ creates new opportunities for side channels and other information leaks.
68364+
68365+ This feature puts PERF_EVENTS into a secure default state and permits
68366+ the administrator to change out of it temporarily if unprivileged
68367+ application profiling is needed.
68368+
68369+config GRKERNSEC_RAND_THREADSTACK
68370+ bool "Insert random gaps between thread stacks"
68371+ default y if GRKERNSEC_CONFIG_AUTO
68372+ depends on PAX_RANDMMAP && !PPC
68373+ help
68374+ If you say Y here, a random-sized gap will be enforced between allocated
68375+ thread stacks. Glibc's NPTL and other threading libraries that
68376+ pass MAP_STACK to the kernel for thread stack allocation are supported.
68377+ The implementation currently provides 8 bits of entropy for the gap.
68378+
68379+ Many distributions do not compile threaded remote services with the
68380+ -fstack-check argument to GCC, causing the variable-sized stack-based
68381+ allocator, alloca(), to not probe the stack on allocation. This
68382+ permits an unbounded alloca() to skip over any guard page and potentially
68383+ modify another thread's stack reliably. An enforced random gap
68384+ reduces the reliability of such an attack and increases the chance
68385+ that such a read/write to another thread's stack instead lands in
68386+ an unmapped area, causing a crash and triggering grsecurity's
68387+ anti-bruteforcing logic.
68388+
68389+config GRKERNSEC_PROC_MEMMAP
68390+ bool "Harden ASLR against information leaks and entropy reduction"
68391+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
68392+ depends on PAX_NOEXEC || PAX_ASLR
68393+ help
68394+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
68395+ give no information about the addresses of its mappings if
68396+ PaX features that rely on random addresses are enabled on the task.
68397+ In addition to sanitizing this information and disabling other
68398+ dangerous sources of information, this option causes reads of sensitive
68399+ /proc/<pid> entries where the file descriptor was opened in a different
68400+ task than the one performing the read. Such attempts are logged.
68401+ This option also limits argv/env strings for suid/sgid binaries
68402+ to 512KB to prevent a complete exhaustion of the stack entropy provided
68403+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
68404+ binaries to prevent alternative mmap layouts from being abused.
68405+
68406+ If you use PaX it is essential that you say Y here as it closes up
68407+ several holes that make full ASLR useless locally.
68408+
68409+
68410+config GRKERNSEC_KSTACKOVERFLOW
68411+ bool "Prevent kernel stack overflows"
68412+ default y if GRKERNSEC_CONFIG_AUTO
68413+ depends on !IA64 && 64BIT
68414+ help
68415+ If you say Y here, the kernel's process stacks will be allocated
68416+ with vmalloc instead of the kernel's default allocator. This
68417+ introduces guard pages that in combination with the alloca checking
68418+ of the STACKLEAK feature prevents all forms of kernel process stack
68419+ overflow abuse. Note that this is different from kernel stack
68420+ buffer overflows.
68421+
68422+config GRKERNSEC_BRUTE
68423+ bool "Deter exploit bruteforcing"
68424+ default y if GRKERNSEC_CONFIG_AUTO
68425+ help
68426+ If you say Y here, attempts to bruteforce exploits against forking
68427+ daemons such as apache or sshd, as well as against suid/sgid binaries
68428+ will be deterred. When a child of a forking daemon is killed by PaX
68429+ or crashes due to an illegal instruction or other suspicious signal,
68430+ the parent process will be delayed 30 seconds upon every subsequent
68431+ fork until the administrator is able to assess the situation and
68432+ restart the daemon.
68433+ In the suid/sgid case, the attempt is logged, the user has all their
68434+ existing instances of the suid/sgid binary terminated and will
68435+ be unable to execute any suid/sgid binaries for 15 minutes.
68436+
68437+ It is recommended that you also enable signal logging in the auditing
68438+ section so that logs are generated when a process triggers a suspicious
68439+ signal.
68440+ If the sysctl option is enabled, a sysctl option with name
68441+ "deter_bruteforce" is created.
68442+
68443+config GRKERNSEC_MODHARDEN
68444+ bool "Harden module auto-loading"
68445+ default y if GRKERNSEC_CONFIG_AUTO
68446+ depends on MODULES
68447+ help
68448+ If you say Y here, module auto-loading in response to use of some
68449+ feature implemented by an unloaded module will be restricted to
68450+ root users. Enabling this option helps defend against attacks
68451+ by unprivileged users who abuse the auto-loading behavior to
68452+ cause a vulnerable module to load that is then exploited.
68453+
68454+ If this option prevents a legitimate use of auto-loading for a
68455+ non-root user, the administrator can execute modprobe manually
68456+ with the exact name of the module mentioned in the alert log.
68457+ Alternatively, the administrator can add the module to the list
68458+ of modules loaded at boot by modifying init scripts.
68459+
68460+ Modification of init scripts will most likely be needed on
68461+ Ubuntu servers with encrypted home directory support enabled,
68462+ as the first non-root user logging in will cause the ecb(aes),
68463+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
68464+
68465+config GRKERNSEC_HIDESYM
68466+ bool "Hide kernel symbols"
68467+ default y if GRKERNSEC_CONFIG_AUTO
68468+ select PAX_USERCOPY_SLABS
68469+ help
68470+ If you say Y here, getting information on loaded modules, and
68471+ displaying all kernel symbols through a syscall will be restricted
68472+ to users with CAP_SYS_MODULE. For software compatibility reasons,
68473+ /proc/kallsyms will be restricted to the root user. The RBAC
68474+ system can hide that entry even from root.
68475+
68476+ This option also prevents leaking of kernel addresses through
68477+ several /proc entries.
68478+
68479+ Note that this option is only effective provided the following
68480+ conditions are met:
68481+ 1) The kernel using grsecurity is not precompiled by some distribution
68482+ 2) You have also enabled GRKERNSEC_DMESG
68483+ 3) You are using the RBAC system and hiding other files such as your
68484+ kernel image and System.map. Alternatively, enabling this option
68485+ causes the permissions on /boot, /lib/modules, and the kernel
68486+ source directory to change at compile time to prevent
68487+ reading by non-root users.
68488+ If the above conditions are met, this option will aid in providing a
68489+ useful protection against local kernel exploitation of overflows
68490+ and arbitrary read/write vulnerabilities.
68491+
68492+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
68493+ in addition to this feature.
68494+
68495+config GRKERNSEC_RANDSTRUCT
68496+ bool "Randomize layout of sensitive kernel structures"
68497+ default y if GRKERNSEC_CONFIG_AUTO
68498+ select GRKERNSEC_HIDESYM
68499+ select MODVERSIONS if MODULES
68500+ help
68501+ If you say Y here, the layouts of a number of sensitive kernel
68502+ structures (task, fs, cred, etc) and all structures composed entirely
68503+ of function pointers (aka "ops" structs) will be randomized at compile-time.
68504+ This can introduce the requirement of an additional infoleak
68505+ vulnerability for exploits targeting these structure types.
68506+
68507+ Enabling this feature will introduce some performance impact, slightly
68508+ increase memory usage, and prevent the use of forensic tools like
68509+ Volatility against the system (unless the kernel source tree isn't
68510+ cleaned after kernel installation).
68511+
68512+ The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
68513+ It remains after a make clean to allow for external modules to be compiled
68514+ with the existing seed and will be removed by a make mrproper or
68515+ make distclean.
68516+
68517+ Note that the implementation requires gcc 4.6.4. or newer. You may need
68518+ to install the supporting headers explicitly in addition to the normal
68519+ gcc package.
68520+
68521+config GRKERNSEC_RANDSTRUCT_PERFORMANCE
68522+ bool "Use cacheline-aware structure randomization"
68523+ depends on GRKERNSEC_RANDSTRUCT
68524+ default y if GRKERNSEC_CONFIG_PRIORITY_PERF
68525+ help
68526+ If you say Y here, the RANDSTRUCT randomization will make a best effort
68527+ at restricting randomization to cacheline-sized groups of elements. It
68528+ will further not randomize bitfields in structures. This reduces the
68529+ performance hit of RANDSTRUCT at the cost of weakened randomization.
68530+
68531+config GRKERNSEC_KERN_LOCKOUT
68532+ bool "Active kernel exploit response"
68533+ default y if GRKERNSEC_CONFIG_AUTO
68534+ depends on X86 || ARM || PPC || SPARC
68535+ help
68536+ If you say Y here, when a PaX alert is triggered due to suspicious
68537+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
68538+ or an OOPS occurs due to bad memory accesses, instead of just
68539+ terminating the offending process (and potentially allowing
68540+ a subsequent exploit from the same user), we will take one of two
68541+ actions:
68542+ If the user was root, we will panic the system
68543+ If the user was non-root, we will log the attempt, terminate
68544+ all processes owned by the user, then prevent them from creating
68545+ any new processes until the system is restarted
68546+ This deters repeated kernel exploitation/bruteforcing attempts
68547+ and is useful for later forensics.
68548+
68549+config GRKERNSEC_OLD_ARM_USERLAND
68550+ bool "Old ARM userland compatibility"
68551+ depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
68552+ help
68553+ If you say Y here, stubs of executable code to perform such operations
68554+ as "compare-exchange" will be placed at fixed locations in the ARM vector
68555+ table. This is unfortunately needed for old ARM userland meant to run
68556+ across a wide range of processors. Without this option enabled,
68557+ the get_tls and data memory barrier stubs will be emulated by the kernel,
68558+ which is enough for Linaro userlands or other userlands designed for v6
68559+ and newer ARM CPUs. It's recommended that you try without this option enabled
68560+ first, and only enable it if your userland does not boot (it will likely fail
68561+ at init time).
68562+
68563+endmenu
68564+menu "Role Based Access Control Options"
68565+depends on GRKERNSEC
68566+
68567+config GRKERNSEC_RBAC_DEBUG
68568+ bool
68569+
68570+config GRKERNSEC_NO_RBAC
68571+ bool "Disable RBAC system"
68572+ help
68573+ If you say Y here, the /dev/grsec device will be removed from the kernel,
68574+ preventing the RBAC system from being enabled. You should only say Y
68575+ here if you have no intention of using the RBAC system, so as to prevent
68576+ an attacker with root access from misusing the RBAC system to hide files
68577+ and processes when loadable module support and /dev/[k]mem have been
68578+ locked down.
68579+
68580+config GRKERNSEC_ACL_HIDEKERN
68581+ bool "Hide kernel processes"
68582+ help
68583+ If you say Y here, all kernel threads will be hidden to all
68584+ processes but those whose subject has the "view hidden processes"
68585+ flag.
68586+
68587+config GRKERNSEC_ACL_MAXTRIES
68588+ int "Maximum tries before password lockout"
68589+ default 3
68590+ help
68591+ This option enforces the maximum number of times a user can attempt
68592+ to authorize themselves with the grsecurity RBAC system before being
68593+ denied the ability to attempt authorization again for a specified time.
68594+ The lower the number, the harder it will be to brute-force a password.
68595+
68596+config GRKERNSEC_ACL_TIMEOUT
68597+ int "Time to wait after max password tries, in seconds"
68598+ default 30
68599+ help
68600+ This option specifies the time the user must wait after attempting to
68601+ authorize to the RBAC system with the maximum number of invalid
68602+ passwords. The higher the number, the harder it will be to brute-force
68603+ a password.
68604+
68605+endmenu
68606+menu "Filesystem Protections"
68607+depends on GRKERNSEC
68608+
68609+config GRKERNSEC_PROC
68610+ bool "Proc restrictions"
68611+ default y if GRKERNSEC_CONFIG_AUTO
68612+ help
68613+ If you say Y here, the permissions of the /proc filesystem
68614+ will be altered to enhance system security and privacy. You MUST
68615+ choose either a user only restriction or a user and group restriction.
68616+ Depending upon the option you choose, you can either restrict users to
68617+ see only the processes they themselves run, or choose a group that can
68618+ view all processes and files normally restricted to root if you choose
68619+ the "restrict to user only" option. NOTE: If you're running identd or
68620+ ntpd as a non-root user, you will have to run it as the group you
68621+ specify here.
68622+
68623+config GRKERNSEC_PROC_USER
68624+ bool "Restrict /proc to user only"
68625+ depends on GRKERNSEC_PROC
68626+ help
68627+ If you say Y here, non-root users will only be able to view their own
68628+ processes, and restricts them from viewing network-related information,
68629+ and viewing kernel symbol and module information.
68630+
68631+config GRKERNSEC_PROC_USERGROUP
68632+ bool "Allow special group"
68633+ default y if GRKERNSEC_CONFIG_AUTO
68634+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
68635+ help
68636+ If you say Y here, you will be able to select a group that will be
68637+ able to view all processes and network-related information. If you've
68638+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
68639+ remain hidden. This option is useful if you want to run identd as
68640+ a non-root user. The group you select may also be chosen at boot time
68641+ via "grsec_proc_gid=" on the kernel commandline.
68642+
68643+config GRKERNSEC_PROC_GID
68644+ int "GID for special group"
68645+ depends on GRKERNSEC_PROC_USERGROUP
68646+ default 1001
68647+
68648+config GRKERNSEC_PROC_ADD
68649+ bool "Additional restrictions"
68650+ default y if GRKERNSEC_CONFIG_AUTO
68651+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
68652+ help
68653+ If you say Y here, additional restrictions will be placed on
68654+ /proc that keep normal users from viewing device information and
68655+ slabinfo information that could be useful for exploits.
68656+
68657+config GRKERNSEC_LINK
68658+ bool "Linking restrictions"
68659+ default y if GRKERNSEC_CONFIG_AUTO
68660+ help
68661+ If you say Y here, /tmp race exploits will be prevented, since users
68662+ will no longer be able to follow symlinks owned by other users in
68663+ world-writable +t directories (e.g. /tmp), unless the owner of the
68664+ symlink is the owner of the directory. users will also not be
68665+ able to hardlink to files they do not own. If the sysctl option is
68666+ enabled, a sysctl option with name "linking_restrictions" is created.
68667+
68668+config GRKERNSEC_SYMLINKOWN
68669+ bool "Kernel-enforced SymlinksIfOwnerMatch"
68670+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
68671+ help
68672+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
68673+ that prevents it from being used as a security feature. As Apache
68674+ verifies the symlink by performing a stat() against the target of
68675+ the symlink before it is followed, an attacker can setup a symlink
68676+ to point to a same-owned file, then replace the symlink with one
68677+ that targets another user's file just after Apache "validates" the
68678+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
68679+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
68680+ will be in place for the group you specify. If the sysctl option
68681+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
68682+ created.
68683+
68684+config GRKERNSEC_SYMLINKOWN_GID
68685+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
68686+ depends on GRKERNSEC_SYMLINKOWN
68687+ default 1006
68688+ help
68689+ Setting this GID determines what group kernel-enforced
68690+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
68691+ is enabled, a sysctl option with name "symlinkown_gid" is created.
68692+
68693+config GRKERNSEC_FIFO
68694+ bool "FIFO restrictions"
68695+ default y if GRKERNSEC_CONFIG_AUTO
68696+ help
68697+ If you say Y here, users will not be able to write to FIFOs they don't
68698+ own in world-writable +t directories (e.g. /tmp), unless the owner of
68699+ the FIFO is the same owner of the directory it's held in. If the sysctl
68700+ option is enabled, a sysctl option with name "fifo_restrictions" is
68701+ created.
68702+
68703+config GRKERNSEC_SYSFS_RESTRICT
68704+ bool "Sysfs/debugfs restriction"
68705+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68706+ depends on SYSFS
68707+ help
68708+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
68709+ any filesystem normally mounted under it (e.g. debugfs) will be
68710+ mostly accessible only by root. These filesystems generally provide access
68711+ to hardware and debug information that isn't appropriate for unprivileged
68712+ users of the system. Sysfs and debugfs have also become a large source
68713+ of new vulnerabilities, ranging from infoleaks to local compromise.
68714+ There has been very little oversight with an eye toward security involved
68715+ in adding new exporters of information to these filesystems, so their
68716+ use is discouraged.
68717+ For reasons of compatibility, a few directories have been whitelisted
68718+ for access by non-root users:
68719+ /sys/fs/selinux
68720+ /sys/fs/fuse
68721+ /sys/devices/system/cpu
68722+
68723+config GRKERNSEC_ROFS
68724+ bool "Runtime read-only mount protection"
68725+ depends on SYSCTL
68726+ help
68727+ If you say Y here, a sysctl option with name "romount_protect" will
68728+ be created. By setting this option to 1 at runtime, filesystems
68729+ will be protected in the following ways:
68730+ * No new writable mounts will be allowed
68731+ * Existing read-only mounts won't be able to be remounted read/write
68732+ * Write operations will be denied on all block devices
68733+ This option acts independently of grsec_lock: once it is set to 1,
68734+ it cannot be turned off. Therefore, please be mindful of the resulting
68735+ behavior if this option is enabled in an init script on a read-only
68736+ filesystem.
68737+ Also be aware that as with other root-focused features, GRKERNSEC_KMEM
68738+ and GRKERNSEC_IO should be enabled and module loading disabled via
68739+ config or at runtime.
68740+ This feature is mainly intended for secure embedded systems.
68741+
68742+
68743+config GRKERNSEC_DEVICE_SIDECHANNEL
68744+ bool "Eliminate stat/notify-based device sidechannels"
68745+ default y if GRKERNSEC_CONFIG_AUTO
68746+ help
68747+ If you say Y here, timing analyses on block or character
68748+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
68749+ will be thwarted for unprivileged users. If a process without
68750+ CAP_MKNOD stats such a device, the last access and last modify times
68751+ will match the device's create time. No access or modify events
68752+ will be triggered through inotify/dnotify/fanotify for such devices.
68753+ This feature will prevent attacks that may at a minimum
68754+ allow an attacker to determine the administrator's password length.
68755+
68756+config GRKERNSEC_CHROOT
68757+ bool "Chroot jail restrictions"
68758+ default y if GRKERNSEC_CONFIG_AUTO
68759+ help
68760+ If you say Y here, you will be able to choose several options that will
68761+ make breaking out of a chrooted jail much more difficult. If you
68762+ encounter no software incompatibilities with the following options, it
68763+ is recommended that you enable each one.
68764+
68765+ Note that the chroot restrictions are not intended to apply to "chroots"
68766+ to directories that are simple bind mounts of the global root filesystem.
68767+ For several other reasons, a user shouldn't expect any significant
68768+ security by performing such a chroot.
68769+
68770+config GRKERNSEC_CHROOT_MOUNT
68771+ bool "Deny mounts"
68772+ default y if GRKERNSEC_CONFIG_AUTO
68773+ depends on GRKERNSEC_CHROOT
68774+ help
68775+ If you say Y here, processes inside a chroot will not be able to
68776+ mount or remount filesystems. If the sysctl option is enabled, a
68777+ sysctl option with name "chroot_deny_mount" is created.
68778+
68779+config GRKERNSEC_CHROOT_DOUBLE
68780+ bool "Deny double-chroots"
68781+ default y if GRKERNSEC_CONFIG_AUTO
68782+ depends on GRKERNSEC_CHROOT
68783+ help
68784+ If you say Y here, processes inside a chroot will not be able to chroot
68785+ again outside the chroot. This is a widely used method of breaking
68786+ out of a chroot jail and should not be allowed. If the sysctl
68787+ option is enabled, a sysctl option with name
68788+ "chroot_deny_chroot" is created.
68789+
68790+config GRKERNSEC_CHROOT_PIVOT
68791+ bool "Deny pivot_root in chroot"
68792+ default y if GRKERNSEC_CONFIG_AUTO
68793+ depends on GRKERNSEC_CHROOT
68794+ help
68795+ If you say Y here, processes inside a chroot will not be able to use
68796+ a function called pivot_root() that was introduced in Linux 2.3.41. It
68797+ works similar to chroot in that it changes the root filesystem. This
68798+ function could be misused in a chrooted process to attempt to break out
68799+ of the chroot, and therefore should not be allowed. If the sysctl
68800+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
68801+ created.
68802+
68803+config GRKERNSEC_CHROOT_CHDIR
68804+ bool "Enforce chdir(\"/\") on all chroots"
68805+ default y if GRKERNSEC_CONFIG_AUTO
68806+ depends on GRKERNSEC_CHROOT
68807+ help
68808+ If you say Y here, the current working directory of all newly-chrooted
68809+ applications will be set to the the root directory of the chroot.
68810+ The man page on chroot(2) states:
68811+ Note that this call does not change the current working
68812+ directory, so that `.' can be outside the tree rooted at
68813+ `/'. In particular, the super-user can escape from a
68814+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
68815+
68816+ It is recommended that you say Y here, since it's not known to break
68817+ any software. If the sysctl option is enabled, a sysctl option with
68818+ name "chroot_enforce_chdir" is created.
68819+
68820+config GRKERNSEC_CHROOT_CHMOD
68821+ bool "Deny (f)chmod +s"
68822+ default y if GRKERNSEC_CONFIG_AUTO
68823+ depends on GRKERNSEC_CHROOT
68824+ help
68825+ If you say Y here, processes inside a chroot will not be able to chmod
68826+ or fchmod files to make them have suid or sgid bits. This protects
68827+ against another published method of breaking a chroot. If the sysctl
68828+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
68829+ created.
68830+
68831+config GRKERNSEC_CHROOT_FCHDIR
68832+ bool "Deny fchdir and fhandle out of chroot"
68833+ default y if GRKERNSEC_CONFIG_AUTO
68834+ depends on GRKERNSEC_CHROOT
68835+ help
68836+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
68837+ to a file descriptor of the chrooting process that points to a directory
68838+ outside the filesystem will be stopped. Additionally, this option prevents
68839+ use of the recently-created syscall for opening files by a guessable "file
68840+ handle" inside a chroot. If the sysctl option is enabled, a sysctl option
68841+ with name "chroot_deny_fchdir" is created.
68842+
68843+config GRKERNSEC_CHROOT_MKNOD
68844+ bool "Deny mknod"
68845+ default y if GRKERNSEC_CONFIG_AUTO
68846+ depends on GRKERNSEC_CHROOT
68847+ help
68848+ If you say Y here, processes inside a chroot will not be allowed to
68849+ mknod. The problem with using mknod inside a chroot is that it
68850+ would allow an attacker to create a device entry that is the same
68851+ as one on the physical root of your system, which could range from
68852+ anything from the console device to a device for your harddrive (which
68853+ they could then use to wipe the drive or steal data). It is recommended
68854+ that you say Y here, unless you run into software incompatibilities.
68855+ If the sysctl option is enabled, a sysctl option with name
68856+ "chroot_deny_mknod" is created.
68857+
68858+config GRKERNSEC_CHROOT_SHMAT
68859+ bool "Deny shmat() out of chroot"
68860+ default y if GRKERNSEC_CONFIG_AUTO
68861+ depends on GRKERNSEC_CHROOT
68862+ help
68863+ If you say Y here, processes inside a chroot will not be able to attach
68864+ to shared memory segments that were created outside of the chroot jail.
68865+ It is recommended that you say Y here. If the sysctl option is enabled,
68866+ a sysctl option with name "chroot_deny_shmat" is created.
68867+
68868+config GRKERNSEC_CHROOT_UNIX
68869+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
68870+ default y if GRKERNSEC_CONFIG_AUTO
68871+ depends on GRKERNSEC_CHROOT
68872+ help
68873+ If you say Y here, processes inside a chroot will not be able to
68874+ connect to abstract (meaning not belonging to a filesystem) Unix
68875+ domain sockets that were bound outside of a chroot. It is recommended
68876+ that you say Y here. If the sysctl option is enabled, a sysctl option
68877+ with name "chroot_deny_unix" is created.
68878+
68879+config GRKERNSEC_CHROOT_FINDTASK
68880+ bool "Protect outside processes"
68881+ default y if GRKERNSEC_CONFIG_AUTO
68882+ depends on GRKERNSEC_CHROOT
68883+ help
68884+ If you say Y here, processes inside a chroot will not be able to
68885+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
68886+ getsid, or view any process outside of the chroot. If the sysctl
68887+ option is enabled, a sysctl option with name "chroot_findtask" is
68888+ created.
68889+
68890+config GRKERNSEC_CHROOT_NICE
68891+ bool "Restrict priority changes"
68892+ default y if GRKERNSEC_CONFIG_AUTO
68893+ depends on GRKERNSEC_CHROOT
68894+ help
68895+ If you say Y here, processes inside a chroot will not be able to raise
68896+ the priority of processes in the chroot, or alter the priority of
68897+ processes outside the chroot. This provides more security than simply
68898+ removing CAP_SYS_NICE from the process' capability set. If the
68899+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
68900+ is created.
68901+
68902+config GRKERNSEC_CHROOT_SYSCTL
68903+ bool "Deny sysctl writes"
68904+ default y if GRKERNSEC_CONFIG_AUTO
68905+ depends on GRKERNSEC_CHROOT
68906+ help
68907+ If you say Y here, an attacker in a chroot will not be able to
68908+ write to sysctl entries, either by sysctl(2) or through a /proc
68909+ interface. It is strongly recommended that you say Y here. If the
68910+ sysctl option is enabled, a sysctl option with name
68911+ "chroot_deny_sysctl" is created.
68912+
68913+config GRKERNSEC_CHROOT_CAPS
68914+ bool "Capability restrictions"
68915+ default y if GRKERNSEC_CONFIG_AUTO
68916+ depends on GRKERNSEC_CHROOT
68917+ help
68918+ If you say Y here, the capabilities on all processes within a
68919+ chroot jail will be lowered to stop module insertion, raw i/o,
68920+ system and net admin tasks, rebooting the system, modifying immutable
68921+ files, modifying IPC owned by another, and changing the system time.
68922+ This is left an option because it can break some apps. Disable this
68923+ if your chrooted apps are having problems performing those kinds of
68924+ tasks. If the sysctl option is enabled, a sysctl option with
68925+ name "chroot_caps" is created.
68926+
68927+config GRKERNSEC_CHROOT_INITRD
68928+ bool "Exempt initrd tasks from restrictions"
68929+ default y if GRKERNSEC_CONFIG_AUTO
68930+ depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
68931+ help
68932+ If you say Y here, tasks started prior to init will be exempted from
68933+ grsecurity's chroot restrictions. This option is mainly meant to
68934+ resolve Plymouth's performing privileged operations unnecessarily
68935+ in a chroot.
68936+
68937+endmenu
68938+menu "Kernel Auditing"
68939+depends on GRKERNSEC
68940+
68941+config GRKERNSEC_AUDIT_GROUP
68942+ bool "Single group for auditing"
68943+ help
68944+ If you say Y here, the exec and chdir logging features will only operate
68945+ on a group you specify. This option is recommended if you only want to
68946+ watch certain users instead of having a large amount of logs from the
68947+ entire system. If the sysctl option is enabled, a sysctl option with
68948+ name "audit_group" is created.
68949+
68950+config GRKERNSEC_AUDIT_GID
68951+ int "GID for auditing"
68952+ depends on GRKERNSEC_AUDIT_GROUP
68953+ default 1007
68954+
68955+config GRKERNSEC_EXECLOG
68956+ bool "Exec logging"
68957+ help
68958+ If you say Y here, all execve() calls will be logged (since the
68959+ other exec*() calls are frontends to execve(), all execution
68960+ will be logged). Useful for shell-servers that like to keep track
68961+ of their users. If the sysctl option is enabled, a sysctl option with
68962+ name "exec_logging" is created.
68963+ WARNING: This option when enabled will produce a LOT of logs, especially
68964+ on an active system.
68965+
68966+config GRKERNSEC_RESLOG
68967+ bool "Resource logging"
68968+ default y if GRKERNSEC_CONFIG_AUTO
68969+ help
68970+ If you say Y here, all attempts to overstep resource limits will
68971+ be logged with the resource name, the requested size, and the current
68972+ limit. It is highly recommended that you say Y here. If the sysctl
68973+ option is enabled, a sysctl option with name "resource_logging" is
68974+ created. If the RBAC system is enabled, the sysctl value is ignored.
68975+
68976+config GRKERNSEC_CHROOT_EXECLOG
68977+ bool "Log execs within chroot"
68978+ help
68979+ If you say Y here, all executions inside a chroot jail will be logged
68980+ to syslog. This can cause a large amount of logs if certain
68981+ applications (eg. djb's daemontools) are installed on the system, and
68982+ is therefore left as an option. If the sysctl option is enabled, a
68983+ sysctl option with name "chroot_execlog" is created.
68984+
68985+config GRKERNSEC_AUDIT_PTRACE
68986+ bool "Ptrace logging"
68987+ help
68988+ If you say Y here, all attempts to attach to a process via ptrace
68989+ will be logged. If the sysctl option is enabled, a sysctl option
68990+ with name "audit_ptrace" is created.
68991+
68992+config GRKERNSEC_AUDIT_CHDIR
68993+ bool "Chdir logging"
68994+ help
68995+ If you say Y here, all chdir() calls will be logged. If the sysctl
68996+ option is enabled, a sysctl option with name "audit_chdir" is created.
68997+
68998+config GRKERNSEC_AUDIT_MOUNT
68999+ bool "(Un)Mount logging"
69000+ help
69001+ If you say Y here, all mounts and unmounts will be logged. If the
69002+ sysctl option is enabled, a sysctl option with name "audit_mount" is
69003+ created.
69004+
69005+config GRKERNSEC_SIGNAL
69006+ bool "Signal logging"
69007+ default y if GRKERNSEC_CONFIG_AUTO
69008+ help
69009+ If you say Y here, certain important signals will be logged, such as
69010+ SIGSEGV, which will as a result inform you of when a error in a program
69011+ occurred, which in some cases could mean a possible exploit attempt.
69012+ If the sysctl option is enabled, a sysctl option with name
69013+ "signal_logging" is created.
69014+
69015+config GRKERNSEC_FORKFAIL
69016+ bool "Fork failure logging"
69017+ help
69018+ If you say Y here, all failed fork() attempts will be logged.
69019+ This could suggest a fork bomb, or someone attempting to overstep
69020+ their process limit. If the sysctl option is enabled, a sysctl option
69021+ with name "forkfail_logging" is created.
69022+
69023+config GRKERNSEC_TIME
69024+ bool "Time change logging"
69025+ default y if GRKERNSEC_CONFIG_AUTO
69026+ help
69027+ If you say Y here, any changes of the system clock will be logged.
69028+ If the sysctl option is enabled, a sysctl option with name
69029+ "timechange_logging" is created.
69030+
69031+config GRKERNSEC_PROC_IPADDR
69032+ bool "/proc/<pid>/ipaddr support"
69033+ default y if GRKERNSEC_CONFIG_AUTO
69034+ help
69035+ If you say Y here, a new entry will be added to each /proc/<pid>
69036+ directory that contains the IP address of the person using the task.
69037+ The IP is carried across local TCP and AF_UNIX stream sockets.
69038+ This information can be useful for IDS/IPSes to perform remote response
69039+ to a local attack. The entry is readable by only the owner of the
69040+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
69041+ the RBAC system), and thus does not create privacy concerns.
69042+
69043+config GRKERNSEC_RWXMAP_LOG
69044+ bool 'Denied RWX mmap/mprotect logging'
69045+ default y if GRKERNSEC_CONFIG_AUTO
69046+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
69047+ help
69048+ If you say Y here, calls to mmap() and mprotect() with explicit
69049+ usage of PROT_WRITE and PROT_EXEC together will be logged when
69050+ denied by the PAX_MPROTECT feature. This feature will also
69051+ log other problematic scenarios that can occur when PAX_MPROTECT
69052+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
69053+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
69054+ is created.
69055+
69056+endmenu
69057+
69058+menu "Executable Protections"
69059+depends on GRKERNSEC
69060+
69061+config GRKERNSEC_DMESG
69062+ bool "Dmesg(8) restriction"
69063+ default y if GRKERNSEC_CONFIG_AUTO
69064+ help
69065+ If you say Y here, non-root users will not be able to use dmesg(8)
69066+ to view the contents of the kernel's circular log buffer.
69067+ The kernel's log buffer often contains kernel addresses and other
69068+ identifying information useful to an attacker in fingerprinting a
69069+ system for a targeted exploit.
69070+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
69071+ created.
69072+
69073+config GRKERNSEC_HARDEN_PTRACE
69074+ bool "Deter ptrace-based process snooping"
69075+ default y if GRKERNSEC_CONFIG_AUTO
69076+ help
69077+ If you say Y here, TTY sniffers and other malicious monitoring
69078+ programs implemented through ptrace will be defeated. If you
69079+ have been using the RBAC system, this option has already been
69080+ enabled for several years for all users, with the ability to make
69081+ fine-grained exceptions.
69082+
69083+ This option only affects the ability of non-root users to ptrace
69084+ processes that are not a descendent of the ptracing process.
69085+ This means that strace ./binary and gdb ./binary will still work,
69086+ but attaching to arbitrary processes will not. If the sysctl
69087+ option is enabled, a sysctl option with name "harden_ptrace" is
69088+ created.
69089+
69090+config GRKERNSEC_PTRACE_READEXEC
69091+ bool "Require read access to ptrace sensitive binaries"
69092+ default y if GRKERNSEC_CONFIG_AUTO
69093+ help
69094+ If you say Y here, unprivileged users will not be able to ptrace unreadable
69095+ binaries. This option is useful in environments that
69096+ remove the read bits (e.g. file mode 4711) from suid binaries to
69097+ prevent infoleaking of their contents. This option adds
69098+ consistency to the use of that file mode, as the binary could normally
69099+ be read out when run without privileges while ptracing.
69100+
69101+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
69102+ is created.
69103+
69104+config GRKERNSEC_SETXID
69105+ bool "Enforce consistent multithreaded privileges"
69106+ default y if GRKERNSEC_CONFIG_AUTO
69107+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
69108+ help
69109+ If you say Y here, a change from a root uid to a non-root uid
69110+ in a multithreaded application will cause the resulting uids,
69111+ gids, supplementary groups, and capabilities in that thread
69112+ to be propagated to the other threads of the process. In most
69113+ cases this is unnecessary, as glibc will emulate this behavior
69114+ on behalf of the application. Other libcs do not act in the
69115+ same way, allowing the other threads of the process to continue
69116+ running with root privileges. If the sysctl option is enabled,
69117+ a sysctl option with name "consistent_setxid" is created.
69118+
69119+config GRKERNSEC_HARDEN_IPC
69120+ bool "Disallow access to overly-permissive IPC objects"
69121+ default y if GRKERNSEC_CONFIG_AUTO
69122+ depends on SYSVIPC
69123+ help
69124+ If you say Y here, access to overly-permissive IPC objects (shared
69125+ memory, message queues, and semaphores) will be denied for processes
69126+ given the following criteria beyond normal permission checks:
69127+ 1) If the IPC object is world-accessible and the euid doesn't match
69128+ that of the creator or current uid for the IPC object
69129+ 2) If the IPC object is group-accessible and the egid doesn't
69130+ match that of the creator or current gid for the IPC object
69131+ It's a common error to grant too much permission to these objects,
69132+ with impact ranging from denial of service and information leaking to
69133+ privilege escalation. This feature was developed in response to
69134+ research by Tim Brown:
69135+ http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
69136+ who found hundreds of such insecure usages. Processes with
69137+ CAP_IPC_OWNER are still permitted to access these IPC objects.
69138+ If the sysctl option is enabled, a sysctl option with name
69139+ "harden_ipc" is created.
69140+
69141+config GRKERNSEC_TPE
69142+ bool "Trusted Path Execution (TPE)"
69143+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
69144+ help
69145+ If you say Y here, you will be able to choose a gid to add to the
69146+ supplementary groups of users you want to mark as "untrusted."
69147+ These users will not be able to execute any files that are not in
69148+ root-owned directories writable only by root. If the sysctl option
69149+ is enabled, a sysctl option with name "tpe" is created.
69150+
69151+config GRKERNSEC_TPE_ALL
69152+ bool "Partially restrict all non-root users"
69153+ depends on GRKERNSEC_TPE
69154+ help
69155+ If you say Y here, all non-root users will be covered under
69156+ a weaker TPE restriction. This is separate from, and in addition to,
69157+ the main TPE options that you have selected elsewhere. Thus, if a
69158+ "trusted" GID is chosen, this restriction applies to even that GID.
69159+ Under this restriction, all non-root users will only be allowed to
69160+ execute files in directories they own that are not group or
69161+ world-writable, or in directories owned by root and writable only by
69162+ root. If the sysctl option is enabled, a sysctl option with name
69163+ "tpe_restrict_all" is created.
69164+
69165+config GRKERNSEC_TPE_INVERT
69166+ bool "Invert GID option"
69167+ depends on GRKERNSEC_TPE
69168+ help
69169+ If you say Y here, the group you specify in the TPE configuration will
69170+ decide what group TPE restrictions will be *disabled* for. This
69171+ option is useful if you want TPE restrictions to be applied to most
69172+ users on the system. If the sysctl option is enabled, a sysctl option
69173+ with name "tpe_invert" is created. Unlike other sysctl options, this
69174+ entry will default to on for backward-compatibility.
69175+
69176+config GRKERNSEC_TPE_GID
69177+ int
69178+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
69179+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
69180+
69181+config GRKERNSEC_TPE_UNTRUSTED_GID
69182+ int "GID for TPE-untrusted users"
69183+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
69184+ default 1005
69185+ help
69186+ Setting this GID determines what group TPE restrictions will be
69187+ *enabled* for. If the sysctl option is enabled, a sysctl option
69188+ with name "tpe_gid" is created.
69189+
69190+config GRKERNSEC_TPE_TRUSTED_GID
69191+ int "GID for TPE-trusted users"
69192+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
69193+ default 1005
69194+ help
69195+ Setting this GID determines what group TPE restrictions will be
69196+ *disabled* for. If the sysctl option is enabled, a sysctl option
69197+ with name "tpe_gid" is created.
69198+
69199+endmenu
69200+menu "Network Protections"
69201+depends on GRKERNSEC
69202+
69203+config GRKERNSEC_BLACKHOLE
69204+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
69205+ default y if GRKERNSEC_CONFIG_AUTO
69206+ depends on NET
69207+ help
69208+ If you say Y here, neither TCP resets nor ICMP
69209+ destination-unreachable packets will be sent in response to packets
69210+ sent to ports for which no associated listening process exists.
69211+ It will also prevent the sending of ICMP protocol unreachable packets
69212+ in response to packets with unknown protocols.
69213+ This feature supports both IPV4 and IPV6 and exempts the
69214+ loopback interface from blackholing. Enabling this feature
69215+ makes a host more resilient to DoS attacks and reduces network
69216+ visibility against scanners.
69217+
69218+ The blackhole feature as-implemented is equivalent to the FreeBSD
69219+ blackhole feature, as it prevents RST responses to all packets, not
69220+ just SYNs. Under most application behavior this causes no
69221+ problems, but applications (like haproxy) may not close certain
69222+ connections in a way that cleanly terminates them on the remote
69223+ end, leaving the remote host in LAST_ACK state. Because of this
69224+ side-effect and to prevent intentional LAST_ACK DoSes, this
69225+ feature also adds automatic mitigation against such attacks.
69226+ The mitigation drastically reduces the amount of time a socket
69227+ can spend in LAST_ACK state. If you're using haproxy and not
69228+ all servers it connects to have this option enabled, consider
69229+ disabling this feature on the haproxy host.
69230+
69231+ If the sysctl option is enabled, two sysctl options with names
69232+ "ip_blackhole" and "lastack_retries" will be created.
69233+ While "ip_blackhole" takes the standard zero/non-zero on/off
69234+ toggle, "lastack_retries" uses the same kinds of values as
69235+ "tcp_retries1" and "tcp_retries2". The default value of 4
69236+ prevents a socket from lasting more than 45 seconds in LAST_ACK
69237+ state.
69238+
69239+config GRKERNSEC_NO_SIMULT_CONNECT
69240+ bool "Disable TCP Simultaneous Connect"
69241+ default y if GRKERNSEC_CONFIG_AUTO
69242+ depends on NET
69243+ help
69244+ If you say Y here, a feature by Willy Tarreau will be enabled that
69245+ removes a weakness in Linux's strict implementation of TCP that
69246+ allows two clients to connect to each other without either entering
69247+ a listening state. The weakness allows an attacker to easily prevent
69248+ a client from connecting to a known server provided the source port
69249+ for the connection is guessed correctly.
69250+
69251+ As the weakness could be used to prevent an antivirus or IPS from
69252+ fetching updates, or prevent an SSL gateway from fetching a CRL,
69253+ it should be eliminated by enabling this option. Though Linux is
69254+ one of few operating systems supporting simultaneous connect, it
69255+ has no legitimate use in practice and is rarely supported by firewalls.
69256+
69257+config GRKERNSEC_SOCKET
69258+ bool "Socket restrictions"
69259+ depends on NET
69260+ help
69261+ If you say Y here, you will be able to choose from several options.
69262+ If you assign a GID on your system and add it to the supplementary
69263+ groups of users you want to restrict socket access to, this patch
69264+ will perform up to three things, based on the option(s) you choose.
69265+
69266+config GRKERNSEC_SOCKET_ALL
69267+ bool "Deny any sockets to group"
69268+ depends on GRKERNSEC_SOCKET
69269+ help
69270+ If you say Y here, you will be able to choose a GID of whose users will
69271+ be unable to connect to other hosts from your machine or run server
69272+ applications from your machine. If the sysctl option is enabled, a
69273+ sysctl option with name "socket_all" is created.
69274+
69275+config GRKERNSEC_SOCKET_ALL_GID
69276+ int "GID to deny all sockets for"
69277+ depends on GRKERNSEC_SOCKET_ALL
69278+ default 1004
69279+ help
69280+ Here you can choose the GID to disable socket access for. Remember to
69281+ add the users you want socket access disabled for to the GID
69282+ specified here. If the sysctl option is enabled, a sysctl option
69283+ with name "socket_all_gid" is created.
69284+
69285+config GRKERNSEC_SOCKET_CLIENT
69286+ bool "Deny client sockets to group"
69287+ depends on GRKERNSEC_SOCKET
69288+ help
69289+ If you say Y here, you will be able to choose a GID of whose users will
69290+ be unable to connect to other hosts from your machine, but will be
69291+ able to run servers. If this option is enabled, all users in the group
69292+ you specify will have to use passive mode when initiating ftp transfers
69293+ from the shell on your machine. If the sysctl option is enabled, a
69294+ sysctl option with name "socket_client" is created.
69295+
69296+config GRKERNSEC_SOCKET_CLIENT_GID
69297+ int "GID to deny client sockets for"
69298+ depends on GRKERNSEC_SOCKET_CLIENT
69299+ default 1003
69300+ help
69301+ Here you can choose the GID to disable client socket access for.
69302+ Remember to add the users you want client socket access disabled for to
69303+ the GID specified here. If the sysctl option is enabled, a sysctl
69304+ option with name "socket_client_gid" is created.
69305+
69306+config GRKERNSEC_SOCKET_SERVER
69307+ bool "Deny server sockets to group"
69308+ depends on GRKERNSEC_SOCKET
69309+ help
69310+ If you say Y here, you will be able to choose a GID of whose users will
69311+ be unable to run server applications from your machine. If the sysctl
69312+ option is enabled, a sysctl option with name "socket_server" is created.
69313+
69314+config GRKERNSEC_SOCKET_SERVER_GID
69315+ int "GID to deny server sockets for"
69316+ depends on GRKERNSEC_SOCKET_SERVER
69317+ default 1002
69318+ help
69319+ Here you can choose the GID to disable server socket access for.
69320+ Remember to add the users you want server socket access disabled for to
69321+ the GID specified here. If the sysctl option is enabled, a sysctl
69322+ option with name "socket_server_gid" is created.
69323+
69324+endmenu
69325+
69326+menu "Physical Protections"
69327+depends on GRKERNSEC
69328+
69329+config GRKERNSEC_DENYUSB
69330+ bool "Deny new USB connections after toggle"
69331+ default y if GRKERNSEC_CONFIG_AUTO
69332+ depends on SYSCTL && USB_SUPPORT
69333+ help
69334+ If you say Y here, a new sysctl option with name "deny_new_usb"
69335+ will be created. Setting its value to 1 will prevent any new
69336+ USB devices from being recognized by the OS. Any attempted USB
69337+ device insertion will be logged. This option is intended to be
69338+ used against custom USB devices designed to exploit vulnerabilities
69339+ in various USB device drivers.
69340+
69341+ For greatest effectiveness, this sysctl should be set after any
69342+ relevant init scripts. This option is safe to enable in distros
69343+ as each user can choose whether or not to toggle the sysctl.
69344+
69345+config GRKERNSEC_DENYUSB_FORCE
69346+ bool "Reject all USB devices not connected at boot"
69347+ select USB
69348+ depends on GRKERNSEC_DENYUSB
69349+ help
69350+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
69351+ that doesn't involve a sysctl entry. This option should only be
69352+ enabled if you're sure you want to deny all new USB connections
69353+ at runtime and don't want to modify init scripts. This should not
69354+ be enabled by distros. It forces the core USB code to be built
69355+ into the kernel image so that all devices connected at boot time
69356+ can be recognized and new USB device connections can be prevented
69357+ prior to init running.
69358+
69359+endmenu
69360+
69361+menu "Sysctl Support"
69362+depends on GRKERNSEC && SYSCTL
69363+
69364+config GRKERNSEC_SYSCTL
69365+ bool "Sysctl support"
69366+ default y if GRKERNSEC_CONFIG_AUTO
69367+ help
69368+ If you say Y here, you will be able to change the options that
69369+ grsecurity runs with at bootup, without having to recompile your
69370+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
69371+ to enable (1) or disable (0) various features. All the sysctl entries
69372+ are mutable until the "grsec_lock" entry is set to a non-zero value.
69373+ All features enabled in the kernel configuration are disabled at boot
69374+ if you do not say Y to the "Turn on features by default" option.
69375+ All options should be set at startup, and the grsec_lock entry should
69376+ be set to a non-zero value after all the options are set.
69377+ *THIS IS EXTREMELY IMPORTANT*
69378+
69379+config GRKERNSEC_SYSCTL_DISTRO
69380+ bool "Extra sysctl support for distro makers (READ HELP)"
69381+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
69382+ help
69383+ If you say Y here, additional sysctl options will be created
69384+ for features that affect processes running as root. Therefore,
69385+ it is critical when using this option that the grsec_lock entry be
69386+ enabled after boot. Only distros with prebuilt kernel packages
69387+ with this option enabled that can ensure grsec_lock is enabled
69388+ after boot should use this option.
69389+ *Failure to set grsec_lock after boot makes all grsec features
69390+ this option covers useless*
69391+
69392+ Currently this option creates the following sysctl entries:
69393+ "Disable Privileged I/O": "disable_priv_io"
69394+
69395+config GRKERNSEC_SYSCTL_ON
69396+ bool "Turn on features by default"
69397+ default y if GRKERNSEC_CONFIG_AUTO
69398+ depends on GRKERNSEC_SYSCTL
69399+ help
69400+ If you say Y here, instead of having all features enabled in the
69401+ kernel configuration disabled at boot time, the features will be
69402+ enabled at boot time. It is recommended you say Y here unless
69403+ there is some reason you would want all sysctl-tunable features to
69404+ be disabled by default. As mentioned elsewhere, it is important
69405+ to enable the grsec_lock entry once you have finished modifying
69406+ the sysctl entries.
69407+
69408+endmenu
69409+menu "Logging Options"
69410+depends on GRKERNSEC
69411+
69412+config GRKERNSEC_FLOODTIME
69413+ int "Seconds in between log messages (minimum)"
69414+ default 10
69415+ help
69416+ This option allows you to enforce the number of seconds between
69417+ grsecurity log messages. The default should be suitable for most
69418+ people, however, if you choose to change it, choose a value small enough
69419+ to allow informative logs to be produced, but large enough to
69420+ prevent flooding.
69421+
69422+ Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
69423+ any rate limiting on grsecurity log messages.
69424+
69425+config GRKERNSEC_FLOODBURST
69426+ int "Number of messages in a burst (maximum)"
69427+ default 6
69428+ help
69429+ This option allows you to choose the maximum number of messages allowed
69430+ within the flood time interval you chose in a separate option. The
69431+ default should be suitable for most people, however if you find that
69432+ many of your logs are being interpreted as flooding, you may want to
69433+ raise this value.
69434+
69435+ Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
69436+ any rate limiting on grsecurity log messages.
69437+
69438+endmenu
69439diff --git a/grsecurity/Makefile b/grsecurity/Makefile
69440new file mode 100644
69441index 0000000..30ababb
69442--- /dev/null
69443+++ b/grsecurity/Makefile
69444@@ -0,0 +1,54 @@
69445+# grsecurity – access control and security hardening for Linux
69446+# All code in this directory and various hooks located throughout the Linux kernel are
69447+# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
69448+# http://www.grsecurity.net spender@grsecurity.net
69449+#
69450+# This program is free software; you can redistribute it and/or
69451+# modify it under the terms of the GNU General Public License version 2
69452+# as published by the Free Software Foundation.
69453+#
69454+# This program is distributed in the hope that it will be useful,
69455+# but WITHOUT ANY WARRANTY; without even the implied warranty of
69456+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69457+# GNU General Public License for more details.
69458+#
69459+# You should have received a copy of the GNU General Public License
69460+# along with this program; if not, write to the Free Software
69461+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
69462+
69463+KBUILD_CFLAGS += -Werror
69464+
69465+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
69466+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
69467+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
69468+ grsec_usb.o grsec_ipc.o grsec_proc.o
69469+
69470+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
69471+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
69472+ gracl_learn.o grsec_log.o gracl_policy.o
69473+ifdef CONFIG_COMPAT
69474+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
69475+endif
69476+
69477+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
69478+
69479+ifdef CONFIG_NET
69480+obj-y += grsec_sock.o
69481+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
69482+endif
69483+
69484+ifndef CONFIG_GRKERNSEC
69485+obj-y += grsec_disabled.o
69486+endif
69487+
69488+ifdef CONFIG_GRKERNSEC_HIDESYM
69489+extra-y := grsec_hidesym.o
69490+$(obj)/grsec_hidesym.o:
69491+ @-chmod -f 500 /boot
69492+ @-chmod -f 500 /lib/modules
69493+ @-chmod -f 500 /lib64/modules
69494+ @-chmod -f 500 /lib32/modules
69495+ @-chmod -f 700 .
69496+ @-chmod -f 700 $(objtree)
69497+ @echo ' grsec: protected kernel image paths'
69498+endif
69499diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
69500new file mode 100644
69501index 0000000..6ae3aa0
69502--- /dev/null
69503+++ b/grsecurity/gracl.c
69504@@ -0,0 +1,2703 @@
69505+#include <linux/kernel.h>
69506+#include <linux/module.h>
69507+#include <linux/sched.h>
69508+#include <linux/mm.h>
69509+#include <linux/file.h>
69510+#include <linux/fs.h>
69511+#include <linux/namei.h>
69512+#include <linux/mount.h>
69513+#include <linux/tty.h>
69514+#include <linux/proc_fs.h>
69515+#include <linux/lglock.h>
69516+#include <linux/slab.h>
69517+#include <linux/vmalloc.h>
69518+#include <linux/types.h>
69519+#include <linux/sysctl.h>
69520+#include <linux/netdevice.h>
69521+#include <linux/ptrace.h>
69522+#include <linux/gracl.h>
69523+#include <linux/gralloc.h>
69524+#include <linux/security.h>
69525+#include <linux/grinternal.h>
69526+#include <linux/pid_namespace.h>
69527+#include <linux/stop_machine.h>
69528+#include <linux/fdtable.h>
69529+#include <linux/percpu.h>
69530+#include <linux/lglock.h>
69531+#include <linux/hugetlb.h>
69532+#include <linux/posix-timers.h>
69533+#include <linux/prefetch.h>
69534+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69535+#include <linux/magic.h>
69536+#include <linux/pagemap.h>
69537+#include "../fs/btrfs/async-thread.h"
69538+#include "../fs/btrfs/ctree.h"
69539+#include "../fs/btrfs/btrfs_inode.h"
69540+#endif
69541+#include "../fs/mount.h"
69542+
69543+#include <asm/uaccess.h>
69544+#include <asm/errno.h>
69545+#include <asm/mman.h>
69546+
69547+#define FOR_EACH_ROLE_START(role) \
69548+ role = running_polstate.role_list; \
69549+ while (role) {
69550+
69551+#define FOR_EACH_ROLE_END(role) \
69552+ role = role->prev; \
69553+ }
69554+
69555+extern struct path gr_real_root;
69556+
69557+static struct gr_policy_state running_polstate;
69558+struct gr_policy_state *polstate = &running_polstate;
69559+extern struct gr_alloc_state *current_alloc_state;
69560+
69561+extern char *gr_shared_page[4];
69562+DEFINE_RWLOCK(gr_inode_lock);
69563+
69564+static unsigned int gr_status __read_only = GR_STATUS_INIT;
69565+
69566+#ifdef CONFIG_NET
69567+extern struct vfsmount *sock_mnt;
69568+#endif
69569+
69570+extern struct vfsmount *pipe_mnt;
69571+extern struct vfsmount *shm_mnt;
69572+
69573+#ifdef CONFIG_HUGETLBFS
69574+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
69575+#endif
69576+
69577+extern u16 acl_sp_role_value;
69578+extern struct acl_object_label *fakefs_obj_rw;
69579+extern struct acl_object_label *fakefs_obj_rwx;
69580+
69581+int gr_acl_is_enabled(void)
69582+{
69583+ return (gr_status & GR_READY);
69584+}
69585+
69586+void gr_enable_rbac_system(void)
69587+{
69588+ pax_open_kernel();
69589+ gr_status |= GR_READY;
69590+ pax_close_kernel();
69591+}
69592+
69593+int gr_rbac_disable(void *unused)
69594+{
69595+ pax_open_kernel();
69596+ gr_status &= ~GR_READY;
69597+ pax_close_kernel();
69598+
69599+ return 0;
69600+}
69601+
69602+static inline dev_t __get_dev(const struct dentry *dentry)
69603+{
69604+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69605+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
69606+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
69607+ else
69608+#endif
69609+ return dentry->d_sb->s_dev;
69610+}
69611+
69612+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
69613+{
69614+ return __get_dev(dentry);
69615+}
69616+
69617+static char gr_task_roletype_to_char(struct task_struct *task)
69618+{
69619+ switch (task->role->roletype &
69620+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
69621+ GR_ROLE_SPECIAL)) {
69622+ case GR_ROLE_DEFAULT:
69623+ return 'D';
69624+ case GR_ROLE_USER:
69625+ return 'U';
69626+ case GR_ROLE_GROUP:
69627+ return 'G';
69628+ case GR_ROLE_SPECIAL:
69629+ return 'S';
69630+ }
69631+
69632+ return 'X';
69633+}
69634+
69635+char gr_roletype_to_char(void)
69636+{
69637+ return gr_task_roletype_to_char(current);
69638+}
69639+
69640+__inline__ int
69641+gr_acl_tpe_check(void)
69642+{
69643+ if (unlikely(!(gr_status & GR_READY)))
69644+ return 0;
69645+ if (current->role->roletype & GR_ROLE_TPE)
69646+ return 1;
69647+ else
69648+ return 0;
69649+}
69650+
69651+int
69652+gr_handle_rawio(const struct inode *inode)
69653+{
69654+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69655+ if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
69656+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
69657+ !capable(CAP_SYS_RAWIO))
69658+ return 1;
69659+#endif
69660+ return 0;
69661+}
69662+
69663+int
69664+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
69665+{
69666+ if (likely(lena != lenb))
69667+ return 0;
69668+
69669+ return !memcmp(a, b, lena);
69670+}
69671+
69672+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
69673+{
69674+ *buflen -= namelen;
69675+ if (*buflen < 0)
69676+ return -ENAMETOOLONG;
69677+ *buffer -= namelen;
69678+ memcpy(*buffer, str, namelen);
69679+ return 0;
69680+}
69681+
69682+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
69683+{
69684+ return prepend(buffer, buflen, name->name, name->len);
69685+}
69686+
69687+static int prepend_path(const struct path *path, struct path *root,
69688+ char **buffer, int *buflen)
69689+{
69690+ struct dentry *dentry = path->dentry;
69691+ struct vfsmount *vfsmnt = path->mnt;
69692+ struct mount *mnt = real_mount(vfsmnt);
69693+ bool slash = false;
69694+ int error = 0;
69695+
69696+ while (dentry != root->dentry || vfsmnt != root->mnt) {
69697+ struct dentry * parent;
69698+
69699+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
69700+ /* Global root? */
69701+ if (!mnt_has_parent(mnt)) {
69702+ goto out;
69703+ }
69704+ dentry = mnt->mnt_mountpoint;
69705+ mnt = mnt->mnt_parent;
69706+ vfsmnt = &mnt->mnt;
69707+ continue;
69708+ }
69709+ parent = dentry->d_parent;
69710+ prefetch(parent);
69711+ spin_lock(&dentry->d_lock);
69712+ error = prepend_name(buffer, buflen, &dentry->d_name);
69713+ spin_unlock(&dentry->d_lock);
69714+ if (!error)
69715+ error = prepend(buffer, buflen, "/", 1);
69716+ if (error)
69717+ break;
69718+
69719+ slash = true;
69720+ dentry = parent;
69721+ }
69722+
69723+out:
69724+ if (!error && !slash)
69725+ error = prepend(buffer, buflen, "/", 1);
69726+
69727+ return error;
69728+}
69729+
69730+/* this must be called with mount_lock and rename_lock held */
69731+
69732+static char *__our_d_path(const struct path *path, struct path *root,
69733+ char *buf, int buflen)
69734+{
69735+ char *res = buf + buflen;
69736+ int error;
69737+
69738+ prepend(&res, &buflen, "\0", 1);
69739+ error = prepend_path(path, root, &res, &buflen);
69740+ if (error)
69741+ return ERR_PTR(error);
69742+
69743+ return res;
69744+}
69745+
69746+static char *
69747+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
69748+{
69749+ char *retval;
69750+
69751+ retval = __our_d_path(path, root, buf, buflen);
69752+ if (unlikely(IS_ERR(retval)))
69753+ retval = strcpy(buf, "<path too long>");
69754+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
69755+ retval[1] = '\0';
69756+
69757+ return retval;
69758+}
69759+
69760+static char *
69761+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
69762+ char *buf, int buflen)
69763+{
69764+ struct path path;
69765+ char *res;
69766+
69767+ path.dentry = (struct dentry *)dentry;
69768+ path.mnt = (struct vfsmount *)vfsmnt;
69769+
69770+ /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
69771+ by the RBAC system */
69772+ res = gen_full_path(&path, &gr_real_root, buf, buflen);
69773+
69774+ return res;
69775+}
69776+
69777+static char *
69778+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
69779+ char *buf, int buflen)
69780+{
69781+ char *res;
69782+ struct path path;
69783+ struct path root;
69784+ struct task_struct *reaper = init_pid_ns.child_reaper;
69785+
69786+ path.dentry = (struct dentry *)dentry;
69787+ path.mnt = (struct vfsmount *)vfsmnt;
69788+
69789+ /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
69790+ get_fs_root(reaper->fs, &root);
69791+
69792+ read_seqlock_excl(&mount_lock);
69793+ write_seqlock(&rename_lock);
69794+ res = gen_full_path(&path, &root, buf, buflen);
69795+ write_sequnlock(&rename_lock);
69796+ read_sequnlock_excl(&mount_lock);
69797+
69798+ path_put(&root);
69799+ return res;
69800+}
69801+
69802+char *
69803+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
69804+{
69805+ char *ret;
69806+ read_seqlock_excl(&mount_lock);
69807+ write_seqlock(&rename_lock);
69808+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
69809+ PAGE_SIZE);
69810+ write_sequnlock(&rename_lock);
69811+ read_sequnlock_excl(&mount_lock);
69812+ return ret;
69813+}
69814+
69815+static char *
69816+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
69817+{
69818+ char *ret;
69819+ char *buf;
69820+ int buflen;
69821+
69822+ read_seqlock_excl(&mount_lock);
69823+ write_seqlock(&rename_lock);
69824+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
69825+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
69826+ buflen = (int)(ret - buf);
69827+ if (buflen >= 5)
69828+ prepend(&ret, &buflen, "/proc", 5);
69829+ else
69830+ ret = strcpy(buf, "<path too long>");
69831+ write_sequnlock(&rename_lock);
69832+ read_sequnlock_excl(&mount_lock);
69833+ return ret;
69834+}
69835+
69836+char *
69837+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
69838+{
69839+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
69840+ PAGE_SIZE);
69841+}
69842+
69843+char *
69844+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
69845+{
69846+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69847+ PAGE_SIZE);
69848+}
69849+
69850+char *
69851+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
69852+{
69853+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
69854+ PAGE_SIZE);
69855+}
69856+
69857+char *
69858+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
69859+{
69860+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
69861+ PAGE_SIZE);
69862+}
69863+
69864+char *
69865+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
69866+{
69867+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
69868+ PAGE_SIZE);
69869+}
69870+
69871+__inline__ __u32
69872+to_gr_audit(const __u32 reqmode)
69873+{
69874+ /* masks off auditable permission flags, then shifts them to create
69875+ auditing flags, and adds the special case of append auditing if
69876+ we're requesting write */
69877+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
69878+}
69879+
69880+struct acl_role_label *
69881+__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
69882+ const gid_t gid)
69883+{
69884+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
69885+ struct acl_role_label *match;
69886+ struct role_allowed_ip *ipp;
69887+ unsigned int x;
69888+ u32 curr_ip = task->signal->saved_ip;
69889+
69890+ match = state->acl_role_set.r_hash[index];
69891+
69892+ while (match) {
69893+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
69894+ for (x = 0; x < match->domain_child_num; x++) {
69895+ if (match->domain_children[x] == uid)
69896+ goto found;
69897+ }
69898+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
69899+ break;
69900+ match = match->next;
69901+ }
69902+found:
69903+ if (match == NULL) {
69904+ try_group:
69905+ index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
69906+ match = state->acl_role_set.r_hash[index];
69907+
69908+ while (match) {
69909+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
69910+ for (x = 0; x < match->domain_child_num; x++) {
69911+ if (match->domain_children[x] == gid)
69912+ goto found2;
69913+ }
69914+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
69915+ break;
69916+ match = match->next;
69917+ }
69918+found2:
69919+ if (match == NULL)
69920+ match = state->default_role;
69921+ if (match->allowed_ips == NULL)
69922+ return match;
69923+ else {
69924+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
69925+ if (likely
69926+ ((ntohl(curr_ip) & ipp->netmask) ==
69927+ (ntohl(ipp->addr) & ipp->netmask)))
69928+ return match;
69929+ }
69930+ match = state->default_role;
69931+ }
69932+ } else if (match->allowed_ips == NULL) {
69933+ return match;
69934+ } else {
69935+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
69936+ if (likely
69937+ ((ntohl(curr_ip) & ipp->netmask) ==
69938+ (ntohl(ipp->addr) & ipp->netmask)))
69939+ return match;
69940+ }
69941+ goto try_group;
69942+ }
69943+
69944+ return match;
69945+}
69946+
69947+static struct acl_role_label *
69948+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
69949+ const gid_t gid)
69950+{
69951+ return __lookup_acl_role_label(&running_polstate, task, uid, gid);
69952+}
69953+
69954+struct acl_subject_label *
69955+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
69956+ const struct acl_role_label *role)
69957+{
69958+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
69959+ struct acl_subject_label *match;
69960+
69961+ match = role->subj_hash[index];
69962+
69963+ while (match && (match->inode != ino || match->device != dev ||
69964+ (match->mode & GR_DELETED))) {
69965+ match = match->next;
69966+ }
69967+
69968+ if (match && !(match->mode & GR_DELETED))
69969+ return match;
69970+ else
69971+ return NULL;
69972+}
69973+
69974+struct acl_subject_label *
69975+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
69976+ const struct acl_role_label *role)
69977+{
69978+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
69979+ struct acl_subject_label *match;
69980+
69981+ match = role->subj_hash[index];
69982+
69983+ while (match && (match->inode != ino || match->device != dev ||
69984+ !(match->mode & GR_DELETED))) {
69985+ match = match->next;
69986+ }
69987+
69988+ if (match && (match->mode & GR_DELETED))
69989+ return match;
69990+ else
69991+ return NULL;
69992+}
69993+
69994+static struct acl_object_label *
69995+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
69996+ const struct acl_subject_label *subj)
69997+{
69998+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
69999+ struct acl_object_label *match;
70000+
70001+ match = subj->obj_hash[index];
70002+
70003+ while (match && (match->inode != ino || match->device != dev ||
70004+ (match->mode & GR_DELETED))) {
70005+ match = match->next;
70006+ }
70007+
70008+ if (match && !(match->mode & GR_DELETED))
70009+ return match;
70010+ else
70011+ return NULL;
70012+}
70013+
70014+static struct acl_object_label *
70015+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
70016+ const struct acl_subject_label *subj)
70017+{
70018+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
70019+ struct acl_object_label *match;
70020+
70021+ match = subj->obj_hash[index];
70022+
70023+ while (match && (match->inode != ino || match->device != dev ||
70024+ !(match->mode & GR_DELETED))) {
70025+ match = match->next;
70026+ }
70027+
70028+ if (match && (match->mode & GR_DELETED))
70029+ return match;
70030+
70031+ match = subj->obj_hash[index];
70032+
70033+ while (match && (match->inode != ino || match->device != dev ||
70034+ (match->mode & GR_DELETED))) {
70035+ match = match->next;
70036+ }
70037+
70038+ if (match && !(match->mode & GR_DELETED))
70039+ return match;
70040+ else
70041+ return NULL;
70042+}
70043+
70044+struct name_entry *
70045+__lookup_name_entry(const struct gr_policy_state *state, const char *name)
70046+{
70047+ unsigned int len = strlen(name);
70048+ unsigned int key = full_name_hash(name, len);
70049+ unsigned int index = key % state->name_set.n_size;
70050+ struct name_entry *match;
70051+
70052+ match = state->name_set.n_hash[index];
70053+
70054+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
70055+ match = match->next;
70056+
70057+ return match;
70058+}
70059+
70060+static struct name_entry *
70061+lookup_name_entry(const char *name)
70062+{
70063+ return __lookup_name_entry(&running_polstate, name);
70064+}
70065+
70066+static struct name_entry *
70067+lookup_name_entry_create(const char *name)
70068+{
70069+ unsigned int len = strlen(name);
70070+ unsigned int key = full_name_hash(name, len);
70071+ unsigned int index = key % running_polstate.name_set.n_size;
70072+ struct name_entry *match;
70073+
70074+ match = running_polstate.name_set.n_hash[index];
70075+
70076+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
70077+ !match->deleted))
70078+ match = match->next;
70079+
70080+ if (match && match->deleted)
70081+ return match;
70082+
70083+ match = running_polstate.name_set.n_hash[index];
70084+
70085+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
70086+ match->deleted))
70087+ match = match->next;
70088+
70089+ if (match && !match->deleted)
70090+ return match;
70091+ else
70092+ return NULL;
70093+}
70094+
70095+static struct inodev_entry *
70096+lookup_inodev_entry(const ino_t ino, const dev_t dev)
70097+{
70098+ unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
70099+ struct inodev_entry *match;
70100+
70101+ match = running_polstate.inodev_set.i_hash[index];
70102+
70103+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
70104+ match = match->next;
70105+
70106+ return match;
70107+}
70108+
70109+void
70110+__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
70111+{
70112+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
70113+ state->inodev_set.i_size);
70114+ struct inodev_entry **curr;
70115+
70116+ entry->prev = NULL;
70117+
70118+ curr = &state->inodev_set.i_hash[index];
70119+ if (*curr != NULL)
70120+ (*curr)->prev = entry;
70121+
70122+ entry->next = *curr;
70123+ *curr = entry;
70124+
70125+ return;
70126+}
70127+
70128+static void
70129+insert_inodev_entry(struct inodev_entry *entry)
70130+{
70131+ __insert_inodev_entry(&running_polstate, entry);
70132+}
70133+
70134+void
70135+insert_acl_obj_label(struct acl_object_label *obj,
70136+ struct acl_subject_label *subj)
70137+{
70138+ unsigned int index =
70139+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
70140+ struct acl_object_label **curr;
70141+
70142+ obj->prev = NULL;
70143+
70144+ curr = &subj->obj_hash[index];
70145+ if (*curr != NULL)
70146+ (*curr)->prev = obj;
70147+
70148+ obj->next = *curr;
70149+ *curr = obj;
70150+
70151+ return;
70152+}
70153+
70154+void
70155+insert_acl_subj_label(struct acl_subject_label *obj,
70156+ struct acl_role_label *role)
70157+{
70158+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
70159+ struct acl_subject_label **curr;
70160+
70161+ obj->prev = NULL;
70162+
70163+ curr = &role->subj_hash[index];
70164+ if (*curr != NULL)
70165+ (*curr)->prev = obj;
70166+
70167+ obj->next = *curr;
70168+ *curr = obj;
70169+
70170+ return;
70171+}
70172+
70173+/* derived from glibc fnmatch() 0: match, 1: no match*/
70174+
70175+static int
70176+glob_match(const char *p, const char *n)
70177+{
70178+ char c;
70179+
70180+ while ((c = *p++) != '\0') {
70181+ switch (c) {
70182+ case '?':
70183+ if (*n == '\0')
70184+ return 1;
70185+ else if (*n == '/')
70186+ return 1;
70187+ break;
70188+ case '\\':
70189+ if (*n != c)
70190+ return 1;
70191+ break;
70192+ case '*':
70193+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
70194+ if (*n == '/')
70195+ return 1;
70196+ else if (c == '?') {
70197+ if (*n == '\0')
70198+ return 1;
70199+ else
70200+ ++n;
70201+ }
70202+ }
70203+ if (c == '\0') {
70204+ return 0;
70205+ } else {
70206+ const char *endp;
70207+
70208+ if ((endp = strchr(n, '/')) == NULL)
70209+ endp = n + strlen(n);
70210+
70211+ if (c == '[') {
70212+ for (--p; n < endp; ++n)
70213+ if (!glob_match(p, n))
70214+ return 0;
70215+ } else if (c == '/') {
70216+ while (*n != '\0' && *n != '/')
70217+ ++n;
70218+ if (*n == '/' && !glob_match(p, n + 1))
70219+ return 0;
70220+ } else {
70221+ for (--p; n < endp; ++n)
70222+ if (*n == c && !glob_match(p, n))
70223+ return 0;
70224+ }
70225+
70226+ return 1;
70227+ }
70228+ case '[':
70229+ {
70230+ int not;
70231+ char cold;
70232+
70233+ if (*n == '\0' || *n == '/')
70234+ return 1;
70235+
70236+ not = (*p == '!' || *p == '^');
70237+ if (not)
70238+ ++p;
70239+
70240+ c = *p++;
70241+ for (;;) {
70242+ unsigned char fn = (unsigned char)*n;
70243+
70244+ if (c == '\0')
70245+ return 1;
70246+ else {
70247+ if (c == fn)
70248+ goto matched;
70249+ cold = c;
70250+ c = *p++;
70251+
70252+ if (c == '-' && *p != ']') {
70253+ unsigned char cend = *p++;
70254+
70255+ if (cend == '\0')
70256+ return 1;
70257+
70258+ if (cold <= fn && fn <= cend)
70259+ goto matched;
70260+
70261+ c = *p++;
70262+ }
70263+ }
70264+
70265+ if (c == ']')
70266+ break;
70267+ }
70268+ if (!not)
70269+ return 1;
70270+ break;
70271+ matched:
70272+ while (c != ']') {
70273+ if (c == '\0')
70274+ return 1;
70275+
70276+ c = *p++;
70277+ }
70278+ if (not)
70279+ return 1;
70280+ }
70281+ break;
70282+ default:
70283+ if (c != *n)
70284+ return 1;
70285+ }
70286+
70287+ ++n;
70288+ }
70289+
70290+ if (*n == '\0')
70291+ return 0;
70292+
70293+ if (*n == '/')
70294+ return 0;
70295+
70296+ return 1;
70297+}
70298+
70299+static struct acl_object_label *
70300+chk_glob_label(struct acl_object_label *globbed,
70301+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
70302+{
70303+ struct acl_object_label *tmp;
70304+
70305+ if (*path == NULL)
70306+ *path = gr_to_filename_nolock(dentry, mnt);
70307+
70308+ tmp = globbed;
70309+
70310+ while (tmp) {
70311+ if (!glob_match(tmp->filename, *path))
70312+ return tmp;
70313+ tmp = tmp->next;
70314+ }
70315+
70316+ return NULL;
70317+}
70318+
70319+static struct acl_object_label *
70320+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
70321+ const ino_t curr_ino, const dev_t curr_dev,
70322+ const struct acl_subject_label *subj, char **path, const int checkglob)
70323+{
70324+ struct acl_subject_label *tmpsubj;
70325+ struct acl_object_label *retval;
70326+ struct acl_object_label *retval2;
70327+
70328+ tmpsubj = (struct acl_subject_label *) subj;
70329+ read_lock(&gr_inode_lock);
70330+ do {
70331+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
70332+ if (retval) {
70333+ if (checkglob && retval->globbed) {
70334+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
70335+ if (retval2)
70336+ retval = retval2;
70337+ }
70338+ break;
70339+ }
70340+ } while ((tmpsubj = tmpsubj->parent_subject));
70341+ read_unlock(&gr_inode_lock);
70342+
70343+ return retval;
70344+}
70345+
70346+static __inline__ struct acl_object_label *
70347+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
70348+ struct dentry *curr_dentry,
70349+ const struct acl_subject_label *subj, char **path, const int checkglob)
70350+{
70351+ int newglob = checkglob;
70352+ ino_t inode;
70353+ dev_t device;
70354+
70355+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
70356+ as we don't want a / * rule to match instead of the / object
70357+ don't do this for create lookups that call this function though, since they're looking up
70358+ on the parent and thus need globbing checks on all paths
70359+ */
70360+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
70361+ newglob = GR_NO_GLOB;
70362+
70363+ spin_lock(&curr_dentry->d_lock);
70364+ inode = curr_dentry->d_inode->i_ino;
70365+ device = __get_dev(curr_dentry);
70366+ spin_unlock(&curr_dentry->d_lock);
70367+
70368+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
70369+}
70370+
70371+#ifdef CONFIG_HUGETLBFS
70372+static inline bool
70373+is_hugetlbfs_mnt(const struct vfsmount *mnt)
70374+{
70375+ int i;
70376+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
70377+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
70378+ return true;
70379+ }
70380+
70381+ return false;
70382+}
70383+#endif
70384+
70385+static struct acl_object_label *
70386+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70387+ const struct acl_subject_label *subj, char *path, const int checkglob)
70388+{
70389+ struct dentry *dentry = (struct dentry *) l_dentry;
70390+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
70391+ struct mount *real_mnt = real_mount(mnt);
70392+ struct acl_object_label *retval;
70393+ struct dentry *parent;
70394+
70395+ read_seqlock_excl(&mount_lock);
70396+ write_seqlock(&rename_lock);
70397+
70398+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
70399+#ifdef CONFIG_NET
70400+ mnt == sock_mnt ||
70401+#endif
70402+#ifdef CONFIG_HUGETLBFS
70403+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
70404+#endif
70405+ /* ignore Eric Biederman */
70406+ IS_PRIVATE(l_dentry->d_inode))) {
70407+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
70408+ goto out;
70409+ }
70410+
70411+ for (;;) {
70412+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
70413+ break;
70414+
70415+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
70416+ if (!mnt_has_parent(real_mnt))
70417+ break;
70418+
70419+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70420+ if (retval != NULL)
70421+ goto out;
70422+
70423+ dentry = real_mnt->mnt_mountpoint;
70424+ real_mnt = real_mnt->mnt_parent;
70425+ mnt = &real_mnt->mnt;
70426+ continue;
70427+ }
70428+
70429+ parent = dentry->d_parent;
70430+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70431+ if (retval != NULL)
70432+ goto out;
70433+
70434+ dentry = parent;
70435+ }
70436+
70437+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70438+
70439+ /* gr_real_root is pinned so we don't have to hold a reference */
70440+ if (retval == NULL)
70441+ retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
70442+out:
70443+ write_sequnlock(&rename_lock);
70444+ read_sequnlock_excl(&mount_lock);
70445+
70446+ BUG_ON(retval == NULL);
70447+
70448+ return retval;
70449+}
70450+
70451+static __inline__ struct acl_object_label *
70452+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70453+ const struct acl_subject_label *subj)
70454+{
70455+ char *path = NULL;
70456+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
70457+}
70458+
70459+static __inline__ struct acl_object_label *
70460+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70461+ const struct acl_subject_label *subj)
70462+{
70463+ char *path = NULL;
70464+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
70465+}
70466+
70467+static __inline__ struct acl_object_label *
70468+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70469+ const struct acl_subject_label *subj, char *path)
70470+{
70471+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
70472+}
70473+
70474+struct acl_subject_label *
70475+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70476+ const struct acl_role_label *role)
70477+{
70478+ struct dentry *dentry = (struct dentry *) l_dentry;
70479+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
70480+ struct mount *real_mnt = real_mount(mnt);
70481+ struct acl_subject_label *retval;
70482+ struct dentry *parent;
70483+
70484+ read_seqlock_excl(&mount_lock);
70485+ write_seqlock(&rename_lock);
70486+
70487+ for (;;) {
70488+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
70489+ break;
70490+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
70491+ if (!mnt_has_parent(real_mnt))
70492+ break;
70493+
70494+ spin_lock(&dentry->d_lock);
70495+ read_lock(&gr_inode_lock);
70496+ retval =
70497+ lookup_acl_subj_label(dentry->d_inode->i_ino,
70498+ __get_dev(dentry), role);
70499+ read_unlock(&gr_inode_lock);
70500+ spin_unlock(&dentry->d_lock);
70501+ if (retval != NULL)
70502+ goto out;
70503+
70504+ dentry = real_mnt->mnt_mountpoint;
70505+ real_mnt = real_mnt->mnt_parent;
70506+ mnt = &real_mnt->mnt;
70507+ continue;
70508+ }
70509+
70510+ spin_lock(&dentry->d_lock);
70511+ read_lock(&gr_inode_lock);
70512+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
70513+ __get_dev(dentry), role);
70514+ read_unlock(&gr_inode_lock);
70515+ parent = dentry->d_parent;
70516+ spin_unlock(&dentry->d_lock);
70517+
70518+ if (retval != NULL)
70519+ goto out;
70520+
70521+ dentry = parent;
70522+ }
70523+
70524+ spin_lock(&dentry->d_lock);
70525+ read_lock(&gr_inode_lock);
70526+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
70527+ __get_dev(dentry), role);
70528+ read_unlock(&gr_inode_lock);
70529+ spin_unlock(&dentry->d_lock);
70530+
70531+ if (unlikely(retval == NULL)) {
70532+ /* gr_real_root is pinned, we don't need to hold a reference */
70533+ read_lock(&gr_inode_lock);
70534+ retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
70535+ __get_dev(gr_real_root.dentry), role);
70536+ read_unlock(&gr_inode_lock);
70537+ }
70538+out:
70539+ write_sequnlock(&rename_lock);
70540+ read_sequnlock_excl(&mount_lock);
70541+
70542+ BUG_ON(retval == NULL);
70543+
70544+ return retval;
70545+}
70546+
70547+void
70548+assign_special_role(const char *rolename)
70549+{
70550+ struct acl_object_label *obj;
70551+ struct acl_role_label *r;
70552+ struct acl_role_label *assigned = NULL;
70553+ struct task_struct *tsk;
70554+ struct file *filp;
70555+
70556+ FOR_EACH_ROLE_START(r)
70557+ if (!strcmp(rolename, r->rolename) &&
70558+ (r->roletype & GR_ROLE_SPECIAL)) {
70559+ assigned = r;
70560+ break;
70561+ }
70562+ FOR_EACH_ROLE_END(r)
70563+
70564+ if (!assigned)
70565+ return;
70566+
70567+ read_lock(&tasklist_lock);
70568+ read_lock(&grsec_exec_file_lock);
70569+
70570+ tsk = current->real_parent;
70571+ if (tsk == NULL)
70572+ goto out_unlock;
70573+
70574+ filp = tsk->exec_file;
70575+ if (filp == NULL)
70576+ goto out_unlock;
70577+
70578+ tsk->is_writable = 0;
70579+ tsk->inherited = 0;
70580+
70581+ tsk->acl_sp_role = 1;
70582+ tsk->acl_role_id = ++acl_sp_role_value;
70583+ tsk->role = assigned;
70584+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
70585+
70586+ /* ignore additional mmap checks for processes that are writable
70587+ by the default ACL */
70588+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
70589+ if (unlikely(obj->mode & GR_WRITE))
70590+ tsk->is_writable = 1;
70591+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
70592+ if (unlikely(obj->mode & GR_WRITE))
70593+ tsk->is_writable = 1;
70594+
70595+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70596+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
70597+ tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
70598+#endif
70599+
70600+out_unlock:
70601+ read_unlock(&grsec_exec_file_lock);
70602+ read_unlock(&tasklist_lock);
70603+ return;
70604+}
70605+
70606+
70607+static void
70608+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
70609+{
70610+ struct task_struct *task = current;
70611+ const struct cred *cred = current_cred();
70612+
70613+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
70614+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70615+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70616+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
70617+
70618+ return;
70619+}
70620+
70621+static void
70622+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
70623+{
70624+ struct task_struct *task = current;
70625+ const struct cred *cred = current_cred();
70626+
70627+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
70628+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70629+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70630+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
70631+
70632+ return;
70633+}
70634+
70635+static void
70636+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
70637+{
70638+ struct task_struct *task = current;
70639+ const struct cred *cred = current_cred();
70640+
70641+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
70642+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70643+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70644+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
70645+
70646+ return;
70647+}
70648+
70649+static void
70650+gr_set_proc_res(struct task_struct *task)
70651+{
70652+ struct acl_subject_label *proc;
70653+ unsigned short i;
70654+
70655+ proc = task->acl;
70656+
70657+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
70658+ return;
70659+
70660+ for (i = 0; i < RLIM_NLIMITS; i++) {
70661+ if (!(proc->resmask & (1U << i)))
70662+ continue;
70663+
70664+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
70665+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
70666+
70667+ if (i == RLIMIT_CPU)
70668+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
70669+ }
70670+
70671+ return;
70672+}
70673+
70674+/* both of the below must be called with
70675+ rcu_read_lock();
70676+ read_lock(&tasklist_lock);
70677+ read_lock(&grsec_exec_file_lock);
70678+*/
70679+
70680+struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
70681+{
70682+ char *tmpname;
70683+ struct acl_subject_label *tmpsubj;
70684+ struct file *filp;
70685+ struct name_entry *nmatch;
70686+
70687+ filp = task->exec_file;
70688+ if (filp == NULL)
70689+ return NULL;
70690+
70691+ /* the following is to apply the correct subject
70692+ on binaries running when the RBAC system
70693+ is enabled, when the binaries have been
70694+ replaced or deleted since their execution
70695+ -----
70696+ when the RBAC system starts, the inode/dev
70697+ from exec_file will be one the RBAC system
70698+ is unaware of. It only knows the inode/dev
70699+ of the present file on disk, or the absence
70700+ of it.
70701+ */
70702+
70703+ if (filename)
70704+ nmatch = __lookup_name_entry(state, filename);
70705+ else {
70706+ preempt_disable();
70707+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
70708+
70709+ nmatch = __lookup_name_entry(state, tmpname);
70710+ preempt_enable();
70711+ }
70712+ tmpsubj = NULL;
70713+ if (nmatch) {
70714+ if (nmatch->deleted)
70715+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
70716+ else
70717+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
70718+ }
70719+ /* this also works for the reload case -- if we don't match a potentially inherited subject
70720+ then we fall back to a normal lookup based on the binary's ino/dev
70721+ */
70722+ if (tmpsubj == NULL)
70723+ tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
70724+
70725+ return tmpsubj;
70726+}
70727+
70728+static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
70729+{
70730+ return __gr_get_subject_for_task(&running_polstate, task, filename);
70731+}
70732+
70733+void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
70734+{
70735+ struct acl_object_label *obj;
70736+ struct file *filp;
70737+
70738+ filp = task->exec_file;
70739+
70740+ task->acl = subj;
70741+ task->is_writable = 0;
70742+ /* ignore additional mmap checks for processes that are writable
70743+ by the default ACL */
70744+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
70745+ if (unlikely(obj->mode & GR_WRITE))
70746+ task->is_writable = 1;
70747+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
70748+ if (unlikely(obj->mode & GR_WRITE))
70749+ task->is_writable = 1;
70750+
70751+ gr_set_proc_res(task);
70752+
70753+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70754+ 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);
70755+#endif
70756+}
70757+
70758+static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
70759+{
70760+ __gr_apply_subject_to_task(&running_polstate, task, subj);
70761+}
70762+
70763+__u32
70764+gr_search_file(const struct dentry * dentry, const __u32 mode,
70765+ const struct vfsmount * mnt)
70766+{
70767+ __u32 retval = mode;
70768+ struct acl_subject_label *curracl;
70769+ struct acl_object_label *currobj;
70770+
70771+ if (unlikely(!(gr_status & GR_READY)))
70772+ return (mode & ~GR_AUDITS);
70773+
70774+ curracl = current->acl;
70775+
70776+ currobj = chk_obj_label(dentry, mnt, curracl);
70777+ retval = currobj->mode & mode;
70778+
70779+ /* if we're opening a specified transfer file for writing
70780+ (e.g. /dev/initctl), then transfer our role to init
70781+ */
70782+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
70783+ current->role->roletype & GR_ROLE_PERSIST)) {
70784+ struct task_struct *task = init_pid_ns.child_reaper;
70785+
70786+ if (task->role != current->role) {
70787+ struct acl_subject_label *subj;
70788+
70789+ task->acl_sp_role = 0;
70790+ task->acl_role_id = current->acl_role_id;
70791+ task->role = current->role;
70792+ rcu_read_lock();
70793+ read_lock(&grsec_exec_file_lock);
70794+ subj = gr_get_subject_for_task(task, NULL);
70795+ gr_apply_subject_to_task(task, subj);
70796+ read_unlock(&grsec_exec_file_lock);
70797+ rcu_read_unlock();
70798+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
70799+ }
70800+ }
70801+
70802+ if (unlikely
70803+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
70804+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
70805+ __u32 new_mode = mode;
70806+
70807+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
70808+
70809+ retval = new_mode;
70810+
70811+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
70812+ new_mode |= GR_INHERIT;
70813+
70814+ if (!(mode & GR_NOLEARN))
70815+ gr_log_learn(dentry, mnt, new_mode);
70816+ }
70817+
70818+ return retval;
70819+}
70820+
70821+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
70822+ const struct dentry *parent,
70823+ const struct vfsmount *mnt)
70824+{
70825+ struct name_entry *match;
70826+ struct acl_object_label *matchpo;
70827+ struct acl_subject_label *curracl;
70828+ char *path;
70829+
70830+ if (unlikely(!(gr_status & GR_READY)))
70831+ return NULL;
70832+
70833+ preempt_disable();
70834+ path = gr_to_filename_rbac(new_dentry, mnt);
70835+ match = lookup_name_entry_create(path);
70836+
70837+ curracl = current->acl;
70838+
70839+ if (match) {
70840+ read_lock(&gr_inode_lock);
70841+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
70842+ read_unlock(&gr_inode_lock);
70843+
70844+ if (matchpo) {
70845+ preempt_enable();
70846+ return matchpo;
70847+ }
70848+ }
70849+
70850+ // lookup parent
70851+
70852+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
70853+
70854+ preempt_enable();
70855+ return matchpo;
70856+}
70857+
70858+__u32
70859+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
70860+ const struct vfsmount * mnt, const __u32 mode)
70861+{
70862+ struct acl_object_label *matchpo;
70863+ __u32 retval;
70864+
70865+ if (unlikely(!(gr_status & GR_READY)))
70866+ return (mode & ~GR_AUDITS);
70867+
70868+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
70869+
70870+ retval = matchpo->mode & mode;
70871+
70872+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
70873+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
70874+ __u32 new_mode = mode;
70875+
70876+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
70877+
70878+ gr_log_learn(new_dentry, mnt, new_mode);
70879+ return new_mode;
70880+ }
70881+
70882+ return retval;
70883+}
70884+
70885+__u32
70886+gr_check_link(const struct dentry * new_dentry,
70887+ const struct dentry * parent_dentry,
70888+ const struct vfsmount * parent_mnt,
70889+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
70890+{
70891+ struct acl_object_label *obj;
70892+ __u32 oldmode, newmode;
70893+ __u32 needmode;
70894+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
70895+ GR_DELETE | GR_INHERIT;
70896+
70897+ if (unlikely(!(gr_status & GR_READY)))
70898+ return (GR_CREATE | GR_LINK);
70899+
70900+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
70901+ oldmode = obj->mode;
70902+
70903+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
70904+ newmode = obj->mode;
70905+
70906+ needmode = newmode & checkmodes;
70907+
70908+ // old name for hardlink must have at least the permissions of the new name
70909+ if ((oldmode & needmode) != needmode)
70910+ goto bad;
70911+
70912+ // if old name had restrictions/auditing, make sure the new name does as well
70913+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
70914+
70915+ // don't allow hardlinking of suid/sgid/fcapped files without permission
70916+ if (is_privileged_binary(old_dentry))
70917+ needmode |= GR_SETID;
70918+
70919+ if ((newmode & needmode) != needmode)
70920+ goto bad;
70921+
70922+ // enforce minimum permissions
70923+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
70924+ return newmode;
70925+bad:
70926+ needmode = oldmode;
70927+ if (is_privileged_binary(old_dentry))
70928+ needmode |= GR_SETID;
70929+
70930+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
70931+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
70932+ return (GR_CREATE | GR_LINK);
70933+ } else if (newmode & GR_SUPPRESS)
70934+ return GR_SUPPRESS;
70935+ else
70936+ return 0;
70937+}
70938+
70939+int
70940+gr_check_hidden_task(const struct task_struct *task)
70941+{
70942+ if (unlikely(!(gr_status & GR_READY)))
70943+ return 0;
70944+
70945+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
70946+ return 1;
70947+
70948+ return 0;
70949+}
70950+
70951+int
70952+gr_check_protected_task(const struct task_struct *task)
70953+{
70954+ if (unlikely(!(gr_status & GR_READY) || !task))
70955+ return 0;
70956+
70957+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
70958+ task->acl != current->acl)
70959+ return 1;
70960+
70961+ return 0;
70962+}
70963+
70964+int
70965+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
70966+{
70967+ struct task_struct *p;
70968+ int ret = 0;
70969+
70970+ if (unlikely(!(gr_status & GR_READY) || !pid))
70971+ return ret;
70972+
70973+ read_lock(&tasklist_lock);
70974+ do_each_pid_task(pid, type, p) {
70975+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
70976+ p->acl != current->acl) {
70977+ ret = 1;
70978+ goto out;
70979+ }
70980+ } while_each_pid_task(pid, type, p);
70981+out:
70982+ read_unlock(&tasklist_lock);
70983+
70984+ return ret;
70985+}
70986+
70987+void
70988+gr_copy_label(struct task_struct *tsk)
70989+{
70990+ struct task_struct *p = current;
70991+
70992+ tsk->inherited = p->inherited;
70993+ tsk->acl_sp_role = 0;
70994+ tsk->acl_role_id = p->acl_role_id;
70995+ tsk->acl = p->acl;
70996+ tsk->role = p->role;
70997+ tsk->signal->used_accept = 0;
70998+ tsk->signal->curr_ip = p->signal->curr_ip;
70999+ tsk->signal->saved_ip = p->signal->saved_ip;
71000+ if (p->exec_file)
71001+ get_file(p->exec_file);
71002+ tsk->exec_file = p->exec_file;
71003+ tsk->is_writable = p->is_writable;
71004+ if (unlikely(p->signal->used_accept)) {
71005+ p->signal->curr_ip = 0;
71006+ p->signal->saved_ip = 0;
71007+ }
71008+
71009+ return;
71010+}
71011+
71012+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
71013+
71014+int
71015+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
71016+{
71017+ unsigned int i;
71018+ __u16 num;
71019+ uid_t *uidlist;
71020+ uid_t curuid;
71021+ int realok = 0;
71022+ int effectiveok = 0;
71023+ int fsok = 0;
71024+ uid_t globalreal, globaleffective, globalfs;
71025+
71026+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
71027+ struct user_struct *user;
71028+
71029+ if (!uid_valid(real))
71030+ goto skipit;
71031+
71032+ /* find user based on global namespace */
71033+
71034+ globalreal = GR_GLOBAL_UID(real);
71035+
71036+ user = find_user(make_kuid(&init_user_ns, globalreal));
71037+ if (user == NULL)
71038+ goto skipit;
71039+
71040+ if (gr_process_kernel_setuid_ban(user)) {
71041+ /* for find_user */
71042+ free_uid(user);
71043+ return 1;
71044+ }
71045+
71046+ /* for find_user */
71047+ free_uid(user);
71048+
71049+skipit:
71050+#endif
71051+
71052+ if (unlikely(!(gr_status & GR_READY)))
71053+ return 0;
71054+
71055+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
71056+ gr_log_learn_uid_change(real, effective, fs);
71057+
71058+ num = current->acl->user_trans_num;
71059+ uidlist = current->acl->user_transitions;
71060+
71061+ if (uidlist == NULL)
71062+ return 0;
71063+
71064+ if (!uid_valid(real)) {
71065+ realok = 1;
71066+ globalreal = (uid_t)-1;
71067+ } else {
71068+ globalreal = GR_GLOBAL_UID(real);
71069+ }
71070+ if (!uid_valid(effective)) {
71071+ effectiveok = 1;
71072+ globaleffective = (uid_t)-1;
71073+ } else {
71074+ globaleffective = GR_GLOBAL_UID(effective);
71075+ }
71076+ if (!uid_valid(fs)) {
71077+ fsok = 1;
71078+ globalfs = (uid_t)-1;
71079+ } else {
71080+ globalfs = GR_GLOBAL_UID(fs);
71081+ }
71082+
71083+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
71084+ for (i = 0; i < num; i++) {
71085+ curuid = uidlist[i];
71086+ if (globalreal == curuid)
71087+ realok = 1;
71088+ if (globaleffective == curuid)
71089+ effectiveok = 1;
71090+ if (globalfs == curuid)
71091+ fsok = 1;
71092+ }
71093+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
71094+ for (i = 0; i < num; i++) {
71095+ curuid = uidlist[i];
71096+ if (globalreal == curuid)
71097+ break;
71098+ if (globaleffective == curuid)
71099+ break;
71100+ if (globalfs == curuid)
71101+ break;
71102+ }
71103+ /* not in deny list */
71104+ if (i == num) {
71105+ realok = 1;
71106+ effectiveok = 1;
71107+ fsok = 1;
71108+ }
71109+ }
71110+
71111+ if (realok && effectiveok && fsok)
71112+ return 0;
71113+ else {
71114+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
71115+ return 1;
71116+ }
71117+}
71118+
71119+int
71120+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
71121+{
71122+ unsigned int i;
71123+ __u16 num;
71124+ gid_t *gidlist;
71125+ gid_t curgid;
71126+ int realok = 0;
71127+ int effectiveok = 0;
71128+ int fsok = 0;
71129+ gid_t globalreal, globaleffective, globalfs;
71130+
71131+ if (unlikely(!(gr_status & GR_READY)))
71132+ return 0;
71133+
71134+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
71135+ gr_log_learn_gid_change(real, effective, fs);
71136+
71137+ num = current->acl->group_trans_num;
71138+ gidlist = current->acl->group_transitions;
71139+
71140+ if (gidlist == NULL)
71141+ return 0;
71142+
71143+ if (!gid_valid(real)) {
71144+ realok = 1;
71145+ globalreal = (gid_t)-1;
71146+ } else {
71147+ globalreal = GR_GLOBAL_GID(real);
71148+ }
71149+ if (!gid_valid(effective)) {
71150+ effectiveok = 1;
71151+ globaleffective = (gid_t)-1;
71152+ } else {
71153+ globaleffective = GR_GLOBAL_GID(effective);
71154+ }
71155+ if (!gid_valid(fs)) {
71156+ fsok = 1;
71157+ globalfs = (gid_t)-1;
71158+ } else {
71159+ globalfs = GR_GLOBAL_GID(fs);
71160+ }
71161+
71162+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
71163+ for (i = 0; i < num; i++) {
71164+ curgid = gidlist[i];
71165+ if (globalreal == curgid)
71166+ realok = 1;
71167+ if (globaleffective == curgid)
71168+ effectiveok = 1;
71169+ if (globalfs == curgid)
71170+ fsok = 1;
71171+ }
71172+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
71173+ for (i = 0; i < num; i++) {
71174+ curgid = gidlist[i];
71175+ if (globalreal == curgid)
71176+ break;
71177+ if (globaleffective == curgid)
71178+ break;
71179+ if (globalfs == curgid)
71180+ break;
71181+ }
71182+ /* not in deny list */
71183+ if (i == num) {
71184+ realok = 1;
71185+ effectiveok = 1;
71186+ fsok = 1;
71187+ }
71188+ }
71189+
71190+ if (realok && effectiveok && fsok)
71191+ return 0;
71192+ else {
71193+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
71194+ return 1;
71195+ }
71196+}
71197+
71198+extern int gr_acl_is_capable(const int cap);
71199+
71200+void
71201+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
71202+{
71203+ struct acl_role_label *role = task->role;
71204+ struct acl_subject_label *subj = NULL;
71205+ struct acl_object_label *obj;
71206+ struct file *filp;
71207+ uid_t uid;
71208+ gid_t gid;
71209+
71210+ if (unlikely(!(gr_status & GR_READY)))
71211+ return;
71212+
71213+ uid = GR_GLOBAL_UID(kuid);
71214+ gid = GR_GLOBAL_GID(kgid);
71215+
71216+ filp = task->exec_file;
71217+
71218+ /* kernel process, we'll give them the kernel role */
71219+ if (unlikely(!filp)) {
71220+ task->role = running_polstate.kernel_role;
71221+ task->acl = running_polstate.kernel_role->root_label;
71222+ return;
71223+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
71224+ /* save the current ip at time of role lookup so that the proper
71225+ IP will be learned for role_allowed_ip */
71226+ task->signal->saved_ip = task->signal->curr_ip;
71227+ role = lookup_acl_role_label(task, uid, gid);
71228+ }
71229+
71230+ /* don't change the role if we're not a privileged process */
71231+ if (role && task->role != role &&
71232+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
71233+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
71234+ return;
71235+
71236+ /* perform subject lookup in possibly new role
71237+ we can use this result below in the case where role == task->role
71238+ */
71239+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
71240+
71241+ /* if we changed uid/gid, but result in the same role
71242+ and are using inheritance, don't lose the inherited subject
71243+ if current subject is other than what normal lookup
71244+ would result in, we arrived via inheritance, don't
71245+ lose subject
71246+ */
71247+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
71248+ (subj == task->acl)))
71249+ task->acl = subj;
71250+
71251+ /* leave task->inherited unaffected */
71252+
71253+ task->role = role;
71254+
71255+ task->is_writable = 0;
71256+
71257+ /* ignore additional mmap checks for processes that are writable
71258+ by the default ACL */
71259+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
71260+ if (unlikely(obj->mode & GR_WRITE))
71261+ task->is_writable = 1;
71262+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
71263+ if (unlikely(obj->mode & GR_WRITE))
71264+ task->is_writable = 1;
71265+
71266+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71267+ 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);
71268+#endif
71269+
71270+ gr_set_proc_res(task);
71271+
71272+ return;
71273+}
71274+
71275+int
71276+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
71277+ const int unsafe_flags)
71278+{
71279+ struct task_struct *task = current;
71280+ struct acl_subject_label *newacl;
71281+ struct acl_object_label *obj;
71282+ __u32 retmode;
71283+
71284+ if (unlikely(!(gr_status & GR_READY)))
71285+ return 0;
71286+
71287+ newacl = chk_subj_label(dentry, mnt, task->role);
71288+
71289+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
71290+ did an exec
71291+ */
71292+ rcu_read_lock();
71293+ read_lock(&tasklist_lock);
71294+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
71295+ (task->parent->acl->mode & GR_POVERRIDE))) {
71296+ read_unlock(&tasklist_lock);
71297+ rcu_read_unlock();
71298+ goto skip_check;
71299+ }
71300+ read_unlock(&tasklist_lock);
71301+ rcu_read_unlock();
71302+
71303+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
71304+ !(task->role->roletype & GR_ROLE_GOD) &&
71305+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
71306+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
71307+ if (unsafe_flags & LSM_UNSAFE_SHARE)
71308+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
71309+ else
71310+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
71311+ return -EACCES;
71312+ }
71313+
71314+skip_check:
71315+
71316+ obj = chk_obj_label(dentry, mnt, task->acl);
71317+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
71318+
71319+ if (!(task->acl->mode & GR_INHERITLEARN) &&
71320+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
71321+ if (obj->nested)
71322+ task->acl = obj->nested;
71323+ else
71324+ task->acl = newacl;
71325+ task->inherited = 0;
71326+ } else {
71327+ task->inherited = 1;
71328+ if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
71329+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
71330+ }
71331+
71332+ task->is_writable = 0;
71333+
71334+ /* ignore additional mmap checks for processes that are writable
71335+ by the default ACL */
71336+ obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
71337+ if (unlikely(obj->mode & GR_WRITE))
71338+ task->is_writable = 1;
71339+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
71340+ if (unlikely(obj->mode & GR_WRITE))
71341+ task->is_writable = 1;
71342+
71343+ gr_set_proc_res(task);
71344+
71345+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71346+ 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);
71347+#endif
71348+ return 0;
71349+}
71350+
71351+/* always called with valid inodev ptr */
71352+static void
71353+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
71354+{
71355+ struct acl_object_label *matchpo;
71356+ struct acl_subject_label *matchps;
71357+ struct acl_subject_label *subj;
71358+ struct acl_role_label *role;
71359+ unsigned int x;
71360+
71361+ FOR_EACH_ROLE_START(role)
71362+ FOR_EACH_SUBJECT_START(role, subj, x)
71363+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
71364+ matchpo->mode |= GR_DELETED;
71365+ FOR_EACH_SUBJECT_END(subj,x)
71366+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
71367+ /* nested subjects aren't in the role's subj_hash table */
71368+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
71369+ matchpo->mode |= GR_DELETED;
71370+ FOR_EACH_NESTED_SUBJECT_END(subj)
71371+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
71372+ matchps->mode |= GR_DELETED;
71373+ FOR_EACH_ROLE_END(role)
71374+
71375+ inodev->nentry->deleted = 1;
71376+
71377+ return;
71378+}
71379+
71380+void
71381+gr_handle_delete(const ino_t ino, const dev_t dev)
71382+{
71383+ struct inodev_entry *inodev;
71384+
71385+ if (unlikely(!(gr_status & GR_READY)))
71386+ return;
71387+
71388+ write_lock(&gr_inode_lock);
71389+ inodev = lookup_inodev_entry(ino, dev);
71390+ if (inodev != NULL)
71391+ do_handle_delete(inodev, ino, dev);
71392+ write_unlock(&gr_inode_lock);
71393+
71394+ return;
71395+}
71396+
71397+static void
71398+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
71399+ const ino_t newinode, const dev_t newdevice,
71400+ struct acl_subject_label *subj)
71401+{
71402+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
71403+ struct acl_object_label *match;
71404+
71405+ match = subj->obj_hash[index];
71406+
71407+ while (match && (match->inode != oldinode ||
71408+ match->device != olddevice ||
71409+ !(match->mode & GR_DELETED)))
71410+ match = match->next;
71411+
71412+ if (match && (match->inode == oldinode)
71413+ && (match->device == olddevice)
71414+ && (match->mode & GR_DELETED)) {
71415+ if (match->prev == NULL) {
71416+ subj->obj_hash[index] = match->next;
71417+ if (match->next != NULL)
71418+ match->next->prev = NULL;
71419+ } else {
71420+ match->prev->next = match->next;
71421+ if (match->next != NULL)
71422+ match->next->prev = match->prev;
71423+ }
71424+ match->prev = NULL;
71425+ match->next = NULL;
71426+ match->inode = newinode;
71427+ match->device = newdevice;
71428+ match->mode &= ~GR_DELETED;
71429+
71430+ insert_acl_obj_label(match, subj);
71431+ }
71432+
71433+ return;
71434+}
71435+
71436+static void
71437+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
71438+ const ino_t newinode, const dev_t newdevice,
71439+ struct acl_role_label *role)
71440+{
71441+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
71442+ struct acl_subject_label *match;
71443+
71444+ match = role->subj_hash[index];
71445+
71446+ while (match && (match->inode != oldinode ||
71447+ match->device != olddevice ||
71448+ !(match->mode & GR_DELETED)))
71449+ match = match->next;
71450+
71451+ if (match && (match->inode == oldinode)
71452+ && (match->device == olddevice)
71453+ && (match->mode & GR_DELETED)) {
71454+ if (match->prev == NULL) {
71455+ role->subj_hash[index] = match->next;
71456+ if (match->next != NULL)
71457+ match->next->prev = NULL;
71458+ } else {
71459+ match->prev->next = match->next;
71460+ if (match->next != NULL)
71461+ match->next->prev = match->prev;
71462+ }
71463+ match->prev = NULL;
71464+ match->next = NULL;
71465+ match->inode = newinode;
71466+ match->device = newdevice;
71467+ match->mode &= ~GR_DELETED;
71468+
71469+ insert_acl_subj_label(match, role);
71470+ }
71471+
71472+ return;
71473+}
71474+
71475+static void
71476+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
71477+ const ino_t newinode, const dev_t newdevice)
71478+{
71479+ unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
71480+ struct inodev_entry *match;
71481+
71482+ match = running_polstate.inodev_set.i_hash[index];
71483+
71484+ while (match && (match->nentry->inode != oldinode ||
71485+ match->nentry->device != olddevice || !match->nentry->deleted))
71486+ match = match->next;
71487+
71488+ if (match && (match->nentry->inode == oldinode)
71489+ && (match->nentry->device == olddevice) &&
71490+ match->nentry->deleted) {
71491+ if (match->prev == NULL) {
71492+ running_polstate.inodev_set.i_hash[index] = match->next;
71493+ if (match->next != NULL)
71494+ match->next->prev = NULL;
71495+ } else {
71496+ match->prev->next = match->next;
71497+ if (match->next != NULL)
71498+ match->next->prev = match->prev;
71499+ }
71500+ match->prev = NULL;
71501+ match->next = NULL;
71502+ match->nentry->inode = newinode;
71503+ match->nentry->device = newdevice;
71504+ match->nentry->deleted = 0;
71505+
71506+ insert_inodev_entry(match);
71507+ }
71508+
71509+ return;
71510+}
71511+
71512+static void
71513+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
71514+{
71515+ struct acl_subject_label *subj;
71516+ struct acl_role_label *role;
71517+ unsigned int x;
71518+
71519+ FOR_EACH_ROLE_START(role)
71520+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
71521+
71522+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
71523+ if ((subj->inode == ino) && (subj->device == dev)) {
71524+ subj->inode = ino;
71525+ subj->device = dev;
71526+ }
71527+ /* nested subjects aren't in the role's subj_hash table */
71528+ update_acl_obj_label(matchn->inode, matchn->device,
71529+ ino, dev, subj);
71530+ FOR_EACH_NESTED_SUBJECT_END(subj)
71531+ FOR_EACH_SUBJECT_START(role, subj, x)
71532+ update_acl_obj_label(matchn->inode, matchn->device,
71533+ ino, dev, subj);
71534+ FOR_EACH_SUBJECT_END(subj,x)
71535+ FOR_EACH_ROLE_END(role)
71536+
71537+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
71538+
71539+ return;
71540+}
71541+
71542+static void
71543+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
71544+ const struct vfsmount *mnt)
71545+{
71546+ ino_t ino = dentry->d_inode->i_ino;
71547+ dev_t dev = __get_dev(dentry);
71548+
71549+ __do_handle_create(matchn, ino, dev);
71550+
71551+ return;
71552+}
71553+
71554+void
71555+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
71556+{
71557+ struct name_entry *matchn;
71558+
71559+ if (unlikely(!(gr_status & GR_READY)))
71560+ return;
71561+
71562+ preempt_disable();
71563+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
71564+
71565+ if (unlikely((unsigned long)matchn)) {
71566+ write_lock(&gr_inode_lock);
71567+ do_handle_create(matchn, dentry, mnt);
71568+ write_unlock(&gr_inode_lock);
71569+ }
71570+ preempt_enable();
71571+
71572+ return;
71573+}
71574+
71575+void
71576+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
71577+{
71578+ struct name_entry *matchn;
71579+
71580+ if (unlikely(!(gr_status & GR_READY)))
71581+ return;
71582+
71583+ preempt_disable();
71584+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
71585+
71586+ if (unlikely((unsigned long)matchn)) {
71587+ write_lock(&gr_inode_lock);
71588+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
71589+ write_unlock(&gr_inode_lock);
71590+ }
71591+ preempt_enable();
71592+
71593+ return;
71594+}
71595+
71596+void
71597+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
71598+ struct dentry *old_dentry,
71599+ struct dentry *new_dentry,
71600+ struct vfsmount *mnt, const __u8 replace, unsigned int flags)
71601+{
71602+ struct name_entry *matchn;
71603+ struct name_entry *matchn2 = NULL;
71604+ struct inodev_entry *inodev;
71605+ struct inode *inode = new_dentry->d_inode;
71606+ ino_t old_ino = old_dentry->d_inode->i_ino;
71607+ dev_t old_dev = __get_dev(old_dentry);
71608+ unsigned int exchange = flags & RENAME_EXCHANGE;
71609+
71610+ /* vfs_rename swaps the name and parent link for old_dentry and
71611+ new_dentry
71612+ at this point, old_dentry has the new name, parent link, and inode
71613+ for the renamed file
71614+ if a file is being replaced by a rename, new_dentry has the inode
71615+ and name for the replaced file
71616+ */
71617+
71618+ if (unlikely(!(gr_status & GR_READY)))
71619+ return;
71620+
71621+ preempt_disable();
71622+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
71623+
71624+ /* exchange cases:
71625+ a filename exists for the source, but not dest
71626+ do a recreate on source
71627+ a filename exists for the dest, but not source
71628+ do a recreate on dest
71629+ a filename exists for both source and dest
71630+ delete source and dest, then create source and dest
71631+ a filename exists for neither source nor dest
71632+ no updates needed
71633+
71634+ the name entry lookups get us the old inode/dev associated with
71635+ each name, so do the deletes first (if possible) so that when
71636+ we do the create, we pick up on the right entries
71637+ */
71638+
71639+ if (exchange)
71640+ matchn2 = lookup_name_entry(gr_to_filename_rbac(new_dentry, mnt));
71641+
71642+ /* we wouldn't have to check d_inode if it weren't for
71643+ NFS silly-renaming
71644+ */
71645+
71646+ write_lock(&gr_inode_lock);
71647+ if (unlikely((replace || exchange) && inode)) {
71648+ ino_t new_ino = inode->i_ino;
71649+ dev_t new_dev = __get_dev(new_dentry);
71650+
71651+ inodev = lookup_inodev_entry(new_ino, new_dev);
71652+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
71653+ do_handle_delete(inodev, new_ino, new_dev);
71654+ }
71655+
71656+ inodev = lookup_inodev_entry(old_ino, old_dev);
71657+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
71658+ do_handle_delete(inodev, old_ino, old_dev);
71659+
71660+ if (unlikely(matchn != NULL))
71661+ do_handle_create(matchn, old_dentry, mnt);
71662+
71663+ if (unlikely(matchn2 != NULL))
71664+ do_handle_create(matchn2, new_dentry, mnt);
71665+
71666+ write_unlock(&gr_inode_lock);
71667+ preempt_enable();
71668+
71669+ return;
71670+}
71671+
71672+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
71673+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
71674+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
71675+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
71676+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
71677+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
71678+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
71679+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
71680+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
71681+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
71682+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
71683+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
71684+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
71685+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
71686+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
71687+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
71688+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
71689+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
71690+};
71691+
71692+void
71693+gr_learn_resource(const struct task_struct *task,
71694+ const int res, const unsigned long wanted, const int gt)
71695+{
71696+ struct acl_subject_label *acl;
71697+ const struct cred *cred;
71698+
71699+ if (unlikely((gr_status & GR_READY) &&
71700+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
71701+ goto skip_reslog;
71702+
71703+ gr_log_resource(task, res, wanted, gt);
71704+skip_reslog:
71705+
71706+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
71707+ return;
71708+
71709+ acl = task->acl;
71710+
71711+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
71712+ !(acl->resmask & (1U << (unsigned short) res))))
71713+ return;
71714+
71715+ if (wanted >= acl->res[res].rlim_cur) {
71716+ unsigned long res_add;
71717+
71718+ res_add = wanted + res_learn_bumps[res];
71719+
71720+ acl->res[res].rlim_cur = res_add;
71721+
71722+ if (wanted > acl->res[res].rlim_max)
71723+ acl->res[res].rlim_max = res_add;
71724+
71725+ /* only log the subject filename, since resource logging is supported for
71726+ single-subject learning only */
71727+ rcu_read_lock();
71728+ cred = __task_cred(task);
71729+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
71730+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
71731+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
71732+ "", (unsigned long) res, &task->signal->saved_ip);
71733+ rcu_read_unlock();
71734+ }
71735+
71736+ return;
71737+}
71738+EXPORT_SYMBOL_GPL(gr_learn_resource);
71739+#endif
71740+
71741+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
71742+void
71743+pax_set_initial_flags(struct linux_binprm *bprm)
71744+{
71745+ struct task_struct *task = current;
71746+ struct acl_subject_label *proc;
71747+ unsigned long flags;
71748+
71749+ if (unlikely(!(gr_status & GR_READY)))
71750+ return;
71751+
71752+ flags = pax_get_flags(task);
71753+
71754+ proc = task->acl;
71755+
71756+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
71757+ flags &= ~MF_PAX_PAGEEXEC;
71758+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
71759+ flags &= ~MF_PAX_SEGMEXEC;
71760+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
71761+ flags &= ~MF_PAX_RANDMMAP;
71762+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
71763+ flags &= ~MF_PAX_EMUTRAMP;
71764+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
71765+ flags &= ~MF_PAX_MPROTECT;
71766+
71767+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
71768+ flags |= MF_PAX_PAGEEXEC;
71769+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
71770+ flags |= MF_PAX_SEGMEXEC;
71771+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
71772+ flags |= MF_PAX_RANDMMAP;
71773+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
71774+ flags |= MF_PAX_EMUTRAMP;
71775+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
71776+ flags |= MF_PAX_MPROTECT;
71777+
71778+ pax_set_flags(task, flags);
71779+
71780+ return;
71781+}
71782+#endif
71783+
71784+int
71785+gr_handle_proc_ptrace(struct task_struct *task)
71786+{
71787+ struct file *filp;
71788+ struct task_struct *tmp = task;
71789+ struct task_struct *curtemp = current;
71790+ __u32 retmode;
71791+
71792+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
71793+ if (unlikely(!(gr_status & GR_READY)))
71794+ return 0;
71795+#endif
71796+
71797+ read_lock(&tasklist_lock);
71798+ read_lock(&grsec_exec_file_lock);
71799+ filp = task->exec_file;
71800+
71801+ while (task_pid_nr(tmp) > 0) {
71802+ if (tmp == curtemp)
71803+ break;
71804+ tmp = tmp->real_parent;
71805+ }
71806+
71807+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
71808+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
71809+ read_unlock(&grsec_exec_file_lock);
71810+ read_unlock(&tasklist_lock);
71811+ return 1;
71812+ }
71813+
71814+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71815+ if (!(gr_status & GR_READY)) {
71816+ read_unlock(&grsec_exec_file_lock);
71817+ read_unlock(&tasklist_lock);
71818+ return 0;
71819+ }
71820+#endif
71821+
71822+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
71823+ read_unlock(&grsec_exec_file_lock);
71824+ read_unlock(&tasklist_lock);
71825+
71826+ if (retmode & GR_NOPTRACE)
71827+ return 1;
71828+
71829+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
71830+ && (current->acl != task->acl || (current->acl != current->role->root_label
71831+ && task_pid_nr(current) != task_pid_nr(task))))
71832+ return 1;
71833+
71834+ return 0;
71835+}
71836+
71837+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
71838+{
71839+ if (unlikely(!(gr_status & GR_READY)))
71840+ return;
71841+
71842+ if (!(current->role->roletype & GR_ROLE_GOD))
71843+ return;
71844+
71845+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
71846+ p->role->rolename, gr_task_roletype_to_char(p),
71847+ p->acl->filename);
71848+}
71849+
71850+int
71851+gr_handle_ptrace(struct task_struct *task, const long request)
71852+{
71853+ struct task_struct *tmp = task;
71854+ struct task_struct *curtemp = current;
71855+ __u32 retmode;
71856+
71857+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
71858+ if (unlikely(!(gr_status & GR_READY)))
71859+ return 0;
71860+#endif
71861+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
71862+ read_lock(&tasklist_lock);
71863+ while (task_pid_nr(tmp) > 0) {
71864+ if (tmp == curtemp)
71865+ break;
71866+ tmp = tmp->real_parent;
71867+ }
71868+
71869+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
71870+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
71871+ read_unlock(&tasklist_lock);
71872+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
71873+ return 1;
71874+ }
71875+ read_unlock(&tasklist_lock);
71876+ }
71877+
71878+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71879+ if (!(gr_status & GR_READY))
71880+ return 0;
71881+#endif
71882+
71883+ read_lock(&grsec_exec_file_lock);
71884+ if (unlikely(!task->exec_file)) {
71885+ read_unlock(&grsec_exec_file_lock);
71886+ return 0;
71887+ }
71888+
71889+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
71890+ read_unlock(&grsec_exec_file_lock);
71891+
71892+ if (retmode & GR_NOPTRACE) {
71893+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
71894+ return 1;
71895+ }
71896+
71897+ if (retmode & GR_PTRACERD) {
71898+ switch (request) {
71899+ case PTRACE_SEIZE:
71900+ case PTRACE_POKETEXT:
71901+ case PTRACE_POKEDATA:
71902+ case PTRACE_POKEUSR:
71903+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
71904+ case PTRACE_SETREGS:
71905+ case PTRACE_SETFPREGS:
71906+#endif
71907+#ifdef CONFIG_X86
71908+ case PTRACE_SETFPXREGS:
71909+#endif
71910+#ifdef CONFIG_ALTIVEC
71911+ case PTRACE_SETVRREGS:
71912+#endif
71913+ return 1;
71914+ default:
71915+ return 0;
71916+ }
71917+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
71918+ !(current->role->roletype & GR_ROLE_GOD) &&
71919+ (current->acl != task->acl)) {
71920+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
71921+ return 1;
71922+ }
71923+
71924+ return 0;
71925+}
71926+
71927+static int is_writable_mmap(const struct file *filp)
71928+{
71929+ struct task_struct *task = current;
71930+ struct acl_object_label *obj, *obj2;
71931+
71932+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
71933+ !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))) {
71934+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
71935+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
71936+ task->role->root_label);
71937+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
71938+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
71939+ return 1;
71940+ }
71941+ }
71942+ return 0;
71943+}
71944+
71945+int
71946+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
71947+{
71948+ __u32 mode;
71949+
71950+ if (unlikely(!file || !(prot & PROT_EXEC)))
71951+ return 1;
71952+
71953+ if (is_writable_mmap(file))
71954+ return 0;
71955+
71956+ mode =
71957+ gr_search_file(file->f_path.dentry,
71958+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
71959+ file->f_path.mnt);
71960+
71961+ if (!gr_tpe_allow(file))
71962+ return 0;
71963+
71964+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
71965+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
71966+ return 0;
71967+ } else if (unlikely(!(mode & GR_EXEC))) {
71968+ return 0;
71969+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
71970+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
71971+ return 1;
71972+ }
71973+
71974+ return 1;
71975+}
71976+
71977+int
71978+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
71979+{
71980+ __u32 mode;
71981+
71982+ if (unlikely(!file || !(prot & PROT_EXEC)))
71983+ return 1;
71984+
71985+ if (is_writable_mmap(file))
71986+ return 0;
71987+
71988+ mode =
71989+ gr_search_file(file->f_path.dentry,
71990+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
71991+ file->f_path.mnt);
71992+
71993+ if (!gr_tpe_allow(file))
71994+ return 0;
71995+
71996+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
71997+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
71998+ return 0;
71999+ } else if (unlikely(!(mode & GR_EXEC))) {
72000+ return 0;
72001+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
72002+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72003+ return 1;
72004+ }
72005+
72006+ return 1;
72007+}
72008+
72009+void
72010+gr_acl_handle_psacct(struct task_struct *task, const long code)
72011+{
72012+ unsigned long runtime, cputime;
72013+ cputime_t utime, stime;
72014+ unsigned int wday, cday;
72015+ __u8 whr, chr;
72016+ __u8 wmin, cmin;
72017+ __u8 wsec, csec;
72018+ struct timespec curtime, starttime;
72019+
72020+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
72021+ !(task->acl->mode & GR_PROCACCT)))
72022+ return;
72023+
72024+ curtime = ns_to_timespec(ktime_get_ns());
72025+ starttime = ns_to_timespec(task->start_time);
72026+ runtime = curtime.tv_sec - starttime.tv_sec;
72027+ wday = runtime / (60 * 60 * 24);
72028+ runtime -= wday * (60 * 60 * 24);
72029+ whr = runtime / (60 * 60);
72030+ runtime -= whr * (60 * 60);
72031+ wmin = runtime / 60;
72032+ runtime -= wmin * 60;
72033+ wsec = runtime;
72034+
72035+ task_cputime(task, &utime, &stime);
72036+ cputime = cputime_to_secs(utime + stime);
72037+ cday = cputime / (60 * 60 * 24);
72038+ cputime -= cday * (60 * 60 * 24);
72039+ chr = cputime / (60 * 60);
72040+ cputime -= chr * (60 * 60);
72041+ cmin = cputime / 60;
72042+ cputime -= cmin * 60;
72043+ csec = cputime;
72044+
72045+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
72046+
72047+ return;
72048+}
72049+
72050+#ifdef CONFIG_TASKSTATS
72051+int gr_is_taskstats_denied(int pid)
72052+{
72053+ struct task_struct *task;
72054+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72055+ const struct cred *cred;
72056+#endif
72057+ int ret = 0;
72058+
72059+ /* restrict taskstats viewing to un-chrooted root users
72060+ who have the 'view' subject flag if the RBAC system is enabled
72061+ */
72062+
72063+ rcu_read_lock();
72064+ read_lock(&tasklist_lock);
72065+ task = find_task_by_vpid(pid);
72066+ if (task) {
72067+#ifdef CONFIG_GRKERNSEC_CHROOT
72068+ if (proc_is_chrooted(task))
72069+ ret = -EACCES;
72070+#endif
72071+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72072+ cred = __task_cred(task);
72073+#ifdef CONFIG_GRKERNSEC_PROC_USER
72074+ if (gr_is_global_nonroot(cred->uid))
72075+ ret = -EACCES;
72076+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72077+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
72078+ ret = -EACCES;
72079+#endif
72080+#endif
72081+ if (gr_status & GR_READY) {
72082+ if (!(task->acl->mode & GR_VIEW))
72083+ ret = -EACCES;
72084+ }
72085+ } else
72086+ ret = -ENOENT;
72087+
72088+ read_unlock(&tasklist_lock);
72089+ rcu_read_unlock();
72090+
72091+ return ret;
72092+}
72093+#endif
72094+
72095+/* AUXV entries are filled via a descendant of search_binary_handler
72096+ after we've already applied the subject for the target
72097+*/
72098+int gr_acl_enable_at_secure(void)
72099+{
72100+ if (unlikely(!(gr_status & GR_READY)))
72101+ return 0;
72102+
72103+ if (current->acl->mode & GR_ATSECURE)
72104+ return 1;
72105+
72106+ return 0;
72107+}
72108+
72109+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
72110+{
72111+ struct task_struct *task = current;
72112+ struct dentry *dentry = file->f_path.dentry;
72113+ struct vfsmount *mnt = file->f_path.mnt;
72114+ struct acl_object_label *obj, *tmp;
72115+ struct acl_subject_label *subj;
72116+ unsigned int bufsize;
72117+ int is_not_root;
72118+ char *path;
72119+ dev_t dev = __get_dev(dentry);
72120+
72121+ if (unlikely(!(gr_status & GR_READY)))
72122+ return 1;
72123+
72124+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
72125+ return 1;
72126+
72127+ /* ignore Eric Biederman */
72128+ if (IS_PRIVATE(dentry->d_inode))
72129+ return 1;
72130+
72131+ subj = task->acl;
72132+ read_lock(&gr_inode_lock);
72133+ do {
72134+ obj = lookup_acl_obj_label(ino, dev, subj);
72135+ if (obj != NULL) {
72136+ read_unlock(&gr_inode_lock);
72137+ return (obj->mode & GR_FIND) ? 1 : 0;
72138+ }
72139+ } while ((subj = subj->parent_subject));
72140+ read_unlock(&gr_inode_lock);
72141+
72142+ /* this is purely an optimization since we're looking for an object
72143+ for the directory we're doing a readdir on
72144+ if it's possible for any globbed object to match the entry we're
72145+ filling into the directory, then the object we find here will be
72146+ an anchor point with attached globbed objects
72147+ */
72148+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
72149+ if (obj->globbed == NULL)
72150+ return (obj->mode & GR_FIND) ? 1 : 0;
72151+
72152+ is_not_root = ((obj->filename[0] == '/') &&
72153+ (obj->filename[1] == '\0')) ? 0 : 1;
72154+ bufsize = PAGE_SIZE - namelen - is_not_root;
72155+
72156+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
72157+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
72158+ return 1;
72159+
72160+ preempt_disable();
72161+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
72162+ bufsize);
72163+
72164+ bufsize = strlen(path);
72165+
72166+ /* if base is "/", don't append an additional slash */
72167+ if (is_not_root)
72168+ *(path + bufsize) = '/';
72169+ memcpy(path + bufsize + is_not_root, name, namelen);
72170+ *(path + bufsize + namelen + is_not_root) = '\0';
72171+
72172+ tmp = obj->globbed;
72173+ while (tmp) {
72174+ if (!glob_match(tmp->filename, path)) {
72175+ preempt_enable();
72176+ return (tmp->mode & GR_FIND) ? 1 : 0;
72177+ }
72178+ tmp = tmp->next;
72179+ }
72180+ preempt_enable();
72181+ return (obj->mode & GR_FIND) ? 1 : 0;
72182+}
72183+
72184+void gr_put_exec_file(struct task_struct *task)
72185+{
72186+ struct file *filp;
72187+
72188+ write_lock(&grsec_exec_file_lock);
72189+ filp = task->exec_file;
72190+ task->exec_file = NULL;
72191+ write_unlock(&grsec_exec_file_lock);
72192+
72193+ if (filp)
72194+ fput(filp);
72195+
72196+ return;
72197+}
72198+
72199+
72200+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
72201+EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
72202+#endif
72203+#ifdef CONFIG_SECURITY
72204+EXPORT_SYMBOL_GPL(gr_check_user_change);
72205+EXPORT_SYMBOL_GPL(gr_check_group_change);
72206+#endif
72207+
72208diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
72209new file mode 100644
72210index 0000000..18ffbbd
72211--- /dev/null
72212+++ b/grsecurity/gracl_alloc.c
72213@@ -0,0 +1,105 @@
72214+#include <linux/kernel.h>
72215+#include <linux/mm.h>
72216+#include <linux/slab.h>
72217+#include <linux/vmalloc.h>
72218+#include <linux/gracl.h>
72219+#include <linux/grsecurity.h>
72220+
72221+static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
72222+struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
72223+
72224+static __inline__ int
72225+alloc_pop(void)
72226+{
72227+ if (current_alloc_state->alloc_stack_next == 1)
72228+ return 0;
72229+
72230+ kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
72231+
72232+ current_alloc_state->alloc_stack_next--;
72233+
72234+ return 1;
72235+}
72236+
72237+static __inline__ int
72238+alloc_push(void *buf)
72239+{
72240+ if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
72241+ return 1;
72242+
72243+ current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
72244+
72245+ current_alloc_state->alloc_stack_next++;
72246+
72247+ return 0;
72248+}
72249+
72250+void *
72251+acl_alloc(unsigned long len)
72252+{
72253+ void *ret = NULL;
72254+
72255+ if (!len || len > PAGE_SIZE)
72256+ goto out;
72257+
72258+ ret = kmalloc(len, GFP_KERNEL);
72259+
72260+ if (ret) {
72261+ if (alloc_push(ret)) {
72262+ kfree(ret);
72263+ ret = NULL;
72264+ }
72265+ }
72266+
72267+out:
72268+ return ret;
72269+}
72270+
72271+void *
72272+acl_alloc_num(unsigned long num, unsigned long len)
72273+{
72274+ if (!len || (num > (PAGE_SIZE / len)))
72275+ return NULL;
72276+
72277+ return acl_alloc(num * len);
72278+}
72279+
72280+void
72281+acl_free_all(void)
72282+{
72283+ if (!current_alloc_state->alloc_stack)
72284+ return;
72285+
72286+ while (alloc_pop()) ;
72287+
72288+ if (current_alloc_state->alloc_stack) {
72289+ if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
72290+ kfree(current_alloc_state->alloc_stack);
72291+ else
72292+ vfree(current_alloc_state->alloc_stack);
72293+ }
72294+
72295+ current_alloc_state->alloc_stack = NULL;
72296+ current_alloc_state->alloc_stack_size = 1;
72297+ current_alloc_state->alloc_stack_next = 1;
72298+
72299+ return;
72300+}
72301+
72302+int
72303+acl_alloc_stack_init(unsigned long size)
72304+{
72305+ if ((size * sizeof (void *)) <= PAGE_SIZE)
72306+ current_alloc_state->alloc_stack =
72307+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
72308+ else
72309+ current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
72310+
72311+ current_alloc_state->alloc_stack_size = size;
72312+ current_alloc_state->alloc_stack_next = 1;
72313+
72314+ if (!current_alloc_state->alloc_stack)
72315+ return 0;
72316+ else
72317+ return 1;
72318+}
72319diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
72320new file mode 100644
72321index 0000000..1a94c11
72322--- /dev/null
72323+++ b/grsecurity/gracl_cap.c
72324@@ -0,0 +1,127 @@
72325+#include <linux/kernel.h>
72326+#include <linux/module.h>
72327+#include <linux/sched.h>
72328+#include <linux/gracl.h>
72329+#include <linux/grsecurity.h>
72330+#include <linux/grinternal.h>
72331+
72332+extern const char *captab_log[];
72333+extern int captab_log_entries;
72334+
72335+int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
72336+{
72337+ struct acl_subject_label *curracl;
72338+
72339+ if (!gr_acl_is_enabled())
72340+ return 1;
72341+
72342+ curracl = task->acl;
72343+
72344+ if (curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
72345+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
72346+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
72347+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
72348+ gr_to_filename(task->exec_file->f_path.dentry,
72349+ task->exec_file->f_path.mnt) : curracl->filename,
72350+ curracl->filename, 0UL,
72351+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
72352+ return 1;
72353+ }
72354+
72355+ return 0;
72356+}
72357+
72358+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
72359+{
72360+ struct acl_subject_label *curracl;
72361+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
72362+ kernel_cap_t cap_audit = __cap_empty_set;
72363+
72364+ if (!gr_acl_is_enabled())
72365+ return 1;
72366+
72367+ curracl = task->acl;
72368+
72369+ cap_drop = curracl->cap_lower;
72370+ cap_mask = curracl->cap_mask;
72371+ cap_audit = curracl->cap_invert_audit;
72372+
72373+ while ((curracl = curracl->parent_subject)) {
72374+ /* if the cap isn't specified in the current computed mask but is specified in the
72375+ current level subject, and is lowered in the current level subject, then add
72376+ it to the set of dropped capabilities
72377+ otherwise, add the current level subject's mask to the current computed mask
72378+ */
72379+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
72380+ cap_raise(cap_mask, cap);
72381+ if (cap_raised(curracl->cap_lower, cap))
72382+ cap_raise(cap_drop, cap);
72383+ if (cap_raised(curracl->cap_invert_audit, cap))
72384+ cap_raise(cap_audit, cap);
72385+ }
72386+ }
72387+
72388+ if (!cap_raised(cap_drop, cap)) {
72389+ if (cap_raised(cap_audit, cap))
72390+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
72391+ return 1;
72392+ }
72393+
72394+ /* only learn the capability use if the process has the capability in the
72395+ general case, the two uses in sys.c of gr_learn_cap are an exception
72396+ to this rule to ensure any role transition involves what the full-learned
72397+ policy believes in a privileged process
72398+ */
72399+ if (cap_raised(cred->cap_effective, cap) && gr_learn_cap(task, cred, cap))
72400+ return 1;
72401+
72402+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
72403+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
72404+
72405+ return 0;
72406+}
72407+
72408+int
72409+gr_acl_is_capable(const int cap)
72410+{
72411+ return gr_task_acl_is_capable(current, current_cred(), cap);
72412+}
72413+
72414+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
72415+{
72416+ struct acl_subject_label *curracl;
72417+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
72418+
72419+ if (!gr_acl_is_enabled())
72420+ return 1;
72421+
72422+ curracl = task->acl;
72423+
72424+ cap_drop = curracl->cap_lower;
72425+ cap_mask = curracl->cap_mask;
72426+
72427+ while ((curracl = curracl->parent_subject)) {
72428+ /* if the cap isn't specified in the current computed mask but is specified in the
72429+ current level subject, and is lowered in the current level subject, then add
72430+ it to the set of dropped capabilities
72431+ otherwise, add the current level subject's mask to the current computed mask
72432+ */
72433+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
72434+ cap_raise(cap_mask, cap);
72435+ if (cap_raised(curracl->cap_lower, cap))
72436+ cap_raise(cap_drop, cap);
72437+ }
72438+ }
72439+
72440+ if (!cap_raised(cap_drop, cap))
72441+ return 1;
72442+
72443+ return 0;
72444+}
72445+
72446+int
72447+gr_acl_is_capable_nolog(const int cap)
72448+{
72449+ return gr_task_acl_is_capable_nolog(current, cap);
72450+}
72451+
72452diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
72453new file mode 100644
72454index 0000000..ca25605
72455--- /dev/null
72456+++ b/grsecurity/gracl_compat.c
72457@@ -0,0 +1,270 @@
72458+#include <linux/kernel.h>
72459+#include <linux/gracl.h>
72460+#include <linux/compat.h>
72461+#include <linux/gracl_compat.h>
72462+
72463+#include <asm/uaccess.h>
72464+
72465+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
72466+{
72467+ struct gr_arg_wrapper_compat uwrapcompat;
72468+
72469+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
72470+ return -EFAULT;
72471+
72472+ if (((uwrapcompat.version != GRSECURITY_VERSION) &&
72473+ (uwrapcompat.version != 0x2901)) ||
72474+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
72475+ return -EINVAL;
72476+
72477+ uwrap->arg = compat_ptr(uwrapcompat.arg);
72478+ uwrap->version = uwrapcompat.version;
72479+ uwrap->size = sizeof(struct gr_arg);
72480+
72481+ return 0;
72482+}
72483+
72484+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
72485+{
72486+ struct gr_arg_compat argcompat;
72487+
72488+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
72489+ return -EFAULT;
72490+
72491+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
72492+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
72493+ arg->role_db.num_roles = argcompat.role_db.num_roles;
72494+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
72495+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
72496+ arg->role_db.num_objects = argcompat.role_db.num_objects;
72497+
72498+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
72499+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
72500+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
72501+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
72502+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
72503+ arg->segv_device = argcompat.segv_device;
72504+ arg->segv_inode = argcompat.segv_inode;
72505+ arg->segv_uid = argcompat.segv_uid;
72506+ arg->num_sprole_pws = argcompat.num_sprole_pws;
72507+ arg->mode = argcompat.mode;
72508+
72509+ return 0;
72510+}
72511+
72512+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
72513+{
72514+ struct acl_object_label_compat objcompat;
72515+
72516+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
72517+ return -EFAULT;
72518+
72519+ obj->filename = compat_ptr(objcompat.filename);
72520+ obj->inode = objcompat.inode;
72521+ obj->device = objcompat.device;
72522+ obj->mode = objcompat.mode;
72523+
72524+ obj->nested = compat_ptr(objcompat.nested);
72525+ obj->globbed = compat_ptr(objcompat.globbed);
72526+
72527+ obj->prev = compat_ptr(objcompat.prev);
72528+ obj->next = compat_ptr(objcompat.next);
72529+
72530+ return 0;
72531+}
72532+
72533+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
72534+{
72535+ unsigned int i;
72536+ struct acl_subject_label_compat subjcompat;
72537+
72538+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
72539+ return -EFAULT;
72540+
72541+ subj->filename = compat_ptr(subjcompat.filename);
72542+ subj->inode = subjcompat.inode;
72543+ subj->device = subjcompat.device;
72544+ subj->mode = subjcompat.mode;
72545+ subj->cap_mask = subjcompat.cap_mask;
72546+ subj->cap_lower = subjcompat.cap_lower;
72547+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
72548+
72549+ for (i = 0; i < GR_NLIMITS; i++) {
72550+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
72551+ subj->res[i].rlim_cur = RLIM_INFINITY;
72552+ else
72553+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
72554+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
72555+ subj->res[i].rlim_max = RLIM_INFINITY;
72556+ else
72557+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
72558+ }
72559+ subj->resmask = subjcompat.resmask;
72560+
72561+ subj->user_trans_type = subjcompat.user_trans_type;
72562+ subj->group_trans_type = subjcompat.group_trans_type;
72563+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
72564+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
72565+ subj->user_trans_num = subjcompat.user_trans_num;
72566+ subj->group_trans_num = subjcompat.group_trans_num;
72567+
72568+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
72569+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
72570+ subj->ip_type = subjcompat.ip_type;
72571+ subj->ips = compat_ptr(subjcompat.ips);
72572+ subj->ip_num = subjcompat.ip_num;
72573+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
72574+
72575+ subj->crashes = subjcompat.crashes;
72576+ subj->expires = subjcompat.expires;
72577+
72578+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
72579+ subj->hash = compat_ptr(subjcompat.hash);
72580+ subj->prev = compat_ptr(subjcompat.prev);
72581+ subj->next = compat_ptr(subjcompat.next);
72582+
72583+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
72584+ subj->obj_hash_size = subjcompat.obj_hash_size;
72585+ subj->pax_flags = subjcompat.pax_flags;
72586+
72587+ return 0;
72588+}
72589+
72590+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
72591+{
72592+ struct acl_role_label_compat rolecompat;
72593+
72594+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
72595+ return -EFAULT;
72596+
72597+ role->rolename = compat_ptr(rolecompat.rolename);
72598+ role->uidgid = rolecompat.uidgid;
72599+ role->roletype = rolecompat.roletype;
72600+
72601+ role->auth_attempts = rolecompat.auth_attempts;
72602+ role->expires = rolecompat.expires;
72603+
72604+ role->root_label = compat_ptr(rolecompat.root_label);
72605+ role->hash = compat_ptr(rolecompat.hash);
72606+
72607+ role->prev = compat_ptr(rolecompat.prev);
72608+ role->next = compat_ptr(rolecompat.next);
72609+
72610+ role->transitions = compat_ptr(rolecompat.transitions);
72611+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
72612+ role->domain_children = compat_ptr(rolecompat.domain_children);
72613+ role->domain_child_num = rolecompat.domain_child_num;
72614+
72615+ role->umask = rolecompat.umask;
72616+
72617+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
72618+ role->subj_hash_size = rolecompat.subj_hash_size;
72619+
72620+ return 0;
72621+}
72622+
72623+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
72624+{
72625+ struct role_allowed_ip_compat roleip_compat;
72626+
72627+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
72628+ return -EFAULT;
72629+
72630+ roleip->addr = roleip_compat.addr;
72631+ roleip->netmask = roleip_compat.netmask;
72632+
72633+ roleip->prev = compat_ptr(roleip_compat.prev);
72634+ roleip->next = compat_ptr(roleip_compat.next);
72635+
72636+ return 0;
72637+}
72638+
72639+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
72640+{
72641+ struct role_transition_compat trans_compat;
72642+
72643+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
72644+ return -EFAULT;
72645+
72646+ trans->rolename = compat_ptr(trans_compat.rolename);
72647+
72648+ trans->prev = compat_ptr(trans_compat.prev);
72649+ trans->next = compat_ptr(trans_compat.next);
72650+
72651+ return 0;
72652+
72653+}
72654+
72655+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
72656+{
72657+ struct gr_hash_struct_compat hash_compat;
72658+
72659+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
72660+ return -EFAULT;
72661+
72662+ hash->table = compat_ptr(hash_compat.table);
72663+ hash->nametable = compat_ptr(hash_compat.nametable);
72664+ hash->first = compat_ptr(hash_compat.first);
72665+
72666+ hash->table_size = hash_compat.table_size;
72667+ hash->used_size = hash_compat.used_size;
72668+
72669+ hash->type = hash_compat.type;
72670+
72671+ return 0;
72672+}
72673+
72674+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
72675+{
72676+ compat_uptr_t ptrcompat;
72677+
72678+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
72679+ return -EFAULT;
72680+
72681+ *(void **)ptr = compat_ptr(ptrcompat);
72682+
72683+ return 0;
72684+}
72685+
72686+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
72687+{
72688+ struct acl_ip_label_compat ip_compat;
72689+
72690+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
72691+ return -EFAULT;
72692+
72693+ ip->iface = compat_ptr(ip_compat.iface);
72694+ ip->addr = ip_compat.addr;
72695+ ip->netmask = ip_compat.netmask;
72696+ ip->low = ip_compat.low;
72697+ ip->high = ip_compat.high;
72698+ ip->mode = ip_compat.mode;
72699+ ip->type = ip_compat.type;
72700+
72701+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
72702+
72703+ ip->prev = compat_ptr(ip_compat.prev);
72704+ ip->next = compat_ptr(ip_compat.next);
72705+
72706+ return 0;
72707+}
72708+
72709+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
72710+{
72711+ struct sprole_pw_compat pw_compat;
72712+
72713+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
72714+ return -EFAULT;
72715+
72716+ pw->rolename = compat_ptr(pw_compat.rolename);
72717+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
72718+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
72719+
72720+ return 0;
72721+}
72722+
72723+size_t get_gr_arg_wrapper_size_compat(void)
72724+{
72725+ return sizeof(struct gr_arg_wrapper_compat);
72726+}
72727+
72728diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
72729new file mode 100644
72730index 0000000..4008fdc
72731--- /dev/null
72732+++ b/grsecurity/gracl_fs.c
72733@@ -0,0 +1,445 @@
72734+#include <linux/kernel.h>
72735+#include <linux/sched.h>
72736+#include <linux/types.h>
72737+#include <linux/fs.h>
72738+#include <linux/file.h>
72739+#include <linux/stat.h>
72740+#include <linux/grsecurity.h>
72741+#include <linux/grinternal.h>
72742+#include <linux/gracl.h>
72743+
72744+umode_t
72745+gr_acl_umask(void)
72746+{
72747+ if (unlikely(!gr_acl_is_enabled()))
72748+ return 0;
72749+
72750+ return current->role->umask;
72751+}
72752+
72753+__u32
72754+gr_acl_handle_hidden_file(const struct dentry * dentry,
72755+ const struct vfsmount * mnt)
72756+{
72757+ __u32 mode;
72758+
72759+ if (unlikely(d_is_negative(dentry)))
72760+ return GR_FIND;
72761+
72762+ mode =
72763+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
72764+
72765+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
72766+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
72767+ return mode;
72768+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
72769+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
72770+ return 0;
72771+ } else if (unlikely(!(mode & GR_FIND)))
72772+ return 0;
72773+
72774+ return GR_FIND;
72775+}
72776+
72777+__u32
72778+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
72779+ int acc_mode)
72780+{
72781+ __u32 reqmode = GR_FIND;
72782+ __u32 mode;
72783+
72784+ if (unlikely(d_is_negative(dentry)))
72785+ return reqmode;
72786+
72787+ if (acc_mode & MAY_APPEND)
72788+ reqmode |= GR_APPEND;
72789+ else if (acc_mode & MAY_WRITE)
72790+ reqmode |= GR_WRITE;
72791+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
72792+ reqmode |= GR_READ;
72793+
72794+ mode =
72795+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
72796+ mnt);
72797+
72798+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72799+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
72800+ reqmode & GR_READ ? " reading" : "",
72801+ reqmode & GR_WRITE ? " writing" : reqmode &
72802+ GR_APPEND ? " appending" : "");
72803+ return reqmode;
72804+ } else
72805+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72806+ {
72807+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
72808+ reqmode & GR_READ ? " reading" : "",
72809+ reqmode & GR_WRITE ? " writing" : reqmode &
72810+ GR_APPEND ? " appending" : "");
72811+ return 0;
72812+ } else if (unlikely((mode & reqmode) != reqmode))
72813+ return 0;
72814+
72815+ return reqmode;
72816+}
72817+
72818+__u32
72819+gr_acl_handle_creat(const struct dentry * dentry,
72820+ const struct dentry * p_dentry,
72821+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
72822+ const int imode)
72823+{
72824+ __u32 reqmode = GR_WRITE | GR_CREATE;
72825+ __u32 mode;
72826+
72827+ if (acc_mode & MAY_APPEND)
72828+ reqmode |= GR_APPEND;
72829+ // if a directory was required or the directory already exists, then
72830+ // don't count this open as a read
72831+ if ((acc_mode & MAY_READ) &&
72832+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
72833+ reqmode |= GR_READ;
72834+ if ((open_flags & O_CREAT) &&
72835+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
72836+ reqmode |= GR_SETID;
72837+
72838+ mode =
72839+ gr_check_create(dentry, p_dentry, p_mnt,
72840+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
72841+
72842+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72843+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
72844+ reqmode & GR_READ ? " reading" : "",
72845+ reqmode & GR_WRITE ? " writing" : reqmode &
72846+ GR_APPEND ? " appending" : "");
72847+ return reqmode;
72848+ } else
72849+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72850+ {
72851+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
72852+ reqmode & GR_READ ? " reading" : "",
72853+ reqmode & GR_WRITE ? " writing" : reqmode &
72854+ GR_APPEND ? " appending" : "");
72855+ return 0;
72856+ } else if (unlikely((mode & reqmode) != reqmode))
72857+ return 0;
72858+
72859+ return reqmode;
72860+}
72861+
72862+__u32
72863+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
72864+ const int fmode)
72865+{
72866+ __u32 mode, reqmode = GR_FIND;
72867+
72868+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
72869+ reqmode |= GR_EXEC;
72870+ if (fmode & S_IWOTH)
72871+ reqmode |= GR_WRITE;
72872+ if (fmode & S_IROTH)
72873+ reqmode |= GR_READ;
72874+
72875+ mode =
72876+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
72877+ mnt);
72878+
72879+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72880+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
72881+ reqmode & GR_READ ? " reading" : "",
72882+ reqmode & GR_WRITE ? " writing" : "",
72883+ reqmode & GR_EXEC ? " executing" : "");
72884+ return reqmode;
72885+ } else
72886+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72887+ {
72888+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
72889+ reqmode & GR_READ ? " reading" : "",
72890+ reqmode & GR_WRITE ? " writing" : "",
72891+ reqmode & GR_EXEC ? " executing" : "");
72892+ return 0;
72893+ } else if (unlikely((mode & reqmode) != reqmode))
72894+ return 0;
72895+
72896+ return reqmode;
72897+}
72898+
72899+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
72900+{
72901+ __u32 mode;
72902+
72903+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
72904+
72905+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
72906+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
72907+ return mode;
72908+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
72909+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
72910+ return 0;
72911+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
72912+ return 0;
72913+
72914+ return (reqmode);
72915+}
72916+
72917+__u32
72918+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
72919+{
72920+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
72921+}
72922+
72923+__u32
72924+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
72925+{
72926+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
72927+}
72928+
72929+__u32
72930+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
72931+{
72932+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
72933+}
72934+
72935+__u32
72936+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
72937+{
72938+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
72939+}
72940+
72941+__u32
72942+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
72943+ umode_t *modeptr)
72944+{
72945+ umode_t mode;
72946+
72947+ *modeptr &= ~gr_acl_umask();
72948+ mode = *modeptr;
72949+
72950+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
72951+ return 1;
72952+
72953+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
72954+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
72955+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
72956+ GR_CHMOD_ACL_MSG);
72957+ } else {
72958+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
72959+ }
72960+}
72961+
72962+__u32
72963+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
72964+{
72965+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
72966+}
72967+
72968+__u32
72969+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
72970+{
72971+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
72972+}
72973+
72974+__u32
72975+gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
72976+{
72977+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
72978+}
72979+
72980+__u32
72981+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
72982+{
72983+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
72984+}
72985+
72986+__u32
72987+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
72988+{
72989+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
72990+ GR_UNIXCONNECT_ACL_MSG);
72991+}
72992+
72993+/* hardlinks require at minimum create and link permission,
72994+ any additional privilege required is based on the
72995+ privilege of the file being linked to
72996+*/
72997+__u32
72998+gr_acl_handle_link(const struct dentry * new_dentry,
72999+ const struct dentry * parent_dentry,
73000+ const struct vfsmount * parent_mnt,
73001+ const struct dentry * old_dentry,
73002+ const struct vfsmount * old_mnt, const struct filename *to)
73003+{
73004+ __u32 mode;
73005+ __u32 needmode = GR_CREATE | GR_LINK;
73006+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
73007+
73008+ mode =
73009+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
73010+ old_mnt);
73011+
73012+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
73013+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
73014+ return mode;
73015+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
73016+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
73017+ return 0;
73018+ } else if (unlikely((mode & needmode) != needmode))
73019+ return 0;
73020+
73021+ return 1;
73022+}
73023+
73024+__u32
73025+gr_acl_handle_symlink(const struct dentry * new_dentry,
73026+ const struct dentry * parent_dentry,
73027+ const struct vfsmount * parent_mnt, const struct filename *from)
73028+{
73029+ __u32 needmode = GR_WRITE | GR_CREATE;
73030+ __u32 mode;
73031+
73032+ mode =
73033+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
73034+ GR_CREATE | GR_AUDIT_CREATE |
73035+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
73036+
73037+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
73038+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
73039+ return mode;
73040+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
73041+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
73042+ return 0;
73043+ } else if (unlikely((mode & needmode) != needmode))
73044+ return 0;
73045+
73046+ return (GR_WRITE | GR_CREATE);
73047+}
73048+
73049+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)
73050+{
73051+ __u32 mode;
73052+
73053+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
73054+
73055+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
73056+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
73057+ return mode;
73058+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
73059+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
73060+ return 0;
73061+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
73062+ return 0;
73063+
73064+ return (reqmode);
73065+}
73066+
73067+__u32
73068+gr_acl_handle_mknod(const struct dentry * new_dentry,
73069+ const struct dentry * parent_dentry,
73070+ const struct vfsmount * parent_mnt,
73071+ const int mode)
73072+{
73073+ __u32 reqmode = GR_WRITE | GR_CREATE;
73074+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
73075+ reqmode |= GR_SETID;
73076+
73077+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
73078+ reqmode, GR_MKNOD_ACL_MSG);
73079+}
73080+
73081+__u32
73082+gr_acl_handle_mkdir(const struct dentry *new_dentry,
73083+ const struct dentry *parent_dentry,
73084+ const struct vfsmount *parent_mnt)
73085+{
73086+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
73087+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
73088+}
73089+
73090+#define RENAME_CHECK_SUCCESS(old, new) \
73091+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
73092+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
73093+
73094+int
73095+gr_acl_handle_rename(struct dentry *new_dentry,
73096+ struct dentry *parent_dentry,
73097+ const struct vfsmount *parent_mnt,
73098+ struct dentry *old_dentry,
73099+ struct inode *old_parent_inode,
73100+ struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags)
73101+{
73102+ __u32 comp1, comp2;
73103+ int error = 0;
73104+
73105+ if (unlikely(!gr_acl_is_enabled()))
73106+ return 0;
73107+
73108+ if (flags & RENAME_EXCHANGE) {
73109+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
73110+ GR_AUDIT_READ | GR_AUDIT_WRITE |
73111+ GR_SUPPRESS, parent_mnt);
73112+ comp2 =
73113+ gr_search_file(old_dentry,
73114+ GR_READ | GR_WRITE | GR_AUDIT_READ |
73115+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
73116+ } else if (d_is_negative(new_dentry)) {
73117+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
73118+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
73119+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
73120+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
73121+ GR_DELETE | GR_AUDIT_DELETE |
73122+ GR_AUDIT_READ | GR_AUDIT_WRITE |
73123+ GR_SUPPRESS, old_mnt);
73124+ } else {
73125+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
73126+ GR_CREATE | GR_DELETE |
73127+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
73128+ GR_AUDIT_READ | GR_AUDIT_WRITE |
73129+ GR_SUPPRESS, parent_mnt);
73130+ comp2 =
73131+ gr_search_file(old_dentry,
73132+ GR_READ | GR_WRITE | GR_AUDIT_READ |
73133+ GR_DELETE | GR_AUDIT_DELETE |
73134+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
73135+ }
73136+
73137+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
73138+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
73139+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
73140+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
73141+ && !(comp2 & GR_SUPPRESS)) {
73142+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
73143+ error = -EACCES;
73144+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
73145+ error = -EACCES;
73146+
73147+ return error;
73148+}
73149+
73150+void
73151+gr_acl_handle_exit(void)
73152+{
73153+ u16 id;
73154+ char *rolename;
73155+
73156+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
73157+ !(current->role->roletype & GR_ROLE_PERSIST))) {
73158+ id = current->acl_role_id;
73159+ rolename = current->role->rolename;
73160+ gr_set_acls(1);
73161+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
73162+ }
73163+
73164+ gr_put_exec_file(current);
73165+ return;
73166+}
73167+
73168+int
73169+gr_acl_handle_procpidmem(const struct task_struct *task)
73170+{
73171+ if (unlikely(!gr_acl_is_enabled()))
73172+ return 0;
73173+
73174+ if (task != current && task->acl->mode & GR_PROTPROCFD)
73175+ return -EACCES;
73176+
73177+ return 0;
73178+}
73179diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
73180new file mode 100644
73181index 0000000..f056b81
73182--- /dev/null
73183+++ b/grsecurity/gracl_ip.c
73184@@ -0,0 +1,386 @@
73185+#include <linux/kernel.h>
73186+#include <asm/uaccess.h>
73187+#include <asm/errno.h>
73188+#include <net/sock.h>
73189+#include <linux/file.h>
73190+#include <linux/fs.h>
73191+#include <linux/net.h>
73192+#include <linux/in.h>
73193+#include <linux/skbuff.h>
73194+#include <linux/ip.h>
73195+#include <linux/udp.h>
73196+#include <linux/types.h>
73197+#include <linux/sched.h>
73198+#include <linux/netdevice.h>
73199+#include <linux/inetdevice.h>
73200+#include <linux/gracl.h>
73201+#include <linux/grsecurity.h>
73202+#include <linux/grinternal.h>
73203+
73204+#define GR_BIND 0x01
73205+#define GR_CONNECT 0x02
73206+#define GR_INVERT 0x04
73207+#define GR_BINDOVERRIDE 0x08
73208+#define GR_CONNECTOVERRIDE 0x10
73209+#define GR_SOCK_FAMILY 0x20
73210+
73211+static const char * gr_protocols[IPPROTO_MAX] = {
73212+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
73213+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
73214+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
73215+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
73216+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
73217+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
73218+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
73219+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
73220+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
73221+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
73222+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
73223+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
73224+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
73225+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
73226+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
73227+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
73228+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
73229+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
73230+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
73231+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
73232+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
73233+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
73234+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
73235+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
73236+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
73237+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
73238+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
73239+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
73240+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
73241+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
73242+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
73243+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
73244+ };
73245+
73246+static const char * gr_socktypes[SOCK_MAX] = {
73247+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
73248+ "unknown:7", "unknown:8", "unknown:9", "packet"
73249+ };
73250+
73251+static const char * gr_sockfamilies[AF_MAX+1] = {
73252+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
73253+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
73254+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
73255+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
73256+ };
73257+
73258+const char *
73259+gr_proto_to_name(unsigned char proto)
73260+{
73261+ return gr_protocols[proto];
73262+}
73263+
73264+const char *
73265+gr_socktype_to_name(unsigned char type)
73266+{
73267+ return gr_socktypes[type];
73268+}
73269+
73270+const char *
73271+gr_sockfamily_to_name(unsigned char family)
73272+{
73273+ return gr_sockfamilies[family];
73274+}
73275+
73276+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
73277+
73278+int
73279+gr_search_socket(const int domain, const int type, const int protocol)
73280+{
73281+ struct acl_subject_label *curr;
73282+ const struct cred *cred = current_cred();
73283+
73284+ if (unlikely(!gr_acl_is_enabled()))
73285+ goto exit;
73286+
73287+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
73288+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
73289+ goto exit; // let the kernel handle it
73290+
73291+ curr = current->acl;
73292+
73293+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
73294+ /* the family is allowed, if this is PF_INET allow it only if
73295+ the extra sock type/protocol checks pass */
73296+ if (domain == PF_INET)
73297+ goto inet_check;
73298+ goto exit;
73299+ } else {
73300+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73301+ __u32 fakeip = 0;
73302+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73303+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
73304+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
73305+ gr_to_filename(current->exec_file->f_path.dentry,
73306+ current->exec_file->f_path.mnt) :
73307+ curr->filename, curr->filename,
73308+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
73309+ &current->signal->saved_ip);
73310+ goto exit;
73311+ }
73312+ goto exit_fail;
73313+ }
73314+
73315+inet_check:
73316+ /* the rest of this checking is for IPv4 only */
73317+ if (!curr->ips)
73318+ goto exit;
73319+
73320+ if ((curr->ip_type & (1U << type)) &&
73321+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
73322+ goto exit;
73323+
73324+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73325+ /* we don't place acls on raw sockets , and sometimes
73326+ dgram/ip sockets are opened for ioctl and not
73327+ bind/connect, so we'll fake a bind learn log */
73328+ if (type == SOCK_RAW || type == SOCK_PACKET) {
73329+ __u32 fakeip = 0;
73330+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73331+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
73332+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
73333+ gr_to_filename(current->exec_file->f_path.dentry,
73334+ current->exec_file->f_path.mnt) :
73335+ curr->filename, curr->filename,
73336+ &fakeip, 0, type,
73337+ protocol, GR_CONNECT, &current->signal->saved_ip);
73338+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
73339+ __u32 fakeip = 0;
73340+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73341+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
73342+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
73343+ gr_to_filename(current->exec_file->f_path.dentry,
73344+ current->exec_file->f_path.mnt) :
73345+ curr->filename, curr->filename,
73346+ &fakeip, 0, type,
73347+ protocol, GR_BIND, &current->signal->saved_ip);
73348+ }
73349+ /* we'll log when they use connect or bind */
73350+ goto exit;
73351+ }
73352+
73353+exit_fail:
73354+ if (domain == PF_INET)
73355+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
73356+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
73357+ else if (rcu_access_pointer(net_families[domain]) != NULL)
73358+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
73359+ gr_socktype_to_name(type), protocol);
73360+
73361+ return 0;
73362+exit:
73363+ return 1;
73364+}
73365+
73366+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)
73367+{
73368+ if ((ip->mode & mode) &&
73369+ (ip_port >= ip->low) &&
73370+ (ip_port <= ip->high) &&
73371+ ((ntohl(ip_addr) & our_netmask) ==
73372+ (ntohl(our_addr) & our_netmask))
73373+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
73374+ && (ip->type & (1U << type))) {
73375+ if (ip->mode & GR_INVERT)
73376+ return 2; // specifically denied
73377+ else
73378+ return 1; // allowed
73379+ }
73380+
73381+ return 0; // not specifically allowed, may continue parsing
73382+}
73383+
73384+static int
73385+gr_search_connectbind(const int full_mode, struct sock *sk,
73386+ struct sockaddr_in *addr, const int type)
73387+{
73388+ char iface[IFNAMSIZ] = {0};
73389+ struct acl_subject_label *curr;
73390+ struct acl_ip_label *ip;
73391+ struct inet_sock *isk;
73392+ struct net_device *dev;
73393+ struct in_device *idev;
73394+ unsigned long i;
73395+ int ret;
73396+ int mode = full_mode & (GR_BIND | GR_CONNECT);
73397+ __u32 ip_addr = 0;
73398+ __u32 our_addr;
73399+ __u32 our_netmask;
73400+ char *p;
73401+ __u16 ip_port = 0;
73402+ const struct cred *cred = current_cred();
73403+
73404+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
73405+ return 0;
73406+
73407+ curr = current->acl;
73408+ isk = inet_sk(sk);
73409+
73410+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
73411+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
73412+ addr->sin_addr.s_addr = curr->inaddr_any_override;
73413+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
73414+ struct sockaddr_in saddr;
73415+ int err;
73416+
73417+ saddr.sin_family = AF_INET;
73418+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
73419+ saddr.sin_port = isk->inet_sport;
73420+
73421+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
73422+ if (err)
73423+ return err;
73424+
73425+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
73426+ if (err)
73427+ return err;
73428+ }
73429+
73430+ if (!curr->ips)
73431+ return 0;
73432+
73433+ ip_addr = addr->sin_addr.s_addr;
73434+ ip_port = ntohs(addr->sin_port);
73435+
73436+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73437+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73438+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
73439+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
73440+ gr_to_filename(current->exec_file->f_path.dentry,
73441+ current->exec_file->f_path.mnt) :
73442+ curr->filename, curr->filename,
73443+ &ip_addr, ip_port, type,
73444+ sk->sk_protocol, mode, &current->signal->saved_ip);
73445+ return 0;
73446+ }
73447+
73448+ for (i = 0; i < curr->ip_num; i++) {
73449+ ip = *(curr->ips + i);
73450+ if (ip->iface != NULL) {
73451+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
73452+ p = strchr(iface, ':');
73453+ if (p != NULL)
73454+ *p = '\0';
73455+ dev = dev_get_by_name(sock_net(sk), iface);
73456+ if (dev == NULL)
73457+ continue;
73458+ idev = in_dev_get(dev);
73459+ if (idev == NULL) {
73460+ dev_put(dev);
73461+ continue;
73462+ }
73463+ rcu_read_lock();
73464+ for_ifa(idev) {
73465+ if (!strcmp(ip->iface, ifa->ifa_label)) {
73466+ our_addr = ifa->ifa_address;
73467+ our_netmask = 0xffffffff;
73468+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
73469+ if (ret == 1) {
73470+ rcu_read_unlock();
73471+ in_dev_put(idev);
73472+ dev_put(dev);
73473+ return 0;
73474+ } else if (ret == 2) {
73475+ rcu_read_unlock();
73476+ in_dev_put(idev);
73477+ dev_put(dev);
73478+ goto denied;
73479+ }
73480+ }
73481+ } endfor_ifa(idev);
73482+ rcu_read_unlock();
73483+ in_dev_put(idev);
73484+ dev_put(dev);
73485+ } else {
73486+ our_addr = ip->addr;
73487+ our_netmask = ip->netmask;
73488+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
73489+ if (ret == 1)
73490+ return 0;
73491+ else if (ret == 2)
73492+ goto denied;
73493+ }
73494+ }
73495+
73496+denied:
73497+ if (mode == GR_BIND)
73498+ 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));
73499+ else if (mode == GR_CONNECT)
73500+ 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));
73501+
73502+ return -EACCES;
73503+}
73504+
73505+int
73506+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
73507+{
73508+ /* always allow disconnection of dgram sockets with connect */
73509+ if (addr->sin_family == AF_UNSPEC)
73510+ return 0;
73511+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
73512+}
73513+
73514+int
73515+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
73516+{
73517+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
73518+}
73519+
73520+int gr_search_listen(struct socket *sock)
73521+{
73522+ struct sock *sk = sock->sk;
73523+ struct sockaddr_in addr;
73524+
73525+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
73526+ addr.sin_port = inet_sk(sk)->inet_sport;
73527+
73528+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
73529+}
73530+
73531+int gr_search_accept(struct socket *sock)
73532+{
73533+ struct sock *sk = sock->sk;
73534+ struct sockaddr_in addr;
73535+
73536+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
73537+ addr.sin_port = inet_sk(sk)->inet_sport;
73538+
73539+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
73540+}
73541+
73542+int
73543+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
73544+{
73545+ if (addr)
73546+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
73547+ else {
73548+ struct sockaddr_in sin;
73549+ const struct inet_sock *inet = inet_sk(sk);
73550+
73551+ sin.sin_addr.s_addr = inet->inet_daddr;
73552+ sin.sin_port = inet->inet_dport;
73553+
73554+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
73555+ }
73556+}
73557+
73558+int
73559+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
73560+{
73561+ struct sockaddr_in sin;
73562+
73563+ if (unlikely(skb->len < sizeof (struct udphdr)))
73564+ return 0; // skip this packet
73565+
73566+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
73567+ sin.sin_port = udp_hdr(skb)->source;
73568+
73569+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
73570+}
73571diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
73572new file mode 100644
73573index 0000000..25f54ef
73574--- /dev/null
73575+++ b/grsecurity/gracl_learn.c
73576@@ -0,0 +1,207 @@
73577+#include <linux/kernel.h>
73578+#include <linux/mm.h>
73579+#include <linux/sched.h>
73580+#include <linux/poll.h>
73581+#include <linux/string.h>
73582+#include <linux/file.h>
73583+#include <linux/types.h>
73584+#include <linux/vmalloc.h>
73585+#include <linux/grinternal.h>
73586+
73587+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
73588+ size_t count, loff_t *ppos);
73589+extern int gr_acl_is_enabled(void);
73590+
73591+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
73592+static int gr_learn_attached;
73593+
73594+/* use a 512k buffer */
73595+#define LEARN_BUFFER_SIZE (512 * 1024)
73596+
73597+static DEFINE_SPINLOCK(gr_learn_lock);
73598+static DEFINE_MUTEX(gr_learn_user_mutex);
73599+
73600+/* we need to maintain two buffers, so that the kernel context of grlearn
73601+ uses a semaphore around the userspace copying, and the other kernel contexts
73602+ use a spinlock when copying into the buffer, since they cannot sleep
73603+*/
73604+static char *learn_buffer;
73605+static char *learn_buffer_user;
73606+static int learn_buffer_len;
73607+static int learn_buffer_user_len;
73608+
73609+static ssize_t
73610+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
73611+{
73612+ DECLARE_WAITQUEUE(wait, current);
73613+ ssize_t retval = 0;
73614+
73615+ add_wait_queue(&learn_wait, &wait);
73616+ set_current_state(TASK_INTERRUPTIBLE);
73617+ do {
73618+ mutex_lock(&gr_learn_user_mutex);
73619+ spin_lock(&gr_learn_lock);
73620+ if (learn_buffer_len)
73621+ break;
73622+ spin_unlock(&gr_learn_lock);
73623+ mutex_unlock(&gr_learn_user_mutex);
73624+ if (file->f_flags & O_NONBLOCK) {
73625+ retval = -EAGAIN;
73626+ goto out;
73627+ }
73628+ if (signal_pending(current)) {
73629+ retval = -ERESTARTSYS;
73630+ goto out;
73631+ }
73632+
73633+ schedule();
73634+ } while (1);
73635+
73636+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
73637+ learn_buffer_user_len = learn_buffer_len;
73638+ retval = learn_buffer_len;
73639+ learn_buffer_len = 0;
73640+
73641+ spin_unlock(&gr_learn_lock);
73642+
73643+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
73644+ retval = -EFAULT;
73645+
73646+ mutex_unlock(&gr_learn_user_mutex);
73647+out:
73648+ set_current_state(TASK_RUNNING);
73649+ remove_wait_queue(&learn_wait, &wait);
73650+ return retval;
73651+}
73652+
73653+static unsigned int
73654+poll_learn(struct file * file, poll_table * wait)
73655+{
73656+ poll_wait(file, &learn_wait, wait);
73657+
73658+ if (learn_buffer_len)
73659+ return (POLLIN | POLLRDNORM);
73660+
73661+ return 0;
73662+}
73663+
73664+void
73665+gr_clear_learn_entries(void)
73666+{
73667+ char *tmp;
73668+
73669+ mutex_lock(&gr_learn_user_mutex);
73670+ spin_lock(&gr_learn_lock);
73671+ tmp = learn_buffer;
73672+ learn_buffer = NULL;
73673+ spin_unlock(&gr_learn_lock);
73674+ if (tmp)
73675+ vfree(tmp);
73676+ if (learn_buffer_user != NULL) {
73677+ vfree(learn_buffer_user);
73678+ learn_buffer_user = NULL;
73679+ }
73680+ learn_buffer_len = 0;
73681+ mutex_unlock(&gr_learn_user_mutex);
73682+
73683+ return;
73684+}
73685+
73686+void
73687+gr_add_learn_entry(const char *fmt, ...)
73688+{
73689+ va_list args;
73690+ unsigned int len;
73691+
73692+ if (!gr_learn_attached)
73693+ return;
73694+
73695+ spin_lock(&gr_learn_lock);
73696+
73697+ /* leave a gap at the end so we know when it's "full" but don't have to
73698+ compute the exact length of the string we're trying to append
73699+ */
73700+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
73701+ spin_unlock(&gr_learn_lock);
73702+ wake_up_interruptible(&learn_wait);
73703+ return;
73704+ }
73705+ if (learn_buffer == NULL) {
73706+ spin_unlock(&gr_learn_lock);
73707+ return;
73708+ }
73709+
73710+ va_start(args, fmt);
73711+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
73712+ va_end(args);
73713+
73714+ learn_buffer_len += len + 1;
73715+
73716+ spin_unlock(&gr_learn_lock);
73717+ wake_up_interruptible(&learn_wait);
73718+
73719+ return;
73720+}
73721+
73722+static int
73723+open_learn(struct inode *inode, struct file *file)
73724+{
73725+ if (file->f_mode & FMODE_READ && gr_learn_attached)
73726+ return -EBUSY;
73727+ if (file->f_mode & FMODE_READ) {
73728+ int retval = 0;
73729+ mutex_lock(&gr_learn_user_mutex);
73730+ if (learn_buffer == NULL)
73731+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
73732+ if (learn_buffer_user == NULL)
73733+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
73734+ if (learn_buffer == NULL) {
73735+ retval = -ENOMEM;
73736+ goto out_error;
73737+ }
73738+ if (learn_buffer_user == NULL) {
73739+ retval = -ENOMEM;
73740+ goto out_error;
73741+ }
73742+ learn_buffer_len = 0;
73743+ learn_buffer_user_len = 0;
73744+ gr_learn_attached = 1;
73745+out_error:
73746+ mutex_unlock(&gr_learn_user_mutex);
73747+ return retval;
73748+ }
73749+ return 0;
73750+}
73751+
73752+static int
73753+close_learn(struct inode *inode, struct file *file)
73754+{
73755+ if (file->f_mode & FMODE_READ) {
73756+ char *tmp = NULL;
73757+ mutex_lock(&gr_learn_user_mutex);
73758+ spin_lock(&gr_learn_lock);
73759+ tmp = learn_buffer;
73760+ learn_buffer = NULL;
73761+ spin_unlock(&gr_learn_lock);
73762+ if (tmp)
73763+ vfree(tmp);
73764+ if (learn_buffer_user != NULL) {
73765+ vfree(learn_buffer_user);
73766+ learn_buffer_user = NULL;
73767+ }
73768+ learn_buffer_len = 0;
73769+ learn_buffer_user_len = 0;
73770+ gr_learn_attached = 0;
73771+ mutex_unlock(&gr_learn_user_mutex);
73772+ }
73773+
73774+ return 0;
73775+}
73776+
73777+const struct file_operations grsec_fops = {
73778+ .read = read_learn,
73779+ .write = write_grsec_handler,
73780+ .open = open_learn,
73781+ .release = close_learn,
73782+ .poll = poll_learn,
73783+};
73784diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
73785new file mode 100644
73786index 0000000..3f8ade0
73787--- /dev/null
73788+++ b/grsecurity/gracl_policy.c
73789@@ -0,0 +1,1782 @@
73790+#include <linux/kernel.h>
73791+#include <linux/module.h>
73792+#include <linux/sched.h>
73793+#include <linux/mm.h>
73794+#include <linux/file.h>
73795+#include <linux/fs.h>
73796+#include <linux/namei.h>
73797+#include <linux/mount.h>
73798+#include <linux/tty.h>
73799+#include <linux/proc_fs.h>
73800+#include <linux/lglock.h>
73801+#include <linux/slab.h>
73802+#include <linux/vmalloc.h>
73803+#include <linux/types.h>
73804+#include <linux/sysctl.h>
73805+#include <linux/netdevice.h>
73806+#include <linux/ptrace.h>
73807+#include <linux/gracl.h>
73808+#include <linux/gralloc.h>
73809+#include <linux/security.h>
73810+#include <linux/grinternal.h>
73811+#include <linux/pid_namespace.h>
73812+#include <linux/stop_machine.h>
73813+#include <linux/fdtable.h>
73814+#include <linux/percpu.h>
73815+#include <linux/lglock.h>
73816+#include <linux/hugetlb.h>
73817+#include <linux/posix-timers.h>
73818+#include "../fs/mount.h"
73819+
73820+#include <asm/uaccess.h>
73821+#include <asm/errno.h>
73822+#include <asm/mman.h>
73823+
73824+extern struct gr_policy_state *polstate;
73825+
73826+#define FOR_EACH_ROLE_START(role) \
73827+ role = polstate->role_list; \
73828+ while (role) {
73829+
73830+#define FOR_EACH_ROLE_END(role) \
73831+ role = role->prev; \
73832+ }
73833+
73834+struct path gr_real_root;
73835+
73836+extern struct gr_alloc_state *current_alloc_state;
73837+
73838+u16 acl_sp_role_value;
73839+
73840+static DEFINE_MUTEX(gr_dev_mutex);
73841+
73842+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
73843+extern void gr_clear_learn_entries(void);
73844+
73845+struct gr_arg *gr_usermode __read_only;
73846+unsigned char *gr_system_salt __read_only;
73847+unsigned char *gr_system_sum __read_only;
73848+
73849+static unsigned int gr_auth_attempts = 0;
73850+static unsigned long gr_auth_expires = 0UL;
73851+
73852+struct acl_object_label *fakefs_obj_rw;
73853+struct acl_object_label *fakefs_obj_rwx;
73854+
73855+extern int gr_init_uidset(void);
73856+extern void gr_free_uidset(void);
73857+extern void gr_remove_uid(uid_t uid);
73858+extern int gr_find_uid(uid_t uid);
73859+
73860+extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
73861+extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
73862+extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
73863+extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
73864+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);
73865+extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
73866+extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
73867+extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
73868+extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
73869+extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
73870+extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
73871+extern void assign_special_role(const char *rolename);
73872+extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
73873+extern int gr_rbac_disable(void *unused);
73874+extern void gr_enable_rbac_system(void);
73875+
73876+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
73877+{
73878+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
73879+ return -EFAULT;
73880+
73881+ return 0;
73882+}
73883+
73884+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
73885+{
73886+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
73887+ return -EFAULT;
73888+
73889+ return 0;
73890+}
73891+
73892+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
73893+{
73894+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
73895+ return -EFAULT;
73896+
73897+ return 0;
73898+}
73899+
73900+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
73901+{
73902+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
73903+ return -EFAULT;
73904+
73905+ return 0;
73906+}
73907+
73908+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
73909+{
73910+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
73911+ return -EFAULT;
73912+
73913+ return 0;
73914+}
73915+
73916+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
73917+{
73918+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
73919+ return -EFAULT;
73920+
73921+ return 0;
73922+}
73923+
73924+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
73925+{
73926+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
73927+ return -EFAULT;
73928+
73929+ return 0;
73930+}
73931+
73932+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
73933+{
73934+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
73935+ return -EFAULT;
73936+
73937+ return 0;
73938+}
73939+
73940+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
73941+{
73942+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
73943+ return -EFAULT;
73944+
73945+ return 0;
73946+}
73947+
73948+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
73949+{
73950+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
73951+ return -EFAULT;
73952+
73953+ if (((uwrap->version != GRSECURITY_VERSION) &&
73954+ (uwrap->version != 0x2901)) ||
73955+ (uwrap->size != sizeof(struct gr_arg)))
73956+ return -EINVAL;
73957+
73958+ return 0;
73959+}
73960+
73961+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
73962+{
73963+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
73964+ return -EFAULT;
73965+
73966+ return 0;
73967+}
73968+
73969+static size_t get_gr_arg_wrapper_size_normal(void)
73970+{
73971+ return sizeof(struct gr_arg_wrapper);
73972+}
73973+
73974+#ifdef CONFIG_COMPAT
73975+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
73976+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
73977+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
73978+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
73979+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
73980+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
73981+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
73982+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
73983+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
73984+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
73985+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
73986+extern size_t get_gr_arg_wrapper_size_compat(void);
73987+
73988+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
73989+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
73990+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
73991+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
73992+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
73993+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
73994+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
73995+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
73996+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
73997+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
73998+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
73999+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
74000+
74001+#else
74002+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
74003+#define copy_gr_arg copy_gr_arg_normal
74004+#define copy_gr_hash_struct copy_gr_hash_struct_normal
74005+#define copy_acl_object_label copy_acl_object_label_normal
74006+#define copy_acl_subject_label copy_acl_subject_label_normal
74007+#define copy_acl_role_label copy_acl_role_label_normal
74008+#define copy_acl_ip_label copy_acl_ip_label_normal
74009+#define copy_pointer_from_array copy_pointer_from_array_normal
74010+#define copy_sprole_pw copy_sprole_pw_normal
74011+#define copy_role_transition copy_role_transition_normal
74012+#define copy_role_allowed_ip copy_role_allowed_ip_normal
74013+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
74014+#endif
74015+
74016+static struct acl_subject_label *
74017+lookup_subject_map(const struct acl_subject_label *userp)
74018+{
74019+ unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
74020+ struct subject_map *match;
74021+
74022+ match = polstate->subj_map_set.s_hash[index];
74023+
74024+ while (match && match->user != userp)
74025+ match = match->next;
74026+
74027+ if (match != NULL)
74028+ return match->kernel;
74029+ else
74030+ return NULL;
74031+}
74032+
74033+static void
74034+insert_subj_map_entry(struct subject_map *subjmap)
74035+{
74036+ unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
74037+ struct subject_map **curr;
74038+
74039+ subjmap->prev = NULL;
74040+
74041+ curr = &polstate->subj_map_set.s_hash[index];
74042+ if (*curr != NULL)
74043+ (*curr)->prev = subjmap;
74044+
74045+ subjmap->next = *curr;
74046+ *curr = subjmap;
74047+
74048+ return;
74049+}
74050+
74051+static void
74052+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
74053+{
74054+ unsigned int index =
74055+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
74056+ struct acl_role_label **curr;
74057+ struct acl_role_label *tmp, *tmp2;
74058+
74059+ curr = &polstate->acl_role_set.r_hash[index];
74060+
74061+ /* simple case, slot is empty, just set it to our role */
74062+ if (*curr == NULL) {
74063+ *curr = role;
74064+ } else {
74065+ /* example:
74066+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
74067+ 2 -> 3
74068+ */
74069+ /* first check to see if we can already be reached via this slot */
74070+ tmp = *curr;
74071+ while (tmp && tmp != role)
74072+ tmp = tmp->next;
74073+ if (tmp == role) {
74074+ /* we don't need to add ourselves to this slot's chain */
74075+ return;
74076+ }
74077+ /* we need to add ourselves to this chain, two cases */
74078+ if (role->next == NULL) {
74079+ /* simple case, append the current chain to our role */
74080+ role->next = *curr;
74081+ *curr = role;
74082+ } else {
74083+ /* 1 -> 2 -> 3 -> 4
74084+ 2 -> 3 -> 4
74085+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
74086+ */
74087+ /* trickier case: walk our role's chain until we find
74088+ the role for the start of the current slot's chain */
74089+ tmp = role;
74090+ tmp2 = *curr;
74091+ while (tmp->next && tmp->next != tmp2)
74092+ tmp = tmp->next;
74093+ if (tmp->next == tmp2) {
74094+ /* from example above, we found 3, so just
74095+ replace this slot's chain with ours */
74096+ *curr = role;
74097+ } else {
74098+ /* we didn't find a subset of our role's chain
74099+ in the current slot's chain, so append their
74100+ chain to ours, and set us as the first role in
74101+ the slot's chain
74102+
74103+ we could fold this case with the case above,
74104+ but making it explicit for clarity
74105+ */
74106+ tmp->next = tmp2;
74107+ *curr = role;
74108+ }
74109+ }
74110+ }
74111+
74112+ return;
74113+}
74114+
74115+static void
74116+insert_acl_role_label(struct acl_role_label *role)
74117+{
74118+ int i;
74119+
74120+ if (polstate->role_list == NULL) {
74121+ polstate->role_list = role;
74122+ role->prev = NULL;
74123+ } else {
74124+ role->prev = polstate->role_list;
74125+ polstate->role_list = role;
74126+ }
74127+
74128+ /* used for hash chains */
74129+ role->next = NULL;
74130+
74131+ if (role->roletype & GR_ROLE_DOMAIN) {
74132+ for (i = 0; i < role->domain_child_num; i++)
74133+ __insert_acl_role_label(role, role->domain_children[i]);
74134+ } else
74135+ __insert_acl_role_label(role, role->uidgid);
74136+}
74137+
74138+static int
74139+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
74140+{
74141+ struct name_entry **curr, *nentry;
74142+ struct inodev_entry *ientry;
74143+ unsigned int len = strlen(name);
74144+ unsigned int key = full_name_hash(name, len);
74145+ unsigned int index = key % polstate->name_set.n_size;
74146+
74147+ curr = &polstate->name_set.n_hash[index];
74148+
74149+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
74150+ curr = &((*curr)->next);
74151+
74152+ if (*curr != NULL)
74153+ return 1;
74154+
74155+ nentry = acl_alloc(sizeof (struct name_entry));
74156+ if (nentry == NULL)
74157+ return 0;
74158+ ientry = acl_alloc(sizeof (struct inodev_entry));
74159+ if (ientry == NULL)
74160+ return 0;
74161+ ientry->nentry = nentry;
74162+
74163+ nentry->key = key;
74164+ nentry->name = name;
74165+ nentry->inode = inode;
74166+ nentry->device = device;
74167+ nentry->len = len;
74168+ nentry->deleted = deleted;
74169+
74170+ nentry->prev = NULL;
74171+ curr = &polstate->name_set.n_hash[index];
74172+ if (*curr != NULL)
74173+ (*curr)->prev = nentry;
74174+ nentry->next = *curr;
74175+ *curr = nentry;
74176+
74177+ /* insert us into the table searchable by inode/dev */
74178+ __insert_inodev_entry(polstate, ientry);
74179+
74180+ return 1;
74181+}
74182+
74183+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
74184+
74185+static void *
74186+create_table(__u32 * len, int elementsize)
74187+{
74188+ unsigned int table_sizes[] = {
74189+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
74190+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
74191+ 4194301, 8388593, 16777213, 33554393, 67108859
74192+ };
74193+ void *newtable = NULL;
74194+ unsigned int pwr = 0;
74195+
74196+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
74197+ table_sizes[pwr] <= *len)
74198+ pwr++;
74199+
74200+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
74201+ return newtable;
74202+
74203+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
74204+ newtable =
74205+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
74206+ else
74207+ newtable = vmalloc(table_sizes[pwr] * elementsize);
74208+
74209+ *len = table_sizes[pwr];
74210+
74211+ return newtable;
74212+}
74213+
74214+static int
74215+init_variables(const struct gr_arg *arg, bool reload)
74216+{
74217+ struct task_struct *reaper = init_pid_ns.child_reaper;
74218+ unsigned int stacksize;
74219+
74220+ polstate->subj_map_set.s_size = arg->role_db.num_subjects;
74221+ polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
74222+ polstate->name_set.n_size = arg->role_db.num_objects;
74223+ polstate->inodev_set.i_size = arg->role_db.num_objects;
74224+
74225+ if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
74226+ !polstate->name_set.n_size || !polstate->inodev_set.i_size)
74227+ return 1;
74228+
74229+ if (!reload) {
74230+ if (!gr_init_uidset())
74231+ return 1;
74232+ }
74233+
74234+ /* set up the stack that holds allocation info */
74235+
74236+ stacksize = arg->role_db.num_pointers + 5;
74237+
74238+ if (!acl_alloc_stack_init(stacksize))
74239+ return 1;
74240+
74241+ if (!reload) {
74242+ /* grab reference for the real root dentry and vfsmount */
74243+ get_fs_root(reaper->fs, &gr_real_root);
74244+
74245+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
74246+ 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);
74247+#endif
74248+
74249+ fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
74250+ if (fakefs_obj_rw == NULL)
74251+ return 1;
74252+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
74253+
74254+ fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
74255+ if (fakefs_obj_rwx == NULL)
74256+ return 1;
74257+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
74258+ }
74259+
74260+ polstate->subj_map_set.s_hash =
74261+ (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
74262+ polstate->acl_role_set.r_hash =
74263+ (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
74264+ polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
74265+ polstate->inodev_set.i_hash =
74266+ (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
74267+
74268+ if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
74269+ !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
74270+ return 1;
74271+
74272+ memset(polstate->subj_map_set.s_hash, 0,
74273+ sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
74274+ memset(polstate->acl_role_set.r_hash, 0,
74275+ sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
74276+ memset(polstate->name_set.n_hash, 0,
74277+ sizeof (struct name_entry *) * polstate->name_set.n_size);
74278+ memset(polstate->inodev_set.i_hash, 0,
74279+ sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
74280+
74281+ return 0;
74282+}
74283+
74284+/* free information not needed after startup
74285+ currently contains user->kernel pointer mappings for subjects
74286+*/
74287+
74288+static void
74289+free_init_variables(void)
74290+{
74291+ __u32 i;
74292+
74293+ if (polstate->subj_map_set.s_hash) {
74294+ for (i = 0; i < polstate->subj_map_set.s_size; i++) {
74295+ if (polstate->subj_map_set.s_hash[i]) {
74296+ kfree(polstate->subj_map_set.s_hash[i]);
74297+ polstate->subj_map_set.s_hash[i] = NULL;
74298+ }
74299+ }
74300+
74301+ if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
74302+ PAGE_SIZE)
74303+ kfree(polstate->subj_map_set.s_hash);
74304+ else
74305+ vfree(polstate->subj_map_set.s_hash);
74306+ }
74307+
74308+ return;
74309+}
74310+
74311+static void
74312+free_variables(bool reload)
74313+{
74314+ struct acl_subject_label *s;
74315+ struct acl_role_label *r;
74316+ struct task_struct *task, *task2;
74317+ unsigned int x;
74318+
74319+ if (!reload) {
74320+ gr_clear_learn_entries();
74321+
74322+ read_lock(&tasklist_lock);
74323+ do_each_thread(task2, task) {
74324+ task->acl_sp_role = 0;
74325+ task->acl_role_id = 0;
74326+ task->inherited = 0;
74327+ task->acl = NULL;
74328+ task->role = NULL;
74329+ } while_each_thread(task2, task);
74330+ read_unlock(&tasklist_lock);
74331+
74332+ kfree(fakefs_obj_rw);
74333+ fakefs_obj_rw = NULL;
74334+ kfree(fakefs_obj_rwx);
74335+ fakefs_obj_rwx = NULL;
74336+
74337+ /* release the reference to the real root dentry and vfsmount */
74338+ path_put(&gr_real_root);
74339+ memset(&gr_real_root, 0, sizeof(gr_real_root));
74340+ }
74341+
74342+ /* free all object hash tables */
74343+
74344+ FOR_EACH_ROLE_START(r)
74345+ if (r->subj_hash == NULL)
74346+ goto next_role;
74347+ FOR_EACH_SUBJECT_START(r, s, x)
74348+ if (s->obj_hash == NULL)
74349+ break;
74350+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
74351+ kfree(s->obj_hash);
74352+ else
74353+ vfree(s->obj_hash);
74354+ FOR_EACH_SUBJECT_END(s, x)
74355+ FOR_EACH_NESTED_SUBJECT_START(r, s)
74356+ if (s->obj_hash == NULL)
74357+ break;
74358+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
74359+ kfree(s->obj_hash);
74360+ else
74361+ vfree(s->obj_hash);
74362+ FOR_EACH_NESTED_SUBJECT_END(s)
74363+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
74364+ kfree(r->subj_hash);
74365+ else
74366+ vfree(r->subj_hash);
74367+ r->subj_hash = NULL;
74368+next_role:
74369+ FOR_EACH_ROLE_END(r)
74370+
74371+ acl_free_all();
74372+
74373+ if (polstate->acl_role_set.r_hash) {
74374+ if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
74375+ PAGE_SIZE)
74376+ kfree(polstate->acl_role_set.r_hash);
74377+ else
74378+ vfree(polstate->acl_role_set.r_hash);
74379+ }
74380+ if (polstate->name_set.n_hash) {
74381+ if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
74382+ PAGE_SIZE)
74383+ kfree(polstate->name_set.n_hash);
74384+ else
74385+ vfree(polstate->name_set.n_hash);
74386+ }
74387+
74388+ if (polstate->inodev_set.i_hash) {
74389+ if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
74390+ PAGE_SIZE)
74391+ kfree(polstate->inodev_set.i_hash);
74392+ else
74393+ vfree(polstate->inodev_set.i_hash);
74394+ }
74395+
74396+ if (!reload)
74397+ gr_free_uidset();
74398+
74399+ memset(&polstate->name_set, 0, sizeof (struct name_db));
74400+ memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
74401+ memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
74402+ memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
74403+
74404+ polstate->default_role = NULL;
74405+ polstate->kernel_role = NULL;
74406+ polstate->role_list = NULL;
74407+
74408+ return;
74409+}
74410+
74411+static struct acl_subject_label *
74412+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
74413+
74414+static int alloc_and_copy_string(char **name, unsigned int maxlen)
74415+{
74416+ unsigned int len = strnlen_user(*name, maxlen);
74417+ char *tmp;
74418+
74419+ if (!len || len >= maxlen)
74420+ return -EINVAL;
74421+
74422+ if ((tmp = (char *) acl_alloc(len)) == NULL)
74423+ return -ENOMEM;
74424+
74425+ if (copy_from_user(tmp, *name, len))
74426+ return -EFAULT;
74427+
74428+ tmp[len-1] = '\0';
74429+ *name = tmp;
74430+
74431+ return 0;
74432+}
74433+
74434+static int
74435+copy_user_glob(struct acl_object_label *obj)
74436+{
74437+ struct acl_object_label *g_tmp, **guser;
74438+ int error;
74439+
74440+ if (obj->globbed == NULL)
74441+ return 0;
74442+
74443+ guser = &obj->globbed;
74444+ while (*guser) {
74445+ g_tmp = (struct acl_object_label *)
74446+ acl_alloc(sizeof (struct acl_object_label));
74447+ if (g_tmp == NULL)
74448+ return -ENOMEM;
74449+
74450+ if (copy_acl_object_label(g_tmp, *guser))
74451+ return -EFAULT;
74452+
74453+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
74454+ if (error)
74455+ return error;
74456+
74457+ *guser = g_tmp;
74458+ guser = &(g_tmp->next);
74459+ }
74460+
74461+ return 0;
74462+}
74463+
74464+static int
74465+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
74466+ struct acl_role_label *role)
74467+{
74468+ struct acl_object_label *o_tmp;
74469+ int ret;
74470+
74471+ while (userp) {
74472+ if ((o_tmp = (struct acl_object_label *)
74473+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
74474+ return -ENOMEM;
74475+
74476+ if (copy_acl_object_label(o_tmp, userp))
74477+ return -EFAULT;
74478+
74479+ userp = o_tmp->prev;
74480+
74481+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
74482+ if (ret)
74483+ return ret;
74484+
74485+ insert_acl_obj_label(o_tmp, subj);
74486+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
74487+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
74488+ return -ENOMEM;
74489+
74490+ ret = copy_user_glob(o_tmp);
74491+ if (ret)
74492+ return ret;
74493+
74494+ if (o_tmp->nested) {
74495+ int already_copied;
74496+
74497+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
74498+ if (IS_ERR(o_tmp->nested))
74499+ return PTR_ERR(o_tmp->nested);
74500+
74501+ /* insert into nested subject list if we haven't copied this one yet
74502+ to prevent duplicate entries */
74503+ if (!already_copied) {
74504+ o_tmp->nested->next = role->hash->first;
74505+ role->hash->first = o_tmp->nested;
74506+ }
74507+ }
74508+ }
74509+
74510+ return 0;
74511+}
74512+
74513+static __u32
74514+count_user_subjs(struct acl_subject_label *userp)
74515+{
74516+ struct acl_subject_label s_tmp;
74517+ __u32 num = 0;
74518+
74519+ while (userp) {
74520+ if (copy_acl_subject_label(&s_tmp, userp))
74521+ break;
74522+
74523+ userp = s_tmp.prev;
74524+ }
74525+
74526+ return num;
74527+}
74528+
74529+static int
74530+copy_user_allowedips(struct acl_role_label *rolep)
74531+{
74532+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
74533+
74534+ ruserip = rolep->allowed_ips;
74535+
74536+ while (ruserip) {
74537+ rlast = rtmp;
74538+
74539+ if ((rtmp = (struct role_allowed_ip *)
74540+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
74541+ return -ENOMEM;
74542+
74543+ if (copy_role_allowed_ip(rtmp, ruserip))
74544+ return -EFAULT;
74545+
74546+ ruserip = rtmp->prev;
74547+
74548+ if (!rlast) {
74549+ rtmp->prev = NULL;
74550+ rolep->allowed_ips = rtmp;
74551+ } else {
74552+ rlast->next = rtmp;
74553+ rtmp->prev = rlast;
74554+ }
74555+
74556+ if (!ruserip)
74557+ rtmp->next = NULL;
74558+ }
74559+
74560+ return 0;
74561+}
74562+
74563+static int
74564+copy_user_transitions(struct acl_role_label *rolep)
74565+{
74566+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
74567+ int error;
74568+
74569+ rusertp = rolep->transitions;
74570+
74571+ while (rusertp) {
74572+ rlast = rtmp;
74573+
74574+ if ((rtmp = (struct role_transition *)
74575+ acl_alloc(sizeof (struct role_transition))) == NULL)
74576+ return -ENOMEM;
74577+
74578+ if (copy_role_transition(rtmp, rusertp))
74579+ return -EFAULT;
74580+
74581+ rusertp = rtmp->prev;
74582+
74583+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
74584+ if (error)
74585+ return error;
74586+
74587+ if (!rlast) {
74588+ rtmp->prev = NULL;
74589+ rolep->transitions = rtmp;
74590+ } else {
74591+ rlast->next = rtmp;
74592+ rtmp->prev = rlast;
74593+ }
74594+
74595+ if (!rusertp)
74596+ rtmp->next = NULL;
74597+ }
74598+
74599+ return 0;
74600+}
74601+
74602+static __u32 count_user_objs(const struct acl_object_label __user *userp)
74603+{
74604+ struct acl_object_label o_tmp;
74605+ __u32 num = 0;
74606+
74607+ while (userp) {
74608+ if (copy_acl_object_label(&o_tmp, userp))
74609+ break;
74610+
74611+ userp = o_tmp.prev;
74612+ num++;
74613+ }
74614+
74615+ return num;
74616+}
74617+
74618+static struct acl_subject_label *
74619+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
74620+{
74621+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
74622+ __u32 num_objs;
74623+ struct acl_ip_label **i_tmp, *i_utmp2;
74624+ struct gr_hash_struct ghash;
74625+ struct subject_map *subjmap;
74626+ unsigned int i_num;
74627+ int err;
74628+
74629+ if (already_copied != NULL)
74630+ *already_copied = 0;
74631+
74632+ s_tmp = lookup_subject_map(userp);
74633+
74634+ /* we've already copied this subject into the kernel, just return
74635+ the reference to it, and don't copy it over again
74636+ */
74637+ if (s_tmp) {
74638+ if (already_copied != NULL)
74639+ *already_copied = 1;
74640+ return(s_tmp);
74641+ }
74642+
74643+ if ((s_tmp = (struct acl_subject_label *)
74644+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
74645+ return ERR_PTR(-ENOMEM);
74646+
74647+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
74648+ if (subjmap == NULL)
74649+ return ERR_PTR(-ENOMEM);
74650+
74651+ subjmap->user = userp;
74652+ subjmap->kernel = s_tmp;
74653+ insert_subj_map_entry(subjmap);
74654+
74655+ if (copy_acl_subject_label(s_tmp, userp))
74656+ return ERR_PTR(-EFAULT);
74657+
74658+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
74659+ if (err)
74660+ return ERR_PTR(err);
74661+
74662+ if (!strcmp(s_tmp->filename, "/"))
74663+ role->root_label = s_tmp;
74664+
74665+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
74666+ return ERR_PTR(-EFAULT);
74667+
74668+ /* copy user and group transition tables */
74669+
74670+ if (s_tmp->user_trans_num) {
74671+ uid_t *uidlist;
74672+
74673+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
74674+ if (uidlist == NULL)
74675+ return ERR_PTR(-ENOMEM);
74676+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
74677+ return ERR_PTR(-EFAULT);
74678+
74679+ s_tmp->user_transitions = uidlist;
74680+ }
74681+
74682+ if (s_tmp->group_trans_num) {
74683+ gid_t *gidlist;
74684+
74685+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
74686+ if (gidlist == NULL)
74687+ return ERR_PTR(-ENOMEM);
74688+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
74689+ return ERR_PTR(-EFAULT);
74690+
74691+ s_tmp->group_transitions = gidlist;
74692+ }
74693+
74694+ /* set up object hash table */
74695+ num_objs = count_user_objs(ghash.first);
74696+
74697+ s_tmp->obj_hash_size = num_objs;
74698+ s_tmp->obj_hash =
74699+ (struct acl_object_label **)
74700+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
74701+
74702+ if (!s_tmp->obj_hash)
74703+ return ERR_PTR(-ENOMEM);
74704+
74705+ memset(s_tmp->obj_hash, 0,
74706+ s_tmp->obj_hash_size *
74707+ sizeof (struct acl_object_label *));
74708+
74709+ /* add in objects */
74710+ err = copy_user_objs(ghash.first, s_tmp, role);
74711+
74712+ if (err)
74713+ return ERR_PTR(err);
74714+
74715+ /* set pointer for parent subject */
74716+ if (s_tmp->parent_subject) {
74717+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
74718+
74719+ if (IS_ERR(s_tmp2))
74720+ return s_tmp2;
74721+
74722+ s_tmp->parent_subject = s_tmp2;
74723+ }
74724+
74725+ /* add in ip acls */
74726+
74727+ if (!s_tmp->ip_num) {
74728+ s_tmp->ips = NULL;
74729+ goto insert;
74730+ }
74731+
74732+ i_tmp =
74733+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
74734+ sizeof (struct acl_ip_label *));
74735+
74736+ if (!i_tmp)
74737+ return ERR_PTR(-ENOMEM);
74738+
74739+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
74740+ *(i_tmp + i_num) =
74741+ (struct acl_ip_label *)
74742+ acl_alloc(sizeof (struct acl_ip_label));
74743+ if (!*(i_tmp + i_num))
74744+ return ERR_PTR(-ENOMEM);
74745+
74746+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
74747+ return ERR_PTR(-EFAULT);
74748+
74749+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
74750+ return ERR_PTR(-EFAULT);
74751+
74752+ if ((*(i_tmp + i_num))->iface == NULL)
74753+ continue;
74754+
74755+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
74756+ if (err)
74757+ return ERR_PTR(err);
74758+ }
74759+
74760+ s_tmp->ips = i_tmp;
74761+
74762+insert:
74763+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
74764+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
74765+ return ERR_PTR(-ENOMEM);
74766+
74767+ return s_tmp;
74768+}
74769+
74770+static int
74771+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
74772+{
74773+ struct acl_subject_label s_pre;
74774+ struct acl_subject_label * ret;
74775+ int err;
74776+
74777+ while (userp) {
74778+ if (copy_acl_subject_label(&s_pre, userp))
74779+ return -EFAULT;
74780+
74781+ ret = do_copy_user_subj(userp, role, NULL);
74782+
74783+ err = PTR_ERR(ret);
74784+ if (IS_ERR(ret))
74785+ return err;
74786+
74787+ insert_acl_subj_label(ret, role);
74788+
74789+ userp = s_pre.prev;
74790+ }
74791+
74792+ return 0;
74793+}
74794+
74795+static int
74796+copy_user_acl(struct gr_arg *arg)
74797+{
74798+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
74799+ struct acl_subject_label *subj_list;
74800+ struct sprole_pw *sptmp;
74801+ struct gr_hash_struct *ghash;
74802+ uid_t *domainlist;
74803+ unsigned int r_num;
74804+ int err = 0;
74805+ __u16 i;
74806+ __u32 num_subjs;
74807+
74808+ /* we need a default and kernel role */
74809+ if (arg->role_db.num_roles < 2)
74810+ return -EINVAL;
74811+
74812+ /* copy special role authentication info from userspace */
74813+
74814+ polstate->num_sprole_pws = arg->num_sprole_pws;
74815+ polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
74816+
74817+ if (!polstate->acl_special_roles && polstate->num_sprole_pws)
74818+ return -ENOMEM;
74819+
74820+ for (i = 0; i < polstate->num_sprole_pws; i++) {
74821+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
74822+ if (!sptmp)
74823+ return -ENOMEM;
74824+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
74825+ return -EFAULT;
74826+
74827+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
74828+ if (err)
74829+ return err;
74830+
74831+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
74832+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
74833+#endif
74834+
74835+ polstate->acl_special_roles[i] = sptmp;
74836+ }
74837+
74838+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
74839+
74840+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
74841+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
74842+
74843+ if (!r_tmp)
74844+ return -ENOMEM;
74845+
74846+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
74847+ return -EFAULT;
74848+
74849+ if (copy_acl_role_label(r_tmp, r_utmp2))
74850+ return -EFAULT;
74851+
74852+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
74853+ if (err)
74854+ return err;
74855+
74856+ if (!strcmp(r_tmp->rolename, "default")
74857+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
74858+ polstate->default_role = r_tmp;
74859+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
74860+ polstate->kernel_role = r_tmp;
74861+ }
74862+
74863+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
74864+ return -ENOMEM;
74865+
74866+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
74867+ return -EFAULT;
74868+
74869+ r_tmp->hash = ghash;
74870+
74871+ num_subjs = count_user_subjs(r_tmp->hash->first);
74872+
74873+ r_tmp->subj_hash_size = num_subjs;
74874+ r_tmp->subj_hash =
74875+ (struct acl_subject_label **)
74876+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
74877+
74878+ if (!r_tmp->subj_hash)
74879+ return -ENOMEM;
74880+
74881+ err = copy_user_allowedips(r_tmp);
74882+ if (err)
74883+ return err;
74884+
74885+ /* copy domain info */
74886+ if (r_tmp->domain_children != NULL) {
74887+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
74888+ if (domainlist == NULL)
74889+ return -ENOMEM;
74890+
74891+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
74892+ return -EFAULT;
74893+
74894+ r_tmp->domain_children = domainlist;
74895+ }
74896+
74897+ err = copy_user_transitions(r_tmp);
74898+ if (err)
74899+ return err;
74900+
74901+ memset(r_tmp->subj_hash, 0,
74902+ r_tmp->subj_hash_size *
74903+ sizeof (struct acl_subject_label *));
74904+
74905+ /* acquire the list of subjects, then NULL out
74906+ the list prior to parsing the subjects for this role,
74907+ as during this parsing the list is replaced with a list
74908+ of *nested* subjects for the role
74909+ */
74910+ subj_list = r_tmp->hash->first;
74911+
74912+ /* set nested subject list to null */
74913+ r_tmp->hash->first = NULL;
74914+
74915+ err = copy_user_subjs(subj_list, r_tmp);
74916+
74917+ if (err)
74918+ return err;
74919+
74920+ insert_acl_role_label(r_tmp);
74921+ }
74922+
74923+ if (polstate->default_role == NULL || polstate->kernel_role == NULL)
74924+ return -EINVAL;
74925+
74926+ return err;
74927+}
74928+
74929+static int gracl_reload_apply_policies(void *reload)
74930+{
74931+ struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
74932+ struct task_struct *task, *task2;
74933+ struct acl_role_label *role, *rtmp;
74934+ struct acl_subject_label *subj;
74935+ const struct cred *cred;
74936+ int role_applied;
74937+ int ret = 0;
74938+
74939+ memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
74940+ memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
74941+
74942+ /* first make sure we'll be able to apply the new policy cleanly */
74943+ do_each_thread(task2, task) {
74944+ if (task->exec_file == NULL)
74945+ continue;
74946+ role_applied = 0;
74947+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
74948+ /* preserve special roles */
74949+ FOR_EACH_ROLE_START(role)
74950+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
74951+ rtmp = task->role;
74952+ task->role = role;
74953+ role_applied = 1;
74954+ break;
74955+ }
74956+ FOR_EACH_ROLE_END(role)
74957+ }
74958+ if (!role_applied) {
74959+ cred = __task_cred(task);
74960+ rtmp = task->role;
74961+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
74962+ }
74963+ /* this handles non-nested inherited subjects, nested subjects will still
74964+ be dropped currently */
74965+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
74966+ task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
74967+ /* change the role back so that we've made no modifications to the policy */
74968+ task->role = rtmp;
74969+
74970+ if (subj == NULL || task->tmpacl == NULL) {
74971+ ret = -EINVAL;
74972+ goto out;
74973+ }
74974+ } while_each_thread(task2, task);
74975+
74976+ /* now actually apply the policy */
74977+
74978+ do_each_thread(task2, task) {
74979+ if (task->exec_file) {
74980+ role_applied = 0;
74981+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
74982+ /* preserve special roles */
74983+ FOR_EACH_ROLE_START(role)
74984+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
74985+ task->role = role;
74986+ role_applied = 1;
74987+ break;
74988+ }
74989+ FOR_EACH_ROLE_END(role)
74990+ }
74991+ if (!role_applied) {
74992+ cred = __task_cred(task);
74993+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
74994+ }
74995+ /* this handles non-nested inherited subjects, nested subjects will still
74996+ be dropped currently */
74997+ if (!reload_state->oldmode && task->inherited)
74998+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
74999+ else {
75000+ /* looked up and tagged to the task previously */
75001+ subj = task->tmpacl;
75002+ }
75003+ /* subj will be non-null */
75004+ __gr_apply_subject_to_task(polstate, task, subj);
75005+ if (reload_state->oldmode) {
75006+ task->acl_role_id = 0;
75007+ task->acl_sp_role = 0;
75008+ task->inherited = 0;
75009+ }
75010+ } else {
75011+ // it's a kernel process
75012+ task->role = polstate->kernel_role;
75013+ task->acl = polstate->kernel_role->root_label;
75014+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
75015+ task->acl->mode &= ~GR_PROCFIND;
75016+#endif
75017+ }
75018+ } while_each_thread(task2, task);
75019+
75020+ memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
75021+ memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
75022+
75023+out:
75024+
75025+ return ret;
75026+}
75027+
75028+static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
75029+{
75030+ struct gr_reload_state new_reload_state = { };
75031+ int err;
75032+
75033+ new_reload_state.oldpolicy_ptr = polstate;
75034+ new_reload_state.oldalloc_ptr = current_alloc_state;
75035+ new_reload_state.oldmode = oldmode;
75036+
75037+ current_alloc_state = &new_reload_state.newalloc;
75038+ polstate = &new_reload_state.newpolicy;
75039+
75040+ /* everything relevant is now saved off, copy in the new policy */
75041+ if (init_variables(args, true)) {
75042+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
75043+ err = -ENOMEM;
75044+ goto error;
75045+ }
75046+
75047+ err = copy_user_acl(args);
75048+ free_init_variables();
75049+ if (err)
75050+ goto error;
75051+ /* the new policy is copied in, with the old policy available via saved_state
75052+ first go through applying roles, making sure to preserve special roles
75053+ then apply new subjects, making sure to preserve inherited and nested subjects,
75054+ though currently only inherited subjects will be preserved
75055+ */
75056+ err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
75057+ if (err)
75058+ goto error;
75059+
75060+ /* we've now applied the new policy, so restore the old policy state to free it */
75061+ polstate = &new_reload_state.oldpolicy;
75062+ current_alloc_state = &new_reload_state.oldalloc;
75063+ free_variables(true);
75064+
75065+ /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
75066+ to running_polstate/current_alloc_state inside stop_machine
75067+ */
75068+ err = 0;
75069+ goto out;
75070+error:
75071+ /* on error of loading the new policy, we'll just keep the previous
75072+ policy set around
75073+ */
75074+ free_variables(true);
75075+
75076+ /* doesn't affect runtime, but maintains consistent state */
75077+out:
75078+ polstate = new_reload_state.oldpolicy_ptr;
75079+ current_alloc_state = new_reload_state.oldalloc_ptr;
75080+
75081+ return err;
75082+}
75083+
75084+static int
75085+gracl_init(struct gr_arg *args)
75086+{
75087+ int error = 0;
75088+
75089+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
75090+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
75091+
75092+ if (init_variables(args, false)) {
75093+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
75094+ error = -ENOMEM;
75095+ goto out;
75096+ }
75097+
75098+ error = copy_user_acl(args);
75099+ free_init_variables();
75100+ if (error)
75101+ goto out;
75102+
75103+ error = gr_set_acls(0);
75104+ if (error)
75105+ goto out;
75106+
75107+ gr_enable_rbac_system();
75108+
75109+ return 0;
75110+
75111+out:
75112+ free_variables(false);
75113+ return error;
75114+}
75115+
75116+static int
75117+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
75118+ unsigned char **sum)
75119+{
75120+ struct acl_role_label *r;
75121+ struct role_allowed_ip *ipp;
75122+ struct role_transition *trans;
75123+ unsigned int i;
75124+ int found = 0;
75125+ u32 curr_ip = current->signal->curr_ip;
75126+
75127+ current->signal->saved_ip = curr_ip;
75128+
75129+ /* check transition table */
75130+
75131+ for (trans = current->role->transitions; trans; trans = trans->next) {
75132+ if (!strcmp(rolename, trans->rolename)) {
75133+ found = 1;
75134+ break;
75135+ }
75136+ }
75137+
75138+ if (!found)
75139+ return 0;
75140+
75141+ /* handle special roles that do not require authentication
75142+ and check ip */
75143+
75144+ FOR_EACH_ROLE_START(r)
75145+ if (!strcmp(rolename, r->rolename) &&
75146+ (r->roletype & GR_ROLE_SPECIAL)) {
75147+ found = 0;
75148+ if (r->allowed_ips != NULL) {
75149+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
75150+ if ((ntohl(curr_ip) & ipp->netmask) ==
75151+ (ntohl(ipp->addr) & ipp->netmask))
75152+ found = 1;
75153+ }
75154+ } else
75155+ found = 2;
75156+ if (!found)
75157+ return 0;
75158+
75159+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
75160+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
75161+ *salt = NULL;
75162+ *sum = NULL;
75163+ return 1;
75164+ }
75165+ }
75166+ FOR_EACH_ROLE_END(r)
75167+
75168+ for (i = 0; i < polstate->num_sprole_pws; i++) {
75169+ if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
75170+ *salt = polstate->acl_special_roles[i]->salt;
75171+ *sum = polstate->acl_special_roles[i]->sum;
75172+ return 1;
75173+ }
75174+ }
75175+
75176+ return 0;
75177+}
75178+
75179+int gr_check_secure_terminal(struct task_struct *task)
75180+{
75181+ struct task_struct *p, *p2, *p3;
75182+ struct files_struct *files;
75183+ struct fdtable *fdt;
75184+ struct file *our_file = NULL, *file;
75185+ int i;
75186+
75187+ if (task->signal->tty == NULL)
75188+ return 1;
75189+
75190+ files = get_files_struct(task);
75191+ if (files != NULL) {
75192+ rcu_read_lock();
75193+ fdt = files_fdtable(files);
75194+ for (i=0; i < fdt->max_fds; i++) {
75195+ file = fcheck_files(files, i);
75196+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
75197+ get_file(file);
75198+ our_file = file;
75199+ }
75200+ }
75201+ rcu_read_unlock();
75202+ put_files_struct(files);
75203+ }
75204+
75205+ if (our_file == NULL)
75206+ return 1;
75207+
75208+ read_lock(&tasklist_lock);
75209+ do_each_thread(p2, p) {
75210+ files = get_files_struct(p);
75211+ if (files == NULL ||
75212+ (p->signal && p->signal->tty == task->signal->tty)) {
75213+ if (files != NULL)
75214+ put_files_struct(files);
75215+ continue;
75216+ }
75217+ rcu_read_lock();
75218+ fdt = files_fdtable(files);
75219+ for (i=0; i < fdt->max_fds; i++) {
75220+ file = fcheck_files(files, i);
75221+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
75222+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
75223+ p3 = task;
75224+ while (task_pid_nr(p3) > 0) {
75225+ if (p3 == p)
75226+ break;
75227+ p3 = p3->real_parent;
75228+ }
75229+ if (p3 == p)
75230+ break;
75231+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
75232+ gr_handle_alertkill(p);
75233+ rcu_read_unlock();
75234+ put_files_struct(files);
75235+ read_unlock(&tasklist_lock);
75236+ fput(our_file);
75237+ return 0;
75238+ }
75239+ }
75240+ rcu_read_unlock();
75241+ put_files_struct(files);
75242+ } while_each_thread(p2, p);
75243+ read_unlock(&tasklist_lock);
75244+
75245+ fput(our_file);
75246+ return 1;
75247+}
75248+
75249+ssize_t
75250+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
75251+{
75252+ struct gr_arg_wrapper uwrap;
75253+ unsigned char *sprole_salt = NULL;
75254+ unsigned char *sprole_sum = NULL;
75255+ int error = 0;
75256+ int error2 = 0;
75257+ size_t req_count = 0;
75258+ unsigned char oldmode = 0;
75259+
75260+ mutex_lock(&gr_dev_mutex);
75261+
75262+ if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
75263+ error = -EPERM;
75264+ goto out;
75265+ }
75266+
75267+#ifdef CONFIG_COMPAT
75268+ pax_open_kernel();
75269+ if (is_compat_task()) {
75270+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
75271+ copy_gr_arg = &copy_gr_arg_compat;
75272+ copy_acl_object_label = &copy_acl_object_label_compat;
75273+ copy_acl_subject_label = &copy_acl_subject_label_compat;
75274+ copy_acl_role_label = &copy_acl_role_label_compat;
75275+ copy_acl_ip_label = &copy_acl_ip_label_compat;
75276+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
75277+ copy_role_transition = &copy_role_transition_compat;
75278+ copy_sprole_pw = &copy_sprole_pw_compat;
75279+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
75280+ copy_pointer_from_array = &copy_pointer_from_array_compat;
75281+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
75282+ } else {
75283+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
75284+ copy_gr_arg = &copy_gr_arg_normal;
75285+ copy_acl_object_label = &copy_acl_object_label_normal;
75286+ copy_acl_subject_label = &copy_acl_subject_label_normal;
75287+ copy_acl_role_label = &copy_acl_role_label_normal;
75288+ copy_acl_ip_label = &copy_acl_ip_label_normal;
75289+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
75290+ copy_role_transition = &copy_role_transition_normal;
75291+ copy_sprole_pw = &copy_sprole_pw_normal;
75292+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
75293+ copy_pointer_from_array = &copy_pointer_from_array_normal;
75294+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
75295+ }
75296+ pax_close_kernel();
75297+#endif
75298+
75299+ req_count = get_gr_arg_wrapper_size();
75300+
75301+ if (count != req_count) {
75302+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
75303+ error = -EINVAL;
75304+ goto out;
75305+ }
75306+
75307+
75308+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
75309+ gr_auth_expires = 0;
75310+ gr_auth_attempts = 0;
75311+ }
75312+
75313+ error = copy_gr_arg_wrapper(buf, &uwrap);
75314+ if (error)
75315+ goto out;
75316+
75317+ error = copy_gr_arg(uwrap.arg, gr_usermode);
75318+ if (error)
75319+ goto out;
75320+
75321+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
75322+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
75323+ time_after(gr_auth_expires, get_seconds())) {
75324+ error = -EBUSY;
75325+ goto out;
75326+ }
75327+
75328+ /* if non-root trying to do anything other than use a special role,
75329+ do not attempt authentication, do not count towards authentication
75330+ locking
75331+ */
75332+
75333+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
75334+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
75335+ gr_is_global_nonroot(current_uid())) {
75336+ error = -EPERM;
75337+ goto out;
75338+ }
75339+
75340+ /* ensure pw and special role name are null terminated */
75341+
75342+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
75343+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
75344+
75345+ /* Okay.
75346+ * We have our enough of the argument structure..(we have yet
75347+ * to copy_from_user the tables themselves) . Copy the tables
75348+ * only if we need them, i.e. for loading operations. */
75349+
75350+ switch (gr_usermode->mode) {
75351+ case GR_STATUS:
75352+ if (gr_acl_is_enabled()) {
75353+ error = 1;
75354+ if (!gr_check_secure_terminal(current))
75355+ error = 3;
75356+ } else
75357+ error = 2;
75358+ goto out;
75359+ case GR_SHUTDOWN:
75360+ if (gr_acl_is_enabled() && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75361+ stop_machine(gr_rbac_disable, NULL, NULL);
75362+ free_variables(false);
75363+ memset(gr_usermode, 0, sizeof(struct gr_arg));
75364+ memset(gr_system_salt, 0, GR_SALT_LEN);
75365+ memset(gr_system_sum, 0, GR_SHA_LEN);
75366+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
75367+ } else if (gr_acl_is_enabled()) {
75368+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
75369+ error = -EPERM;
75370+ } else {
75371+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
75372+ error = -EAGAIN;
75373+ }
75374+ break;
75375+ case GR_ENABLE:
75376+ if (!gr_acl_is_enabled() && !(error2 = gracl_init(gr_usermode)))
75377+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
75378+ else {
75379+ if (gr_acl_is_enabled())
75380+ error = -EAGAIN;
75381+ else
75382+ error = error2;
75383+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
75384+ }
75385+ break;
75386+ case GR_OLDRELOAD:
75387+ oldmode = 1;
75388+ case GR_RELOAD:
75389+ if (!gr_acl_is_enabled()) {
75390+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
75391+ error = -EAGAIN;
75392+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75393+ error2 = gracl_reload(gr_usermode, oldmode);
75394+ if (!error2)
75395+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
75396+ else {
75397+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
75398+ error = error2;
75399+ }
75400+ } else {
75401+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
75402+ error = -EPERM;
75403+ }
75404+ break;
75405+ case GR_SEGVMOD:
75406+ if (unlikely(!gr_acl_is_enabled())) {
75407+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
75408+ error = -EAGAIN;
75409+ break;
75410+ }
75411+
75412+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75413+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
75414+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
75415+ struct acl_subject_label *segvacl;
75416+ segvacl =
75417+ lookup_acl_subj_label(gr_usermode->segv_inode,
75418+ gr_usermode->segv_device,
75419+ current->role);
75420+ if (segvacl) {
75421+ segvacl->crashes = 0;
75422+ segvacl->expires = 0;
75423+ }
75424+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
75425+ gr_remove_uid(gr_usermode->segv_uid);
75426+ }
75427+ } else {
75428+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
75429+ error = -EPERM;
75430+ }
75431+ break;
75432+ case GR_SPROLE:
75433+ case GR_SPROLEPAM:
75434+ if (unlikely(!gr_acl_is_enabled())) {
75435+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
75436+ error = -EAGAIN;
75437+ break;
75438+ }
75439+
75440+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
75441+ current->role->expires = 0;
75442+ current->role->auth_attempts = 0;
75443+ }
75444+
75445+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
75446+ time_after(current->role->expires, get_seconds())) {
75447+ error = -EBUSY;
75448+ goto out;
75449+ }
75450+
75451+ if (lookup_special_role_auth
75452+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
75453+ && ((!sprole_salt && !sprole_sum)
75454+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
75455+ char *p = "";
75456+ assign_special_role(gr_usermode->sp_role);
75457+ read_lock(&tasklist_lock);
75458+ if (current->real_parent)
75459+ p = current->real_parent->role->rolename;
75460+ read_unlock(&tasklist_lock);
75461+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
75462+ p, acl_sp_role_value);
75463+ } else {
75464+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
75465+ error = -EPERM;
75466+ if(!(current->role->auth_attempts++))
75467+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
75468+
75469+ goto out;
75470+ }
75471+ break;
75472+ case GR_UNSPROLE:
75473+ if (unlikely(!gr_acl_is_enabled())) {
75474+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
75475+ error = -EAGAIN;
75476+ break;
75477+ }
75478+
75479+ if (current->role->roletype & GR_ROLE_SPECIAL) {
75480+ char *p = "";
75481+ int i = 0;
75482+
75483+ read_lock(&tasklist_lock);
75484+ if (current->real_parent) {
75485+ p = current->real_parent->role->rolename;
75486+ i = current->real_parent->acl_role_id;
75487+ }
75488+ read_unlock(&tasklist_lock);
75489+
75490+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
75491+ gr_set_acls(1);
75492+ } else {
75493+ error = -EPERM;
75494+ goto out;
75495+ }
75496+ break;
75497+ default:
75498+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
75499+ error = -EINVAL;
75500+ break;
75501+ }
75502+
75503+ if (error != -EPERM)
75504+ goto out;
75505+
75506+ if(!(gr_auth_attempts++))
75507+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
75508+
75509+ out:
75510+ mutex_unlock(&gr_dev_mutex);
75511+
75512+ if (!error)
75513+ error = req_count;
75514+
75515+ return error;
75516+}
75517+
75518+int
75519+gr_set_acls(const int type)
75520+{
75521+ struct task_struct *task, *task2;
75522+ struct acl_role_label *role = current->role;
75523+ struct acl_subject_label *subj;
75524+ __u16 acl_role_id = current->acl_role_id;
75525+ const struct cred *cred;
75526+ int ret;
75527+
75528+ rcu_read_lock();
75529+ read_lock(&tasklist_lock);
75530+ read_lock(&grsec_exec_file_lock);
75531+ do_each_thread(task2, task) {
75532+ /* check to see if we're called from the exit handler,
75533+ if so, only replace ACLs that have inherited the admin
75534+ ACL */
75535+
75536+ if (type && (task->role != role ||
75537+ task->acl_role_id != acl_role_id))
75538+ continue;
75539+
75540+ task->acl_role_id = 0;
75541+ task->acl_sp_role = 0;
75542+ task->inherited = 0;
75543+
75544+ if (task->exec_file) {
75545+ cred = __task_cred(task);
75546+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75547+ subj = __gr_get_subject_for_task(polstate, task, NULL);
75548+ if (subj == NULL) {
75549+ ret = -EINVAL;
75550+ read_unlock(&grsec_exec_file_lock);
75551+ read_unlock(&tasklist_lock);
75552+ rcu_read_unlock();
75553+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
75554+ return ret;
75555+ }
75556+ __gr_apply_subject_to_task(polstate, task, subj);
75557+ } else {
75558+ // it's a kernel process
75559+ task->role = polstate->kernel_role;
75560+ task->acl = polstate->kernel_role->root_label;
75561+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
75562+ task->acl->mode &= ~GR_PROCFIND;
75563+#endif
75564+ }
75565+ } while_each_thread(task2, task);
75566+ read_unlock(&grsec_exec_file_lock);
75567+ read_unlock(&tasklist_lock);
75568+ rcu_read_unlock();
75569+
75570+ return 0;
75571+}
75572diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
75573new file mode 100644
75574index 0000000..39645c9
75575--- /dev/null
75576+++ b/grsecurity/gracl_res.c
75577@@ -0,0 +1,68 @@
75578+#include <linux/kernel.h>
75579+#include <linux/sched.h>
75580+#include <linux/gracl.h>
75581+#include <linux/grinternal.h>
75582+
75583+static const char *restab_log[] = {
75584+ [RLIMIT_CPU] = "RLIMIT_CPU",
75585+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
75586+ [RLIMIT_DATA] = "RLIMIT_DATA",
75587+ [RLIMIT_STACK] = "RLIMIT_STACK",
75588+ [RLIMIT_CORE] = "RLIMIT_CORE",
75589+ [RLIMIT_RSS] = "RLIMIT_RSS",
75590+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
75591+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
75592+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
75593+ [RLIMIT_AS] = "RLIMIT_AS",
75594+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
75595+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
75596+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
75597+ [RLIMIT_NICE] = "RLIMIT_NICE",
75598+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
75599+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
75600+ [GR_CRASH_RES] = "RLIMIT_CRASH"
75601+};
75602+
75603+void
75604+gr_log_resource(const struct task_struct *task,
75605+ const int res, const unsigned long wanted, const int gt)
75606+{
75607+ const struct cred *cred;
75608+ unsigned long rlim;
75609+
75610+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
75611+ return;
75612+
75613+ // not yet supported resource
75614+ if (unlikely(!restab_log[res]))
75615+ return;
75616+
75617+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
75618+ rlim = task_rlimit_max(task, res);
75619+ else
75620+ rlim = task_rlimit(task, res);
75621+
75622+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
75623+ return;
75624+
75625+ rcu_read_lock();
75626+ cred = __task_cred(task);
75627+
75628+ if (res == RLIMIT_NPROC &&
75629+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
75630+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
75631+ goto out_rcu_unlock;
75632+ else if (res == RLIMIT_MEMLOCK &&
75633+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
75634+ goto out_rcu_unlock;
75635+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
75636+ goto out_rcu_unlock;
75637+ rcu_read_unlock();
75638+
75639+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
75640+
75641+ return;
75642+out_rcu_unlock:
75643+ rcu_read_unlock();
75644+ return;
75645+}
75646diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
75647new file mode 100644
75648index 0000000..2040e61
75649--- /dev/null
75650+++ b/grsecurity/gracl_segv.c
75651@@ -0,0 +1,313 @@
75652+#include <linux/kernel.h>
75653+#include <linux/mm.h>
75654+#include <asm/uaccess.h>
75655+#include <asm/errno.h>
75656+#include <asm/mman.h>
75657+#include <net/sock.h>
75658+#include <linux/file.h>
75659+#include <linux/fs.h>
75660+#include <linux/net.h>
75661+#include <linux/in.h>
75662+#include <linux/slab.h>
75663+#include <linux/types.h>
75664+#include <linux/sched.h>
75665+#include <linux/timer.h>
75666+#include <linux/gracl.h>
75667+#include <linux/grsecurity.h>
75668+#include <linux/grinternal.h>
75669+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
75670+#include <linux/magic.h>
75671+#include <linux/pagemap.h>
75672+#include "../fs/btrfs/async-thread.h"
75673+#include "../fs/btrfs/ctree.h"
75674+#include "../fs/btrfs/btrfs_inode.h"
75675+#endif
75676+
75677+static struct crash_uid *uid_set;
75678+static unsigned short uid_used;
75679+static DEFINE_SPINLOCK(gr_uid_lock);
75680+extern rwlock_t gr_inode_lock;
75681+extern struct acl_subject_label *
75682+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
75683+ struct acl_role_label *role);
75684+
75685+static inline dev_t __get_dev(const struct dentry *dentry)
75686+{
75687+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
75688+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
75689+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
75690+ else
75691+#endif
75692+ return dentry->d_sb->s_dev;
75693+}
75694+
75695+int
75696+gr_init_uidset(void)
75697+{
75698+ uid_set =
75699+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
75700+ uid_used = 0;
75701+
75702+ return uid_set ? 1 : 0;
75703+}
75704+
75705+void
75706+gr_free_uidset(void)
75707+{
75708+ if (uid_set) {
75709+ struct crash_uid *tmpset;
75710+ spin_lock(&gr_uid_lock);
75711+ tmpset = uid_set;
75712+ uid_set = NULL;
75713+ uid_used = 0;
75714+ spin_unlock(&gr_uid_lock);
75715+ if (tmpset)
75716+ kfree(tmpset);
75717+ }
75718+
75719+ return;
75720+}
75721+
75722+int
75723+gr_find_uid(const uid_t uid)
75724+{
75725+ struct crash_uid *tmp = uid_set;
75726+ uid_t buid;
75727+ int low = 0, high = uid_used - 1, mid;
75728+
75729+ while (high >= low) {
75730+ mid = (low + high) >> 1;
75731+ buid = tmp[mid].uid;
75732+ if (buid == uid)
75733+ return mid;
75734+ if (buid > uid)
75735+ high = mid - 1;
75736+ if (buid < uid)
75737+ low = mid + 1;
75738+ }
75739+
75740+ return -1;
75741+}
75742+
75743+static __inline__ void
75744+gr_insertsort(void)
75745+{
75746+ unsigned short i, j;
75747+ struct crash_uid index;
75748+
75749+ for (i = 1; i < uid_used; i++) {
75750+ index = uid_set[i];
75751+ j = i;
75752+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
75753+ uid_set[j] = uid_set[j - 1];
75754+ j--;
75755+ }
75756+ uid_set[j] = index;
75757+ }
75758+
75759+ return;
75760+}
75761+
75762+static __inline__ void
75763+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
75764+{
75765+ int loc;
75766+ uid_t uid = GR_GLOBAL_UID(kuid);
75767+
75768+ if (uid_used == GR_UIDTABLE_MAX)
75769+ return;
75770+
75771+ loc = gr_find_uid(uid);
75772+
75773+ if (loc >= 0) {
75774+ uid_set[loc].expires = expires;
75775+ return;
75776+ }
75777+
75778+ uid_set[uid_used].uid = uid;
75779+ uid_set[uid_used].expires = expires;
75780+ uid_used++;
75781+
75782+ gr_insertsort();
75783+
75784+ return;
75785+}
75786+
75787+void
75788+gr_remove_uid(const unsigned short loc)
75789+{
75790+ unsigned short i;
75791+
75792+ for (i = loc + 1; i < uid_used; i++)
75793+ uid_set[i - 1] = uid_set[i];
75794+
75795+ uid_used--;
75796+
75797+ return;
75798+}
75799+
75800+int
75801+gr_check_crash_uid(const kuid_t kuid)
75802+{
75803+ int loc;
75804+ int ret = 0;
75805+ uid_t uid;
75806+
75807+ if (unlikely(!gr_acl_is_enabled()))
75808+ return 0;
75809+
75810+ uid = GR_GLOBAL_UID(kuid);
75811+
75812+ spin_lock(&gr_uid_lock);
75813+ loc = gr_find_uid(uid);
75814+
75815+ if (loc < 0)
75816+ goto out_unlock;
75817+
75818+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
75819+ gr_remove_uid(loc);
75820+ else
75821+ ret = 1;
75822+
75823+out_unlock:
75824+ spin_unlock(&gr_uid_lock);
75825+ return ret;
75826+}
75827+
75828+static __inline__ int
75829+proc_is_setxid(const struct cred *cred)
75830+{
75831+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
75832+ !uid_eq(cred->uid, cred->fsuid))
75833+ return 1;
75834+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
75835+ !gid_eq(cred->gid, cred->fsgid))
75836+ return 1;
75837+
75838+ return 0;
75839+}
75840+
75841+extern int gr_fake_force_sig(int sig, struct task_struct *t);
75842+
75843+void
75844+gr_handle_crash(struct task_struct *task, const int sig)
75845+{
75846+ struct acl_subject_label *curr;
75847+ struct task_struct *tsk, *tsk2;
75848+ const struct cred *cred;
75849+ const struct cred *cred2;
75850+
75851+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
75852+ return;
75853+
75854+ if (unlikely(!gr_acl_is_enabled()))
75855+ return;
75856+
75857+ curr = task->acl;
75858+
75859+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
75860+ return;
75861+
75862+ if (time_before_eq(curr->expires, get_seconds())) {
75863+ curr->expires = 0;
75864+ curr->crashes = 0;
75865+ }
75866+
75867+ curr->crashes++;
75868+
75869+ if (!curr->expires)
75870+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
75871+
75872+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
75873+ time_after(curr->expires, get_seconds())) {
75874+ rcu_read_lock();
75875+ cred = __task_cred(task);
75876+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
75877+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
75878+ spin_lock(&gr_uid_lock);
75879+ gr_insert_uid(cred->uid, curr->expires);
75880+ spin_unlock(&gr_uid_lock);
75881+ curr->expires = 0;
75882+ curr->crashes = 0;
75883+ read_lock(&tasklist_lock);
75884+ do_each_thread(tsk2, tsk) {
75885+ cred2 = __task_cred(tsk);
75886+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
75887+ gr_fake_force_sig(SIGKILL, tsk);
75888+ } while_each_thread(tsk2, tsk);
75889+ read_unlock(&tasklist_lock);
75890+ } else {
75891+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
75892+ read_lock(&tasklist_lock);
75893+ read_lock(&grsec_exec_file_lock);
75894+ do_each_thread(tsk2, tsk) {
75895+ if (likely(tsk != task)) {
75896+ // if this thread has the same subject as the one that triggered
75897+ // RES_CRASH and it's the same binary, kill it
75898+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
75899+ gr_fake_force_sig(SIGKILL, tsk);
75900+ }
75901+ } while_each_thread(tsk2, tsk);
75902+ read_unlock(&grsec_exec_file_lock);
75903+ read_unlock(&tasklist_lock);
75904+ }
75905+ rcu_read_unlock();
75906+ }
75907+
75908+ return;
75909+}
75910+
75911+int
75912+gr_check_crash_exec(const struct file *filp)
75913+{
75914+ struct acl_subject_label *curr;
75915+
75916+ if (unlikely(!gr_acl_is_enabled()))
75917+ return 0;
75918+
75919+ read_lock(&gr_inode_lock);
75920+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
75921+ __get_dev(filp->f_path.dentry),
75922+ current->role);
75923+ read_unlock(&gr_inode_lock);
75924+
75925+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
75926+ (!curr->crashes && !curr->expires))
75927+ return 0;
75928+
75929+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
75930+ time_after(curr->expires, get_seconds()))
75931+ return 1;
75932+ else if (time_before_eq(curr->expires, get_seconds())) {
75933+ curr->crashes = 0;
75934+ curr->expires = 0;
75935+ }
75936+
75937+ return 0;
75938+}
75939+
75940+void
75941+gr_handle_alertkill(struct task_struct *task)
75942+{
75943+ struct acl_subject_label *curracl;
75944+ __u32 curr_ip;
75945+ struct task_struct *p, *p2;
75946+
75947+ if (unlikely(!gr_acl_is_enabled()))
75948+ return;
75949+
75950+ curracl = task->acl;
75951+ curr_ip = task->signal->curr_ip;
75952+
75953+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
75954+ read_lock(&tasklist_lock);
75955+ do_each_thread(p2, p) {
75956+ if (p->signal->curr_ip == curr_ip)
75957+ gr_fake_force_sig(SIGKILL, p);
75958+ } while_each_thread(p2, p);
75959+ read_unlock(&tasklist_lock);
75960+ } else if (curracl->mode & GR_KILLPROC)
75961+ gr_fake_force_sig(SIGKILL, task);
75962+
75963+ return;
75964+}
75965diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
75966new file mode 100644
75967index 0000000..6b0c9cc
75968--- /dev/null
75969+++ b/grsecurity/gracl_shm.c
75970@@ -0,0 +1,40 @@
75971+#include <linux/kernel.h>
75972+#include <linux/mm.h>
75973+#include <linux/sched.h>
75974+#include <linux/file.h>
75975+#include <linux/ipc.h>
75976+#include <linux/gracl.h>
75977+#include <linux/grsecurity.h>
75978+#include <linux/grinternal.h>
75979+
75980+int
75981+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
75982+ const u64 shm_createtime, const kuid_t cuid, const int shmid)
75983+{
75984+ struct task_struct *task;
75985+
75986+ if (!gr_acl_is_enabled())
75987+ return 1;
75988+
75989+ rcu_read_lock();
75990+ read_lock(&tasklist_lock);
75991+
75992+ task = find_task_by_vpid(shm_cprid);
75993+
75994+ if (unlikely(!task))
75995+ task = find_task_by_vpid(shm_lapid);
75996+
75997+ if (unlikely(task && (time_before_eq64(task->start_time, shm_createtime) ||
75998+ (task_pid_nr(task) == shm_lapid)) &&
75999+ (task->acl->mode & GR_PROTSHM) &&
76000+ (task->acl != current->acl))) {
76001+ read_unlock(&tasklist_lock);
76002+ rcu_read_unlock();
76003+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
76004+ return 0;
76005+ }
76006+ read_unlock(&tasklist_lock);
76007+ rcu_read_unlock();
76008+
76009+ return 1;
76010+}
76011diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
76012new file mode 100644
76013index 0000000..bc0be01
76014--- /dev/null
76015+++ b/grsecurity/grsec_chdir.c
76016@@ -0,0 +1,19 @@
76017+#include <linux/kernel.h>
76018+#include <linux/sched.h>
76019+#include <linux/fs.h>
76020+#include <linux/file.h>
76021+#include <linux/grsecurity.h>
76022+#include <linux/grinternal.h>
76023+
76024+void
76025+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
76026+{
76027+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76028+ if ((grsec_enable_chdir && grsec_enable_group &&
76029+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
76030+ !grsec_enable_group)) {
76031+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
76032+ }
76033+#endif
76034+ return;
76035+}
76036diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
76037new file mode 100644
76038index 0000000..6d99cec
76039--- /dev/null
76040+++ b/grsecurity/grsec_chroot.c
76041@@ -0,0 +1,385 @@
76042+#include <linux/kernel.h>
76043+#include <linux/module.h>
76044+#include <linux/sched.h>
76045+#include <linux/file.h>
76046+#include <linux/fs.h>
76047+#include <linux/mount.h>
76048+#include <linux/types.h>
76049+#include "../fs/mount.h"
76050+#include <linux/grsecurity.h>
76051+#include <linux/grinternal.h>
76052+
76053+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76054+int gr_init_ran;
76055+#endif
76056+
76057+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
76058+{
76059+#ifdef CONFIG_GRKERNSEC
76060+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
76061+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
76062+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76063+ && gr_init_ran
76064+#endif
76065+ )
76066+ task->gr_is_chrooted = 1;
76067+ else {
76068+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76069+ if (task_pid_nr(task) == 1 && !gr_init_ran)
76070+ gr_init_ran = 1;
76071+#endif
76072+ task->gr_is_chrooted = 0;
76073+ }
76074+
76075+ task->gr_chroot_dentry = path->dentry;
76076+#endif
76077+ return;
76078+}
76079+
76080+void gr_clear_chroot_entries(struct task_struct *task)
76081+{
76082+#ifdef CONFIG_GRKERNSEC
76083+ task->gr_is_chrooted = 0;
76084+ task->gr_chroot_dentry = NULL;
76085+#endif
76086+ return;
76087+}
76088+
76089+int
76090+gr_handle_chroot_unix(const pid_t pid)
76091+{
76092+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76093+ struct task_struct *p;
76094+
76095+ if (unlikely(!grsec_enable_chroot_unix))
76096+ return 1;
76097+
76098+ if (likely(!proc_is_chrooted(current)))
76099+ return 1;
76100+
76101+ rcu_read_lock();
76102+ read_lock(&tasklist_lock);
76103+ p = find_task_by_vpid_unrestricted(pid);
76104+ if (unlikely(p && !have_same_root(current, p))) {
76105+ read_unlock(&tasklist_lock);
76106+ rcu_read_unlock();
76107+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
76108+ return 0;
76109+ }
76110+ read_unlock(&tasklist_lock);
76111+ rcu_read_unlock();
76112+#endif
76113+ return 1;
76114+}
76115+
76116+int
76117+gr_handle_chroot_nice(void)
76118+{
76119+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76120+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
76121+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
76122+ return -EPERM;
76123+ }
76124+#endif
76125+ return 0;
76126+}
76127+
76128+int
76129+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
76130+{
76131+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76132+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
76133+ && proc_is_chrooted(current)) {
76134+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
76135+ return -EACCES;
76136+ }
76137+#endif
76138+ return 0;
76139+}
76140+
76141+int
76142+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
76143+{
76144+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76145+ struct task_struct *p;
76146+ int ret = 0;
76147+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
76148+ return ret;
76149+
76150+ read_lock(&tasklist_lock);
76151+ do_each_pid_task(pid, type, p) {
76152+ if (!have_same_root(current, p)) {
76153+ ret = 1;
76154+ goto out;
76155+ }
76156+ } while_each_pid_task(pid, type, p);
76157+out:
76158+ read_unlock(&tasklist_lock);
76159+ return ret;
76160+#endif
76161+ return 0;
76162+}
76163+
76164+int
76165+gr_pid_is_chrooted(struct task_struct *p)
76166+{
76167+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76168+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
76169+ return 0;
76170+
76171+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
76172+ !have_same_root(current, p)) {
76173+ return 1;
76174+ }
76175+#endif
76176+ return 0;
76177+}
76178+
76179+EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
76180+
76181+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
76182+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
76183+{
76184+ struct path path, currentroot;
76185+ int ret = 0;
76186+
76187+ path.dentry = (struct dentry *)u_dentry;
76188+ path.mnt = (struct vfsmount *)u_mnt;
76189+ get_fs_root(current->fs, &currentroot);
76190+ if (path_is_under(&path, &currentroot))
76191+ ret = 1;
76192+ path_put(&currentroot);
76193+
76194+ return ret;
76195+}
76196+#endif
76197+
76198+int
76199+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
76200+{
76201+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76202+ if (!grsec_enable_chroot_fchdir)
76203+ return 1;
76204+
76205+ if (!proc_is_chrooted(current))
76206+ return 1;
76207+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
76208+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
76209+ return 0;
76210+ }
76211+#endif
76212+ return 1;
76213+}
76214+
76215+int
76216+gr_chroot_fhandle(void)
76217+{
76218+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76219+ if (!grsec_enable_chroot_fchdir)
76220+ return 1;
76221+
76222+ if (!proc_is_chrooted(current))
76223+ return 1;
76224+ else {
76225+ gr_log_noargs(GR_DONT_AUDIT, GR_CHROOT_FHANDLE_MSG);
76226+ return 0;
76227+ }
76228+#endif
76229+ return 1;
76230+}
76231+
76232+int
76233+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76234+ const u64 shm_createtime)
76235+{
76236+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
76237+ struct task_struct *p;
76238+
76239+ if (unlikely(!grsec_enable_chroot_shmat))
76240+ return 1;
76241+
76242+ if (likely(!proc_is_chrooted(current)))
76243+ return 1;
76244+
76245+ rcu_read_lock();
76246+ read_lock(&tasklist_lock);
76247+
76248+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
76249+ if (time_before_eq64(p->start_time, shm_createtime)) {
76250+ if (have_same_root(current, p)) {
76251+ goto allow;
76252+ } else {
76253+ read_unlock(&tasklist_lock);
76254+ rcu_read_unlock();
76255+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
76256+ return 0;
76257+ }
76258+ }
76259+ /* creator exited, pid reuse, fall through to next check */
76260+ }
76261+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
76262+ if (unlikely(!have_same_root(current, p))) {
76263+ read_unlock(&tasklist_lock);
76264+ rcu_read_unlock();
76265+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
76266+ return 0;
76267+ }
76268+ }
76269+
76270+allow:
76271+ read_unlock(&tasklist_lock);
76272+ rcu_read_unlock();
76273+#endif
76274+ return 1;
76275+}
76276+
76277+void
76278+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
76279+{
76280+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
76281+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
76282+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
76283+#endif
76284+ return;
76285+}
76286+
76287+int
76288+gr_handle_chroot_mknod(const struct dentry *dentry,
76289+ const struct vfsmount *mnt, const int mode)
76290+{
76291+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
76292+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
76293+ proc_is_chrooted(current)) {
76294+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
76295+ return -EPERM;
76296+ }
76297+#endif
76298+ return 0;
76299+}
76300+
76301+int
76302+gr_handle_chroot_mount(const struct dentry *dentry,
76303+ const struct vfsmount *mnt, const char *dev_name)
76304+{
76305+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
76306+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
76307+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
76308+ return -EPERM;
76309+ }
76310+#endif
76311+ return 0;
76312+}
76313+
76314+int
76315+gr_handle_chroot_pivot(void)
76316+{
76317+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
76318+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
76319+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
76320+ return -EPERM;
76321+ }
76322+#endif
76323+ return 0;
76324+}
76325+
76326+int
76327+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
76328+{
76329+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
76330+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
76331+ !gr_is_outside_chroot(dentry, mnt)) {
76332+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
76333+ return -EPERM;
76334+ }
76335+#endif
76336+ return 0;
76337+}
76338+
76339+extern const char *captab_log[];
76340+extern int captab_log_entries;
76341+
76342+int
76343+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
76344+{
76345+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76346+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
76347+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
76348+ if (cap_raised(chroot_caps, cap)) {
76349+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
76350+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
76351+ }
76352+ return 0;
76353+ }
76354+ }
76355+#endif
76356+ return 1;
76357+}
76358+
76359+int
76360+gr_chroot_is_capable(const int cap)
76361+{
76362+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76363+ return gr_task_chroot_is_capable(current, current_cred(), cap);
76364+#endif
76365+ return 1;
76366+}
76367+
76368+int
76369+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
76370+{
76371+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76372+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
76373+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
76374+ if (cap_raised(chroot_caps, cap)) {
76375+ return 0;
76376+ }
76377+ }
76378+#endif
76379+ return 1;
76380+}
76381+
76382+int
76383+gr_chroot_is_capable_nolog(const int cap)
76384+{
76385+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76386+ return gr_task_chroot_is_capable_nolog(current, cap);
76387+#endif
76388+ return 1;
76389+}
76390+
76391+int
76392+gr_handle_chroot_sysctl(const int op)
76393+{
76394+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76395+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
76396+ proc_is_chrooted(current))
76397+ return -EACCES;
76398+#endif
76399+ return 0;
76400+}
76401+
76402+void
76403+gr_handle_chroot_chdir(const struct path *path)
76404+{
76405+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76406+ if (grsec_enable_chroot_chdir)
76407+ set_fs_pwd(current->fs, path);
76408+#endif
76409+ return;
76410+}
76411+
76412+int
76413+gr_handle_chroot_chmod(const struct dentry *dentry,
76414+ const struct vfsmount *mnt, const int mode)
76415+{
76416+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76417+ /* allow chmod +s on directories, but not files */
76418+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
76419+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
76420+ proc_is_chrooted(current)) {
76421+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
76422+ return -EPERM;
76423+ }
76424+#endif
76425+ return 0;
76426+}
76427diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
76428new file mode 100644
76429index 0000000..0f9ac91
76430--- /dev/null
76431+++ b/grsecurity/grsec_disabled.c
76432@@ -0,0 +1,440 @@
76433+#include <linux/kernel.h>
76434+#include <linux/module.h>
76435+#include <linux/sched.h>
76436+#include <linux/file.h>
76437+#include <linux/fs.h>
76438+#include <linux/kdev_t.h>
76439+#include <linux/net.h>
76440+#include <linux/in.h>
76441+#include <linux/ip.h>
76442+#include <linux/skbuff.h>
76443+#include <linux/sysctl.h>
76444+
76445+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
76446+void
76447+pax_set_initial_flags(struct linux_binprm *bprm)
76448+{
76449+ return;
76450+}
76451+#endif
76452+
76453+#ifdef CONFIG_SYSCTL
76454+__u32
76455+gr_handle_sysctl(const struct ctl_table * table, const int op)
76456+{
76457+ return 0;
76458+}
76459+#endif
76460+
76461+#ifdef CONFIG_TASKSTATS
76462+int gr_is_taskstats_denied(int pid)
76463+{
76464+ return 0;
76465+}
76466+#endif
76467+
76468+int
76469+gr_acl_is_enabled(void)
76470+{
76471+ return 0;
76472+}
76473+
76474+int
76475+gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
76476+{
76477+ return 0;
76478+}
76479+
76480+void
76481+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
76482+{
76483+ return;
76484+}
76485+
76486+int
76487+gr_handle_rawio(const struct inode *inode)
76488+{
76489+ return 0;
76490+}
76491+
76492+void
76493+gr_acl_handle_psacct(struct task_struct *task, const long code)
76494+{
76495+ return;
76496+}
76497+
76498+int
76499+gr_handle_ptrace(struct task_struct *task, const long request)
76500+{
76501+ return 0;
76502+}
76503+
76504+int
76505+gr_handle_proc_ptrace(struct task_struct *task)
76506+{
76507+ return 0;
76508+}
76509+
76510+int
76511+gr_set_acls(const int type)
76512+{
76513+ return 0;
76514+}
76515+
76516+int
76517+gr_check_hidden_task(const struct task_struct *tsk)
76518+{
76519+ return 0;
76520+}
76521+
76522+int
76523+gr_check_protected_task(const struct task_struct *task)
76524+{
76525+ return 0;
76526+}
76527+
76528+int
76529+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
76530+{
76531+ return 0;
76532+}
76533+
76534+void
76535+gr_copy_label(struct task_struct *tsk)
76536+{
76537+ return;
76538+}
76539+
76540+void
76541+gr_set_pax_flags(struct task_struct *task)
76542+{
76543+ return;
76544+}
76545+
76546+int
76547+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
76548+ const int unsafe_share)
76549+{
76550+ return 0;
76551+}
76552+
76553+void
76554+gr_handle_delete(const ino_t ino, const dev_t dev)
76555+{
76556+ return;
76557+}
76558+
76559+void
76560+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
76561+{
76562+ return;
76563+}
76564+
76565+void
76566+gr_handle_crash(struct task_struct *task, const int sig)
76567+{
76568+ return;
76569+}
76570+
76571+int
76572+gr_check_crash_exec(const struct file *filp)
76573+{
76574+ return 0;
76575+}
76576+
76577+int
76578+gr_check_crash_uid(const kuid_t uid)
76579+{
76580+ return 0;
76581+}
76582+
76583+void
76584+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
76585+ struct dentry *old_dentry,
76586+ struct dentry *new_dentry,
76587+ struct vfsmount *mnt, const __u8 replace, unsigned int flags)
76588+{
76589+ return;
76590+}
76591+
76592+int
76593+gr_search_socket(const int family, const int type, const int protocol)
76594+{
76595+ return 1;
76596+}
76597+
76598+int
76599+gr_search_connectbind(const int mode, const struct socket *sock,
76600+ const struct sockaddr_in *addr)
76601+{
76602+ return 0;
76603+}
76604+
76605+void
76606+gr_handle_alertkill(struct task_struct *task)
76607+{
76608+ return;
76609+}
76610+
76611+__u32
76612+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
76613+{
76614+ return 1;
76615+}
76616+
76617+__u32
76618+gr_acl_handle_hidden_file(const struct dentry * dentry,
76619+ const struct vfsmount * mnt)
76620+{
76621+ return 1;
76622+}
76623+
76624+__u32
76625+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
76626+ int acc_mode)
76627+{
76628+ return 1;
76629+}
76630+
76631+__u32
76632+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
76633+{
76634+ return 1;
76635+}
76636+
76637+__u32
76638+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
76639+{
76640+ return 1;
76641+}
76642+
76643+int
76644+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
76645+ unsigned int *vm_flags)
76646+{
76647+ return 1;
76648+}
76649+
76650+__u32
76651+gr_acl_handle_truncate(const struct dentry * dentry,
76652+ const struct vfsmount * mnt)
76653+{
76654+ return 1;
76655+}
76656+
76657+__u32
76658+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
76659+{
76660+ return 1;
76661+}
76662+
76663+__u32
76664+gr_acl_handle_access(const struct dentry * dentry,
76665+ const struct vfsmount * mnt, const int fmode)
76666+{
76667+ return 1;
76668+}
76669+
76670+__u32
76671+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
76672+ umode_t *mode)
76673+{
76674+ return 1;
76675+}
76676+
76677+__u32
76678+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
76679+{
76680+ return 1;
76681+}
76682+
76683+__u32
76684+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
76685+{
76686+ return 1;
76687+}
76688+
76689+__u32
76690+gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
76691+{
76692+ return 1;
76693+}
76694+
76695+void
76696+grsecurity_init(void)
76697+{
76698+ return;
76699+}
76700+
76701+umode_t gr_acl_umask(void)
76702+{
76703+ return 0;
76704+}
76705+
76706+__u32
76707+gr_acl_handle_mknod(const struct dentry * new_dentry,
76708+ const struct dentry * parent_dentry,
76709+ const struct vfsmount * parent_mnt,
76710+ const int mode)
76711+{
76712+ return 1;
76713+}
76714+
76715+__u32
76716+gr_acl_handle_mkdir(const struct dentry * new_dentry,
76717+ const struct dentry * parent_dentry,
76718+ const struct vfsmount * parent_mnt)
76719+{
76720+ return 1;
76721+}
76722+
76723+__u32
76724+gr_acl_handle_symlink(const struct dentry * new_dentry,
76725+ const struct dentry * parent_dentry,
76726+ const struct vfsmount * parent_mnt, const struct filename *from)
76727+{
76728+ return 1;
76729+}
76730+
76731+__u32
76732+gr_acl_handle_link(const struct dentry * new_dentry,
76733+ const struct dentry * parent_dentry,
76734+ const struct vfsmount * parent_mnt,
76735+ const struct dentry * old_dentry,
76736+ const struct vfsmount * old_mnt, const struct filename *to)
76737+{
76738+ return 1;
76739+}
76740+
76741+int
76742+gr_acl_handle_rename(const struct dentry *new_dentry,
76743+ const struct dentry *parent_dentry,
76744+ const struct vfsmount *parent_mnt,
76745+ const struct dentry *old_dentry,
76746+ const struct inode *old_parent_inode,
76747+ const struct vfsmount *old_mnt, const struct filename *newname,
76748+ unsigned int flags)
76749+{
76750+ return 0;
76751+}
76752+
76753+int
76754+gr_acl_handle_filldir(const struct file *file, const char *name,
76755+ const int namelen, const ino_t ino)
76756+{
76757+ return 1;
76758+}
76759+
76760+int
76761+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76762+ const u64 shm_createtime, const kuid_t cuid, const int shmid)
76763+{
76764+ return 1;
76765+}
76766+
76767+int
76768+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
76769+{
76770+ return 0;
76771+}
76772+
76773+int
76774+gr_search_accept(const struct socket *sock)
76775+{
76776+ return 0;
76777+}
76778+
76779+int
76780+gr_search_listen(const struct socket *sock)
76781+{
76782+ return 0;
76783+}
76784+
76785+int
76786+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
76787+{
76788+ return 0;
76789+}
76790+
76791+__u32
76792+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
76793+{
76794+ return 1;
76795+}
76796+
76797+__u32
76798+gr_acl_handle_creat(const struct dentry * dentry,
76799+ const struct dentry * p_dentry,
76800+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
76801+ const int imode)
76802+{
76803+ return 1;
76804+}
76805+
76806+void
76807+gr_acl_handle_exit(void)
76808+{
76809+ return;
76810+}
76811+
76812+int
76813+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
76814+{
76815+ return 1;
76816+}
76817+
76818+void
76819+gr_set_role_label(const kuid_t uid, const kgid_t gid)
76820+{
76821+ return;
76822+}
76823+
76824+int
76825+gr_acl_handle_procpidmem(const struct task_struct *task)
76826+{
76827+ return 0;
76828+}
76829+
76830+int
76831+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
76832+{
76833+ return 0;
76834+}
76835+
76836+int
76837+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
76838+{
76839+ return 0;
76840+}
76841+
76842+int
76843+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
76844+{
76845+ return 0;
76846+}
76847+
76848+int
76849+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
76850+{
76851+ return 0;
76852+}
76853+
76854+int gr_acl_enable_at_secure(void)
76855+{
76856+ return 0;
76857+}
76858+
76859+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
76860+{
76861+ return dentry->d_sb->s_dev;
76862+}
76863+
76864+void gr_put_exec_file(struct task_struct *task)
76865+{
76866+ return;
76867+}
76868+
76869+#ifdef CONFIG_SECURITY
76870+EXPORT_SYMBOL_GPL(gr_check_user_change);
76871+EXPORT_SYMBOL_GPL(gr_check_group_change);
76872+#endif
76873diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
76874new file mode 100644
76875index 0000000..14638ff
76876--- /dev/null
76877+++ b/grsecurity/grsec_exec.c
76878@@ -0,0 +1,188 @@
76879+#include <linux/kernel.h>
76880+#include <linux/sched.h>
76881+#include <linux/file.h>
76882+#include <linux/binfmts.h>
76883+#include <linux/fs.h>
76884+#include <linux/types.h>
76885+#include <linux/grdefs.h>
76886+#include <linux/grsecurity.h>
76887+#include <linux/grinternal.h>
76888+#include <linux/capability.h>
76889+#include <linux/module.h>
76890+#include <linux/compat.h>
76891+
76892+#include <asm/uaccess.h>
76893+
76894+#ifdef CONFIG_GRKERNSEC_EXECLOG
76895+static char gr_exec_arg_buf[132];
76896+static DEFINE_MUTEX(gr_exec_arg_mutex);
76897+#endif
76898+
76899+struct user_arg_ptr {
76900+#ifdef CONFIG_COMPAT
76901+ bool is_compat;
76902+#endif
76903+ union {
76904+ const char __user *const __user *native;
76905+#ifdef CONFIG_COMPAT
76906+ const compat_uptr_t __user *compat;
76907+#endif
76908+ } ptr;
76909+};
76910+
76911+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
76912+
76913+void
76914+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
76915+{
76916+#ifdef CONFIG_GRKERNSEC_EXECLOG
76917+ char *grarg = gr_exec_arg_buf;
76918+ unsigned int i, x, execlen = 0;
76919+ char c;
76920+
76921+ if (!((grsec_enable_execlog && grsec_enable_group &&
76922+ in_group_p(grsec_audit_gid))
76923+ || (grsec_enable_execlog && !grsec_enable_group)))
76924+ return;
76925+
76926+ mutex_lock(&gr_exec_arg_mutex);
76927+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
76928+
76929+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
76930+ const char __user *p;
76931+ unsigned int len;
76932+
76933+ p = get_user_arg_ptr(argv, i);
76934+ if (IS_ERR(p))
76935+ goto log;
76936+
76937+ len = strnlen_user(p, 128 - execlen);
76938+ if (len > 128 - execlen)
76939+ len = 128 - execlen;
76940+ else if (len > 0)
76941+ len--;
76942+ if (copy_from_user(grarg + execlen, p, len))
76943+ goto log;
76944+
76945+ /* rewrite unprintable characters */
76946+ for (x = 0; x < len; x++) {
76947+ c = *(grarg + execlen + x);
76948+ if (c < 32 || c > 126)
76949+ *(grarg + execlen + x) = ' ';
76950+ }
76951+
76952+ execlen += len;
76953+ *(grarg + execlen) = ' ';
76954+ *(grarg + execlen + 1) = '\0';
76955+ execlen++;
76956+ }
76957+
76958+ log:
76959+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
76960+ bprm->file->f_path.mnt, grarg);
76961+ mutex_unlock(&gr_exec_arg_mutex);
76962+#endif
76963+ return;
76964+}
76965+
76966+#ifdef CONFIG_GRKERNSEC
76967+extern int gr_acl_is_capable(const int cap);
76968+extern int gr_acl_is_capable_nolog(const int cap);
76969+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
76970+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
76971+extern int gr_chroot_is_capable(const int cap);
76972+extern int gr_chroot_is_capable_nolog(const int cap);
76973+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
76974+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
76975+#endif
76976+
76977+const char *captab_log[] = {
76978+ "CAP_CHOWN",
76979+ "CAP_DAC_OVERRIDE",
76980+ "CAP_DAC_READ_SEARCH",
76981+ "CAP_FOWNER",
76982+ "CAP_FSETID",
76983+ "CAP_KILL",
76984+ "CAP_SETGID",
76985+ "CAP_SETUID",
76986+ "CAP_SETPCAP",
76987+ "CAP_LINUX_IMMUTABLE",
76988+ "CAP_NET_BIND_SERVICE",
76989+ "CAP_NET_BROADCAST",
76990+ "CAP_NET_ADMIN",
76991+ "CAP_NET_RAW",
76992+ "CAP_IPC_LOCK",
76993+ "CAP_IPC_OWNER",
76994+ "CAP_SYS_MODULE",
76995+ "CAP_SYS_RAWIO",
76996+ "CAP_SYS_CHROOT",
76997+ "CAP_SYS_PTRACE",
76998+ "CAP_SYS_PACCT",
76999+ "CAP_SYS_ADMIN",
77000+ "CAP_SYS_BOOT",
77001+ "CAP_SYS_NICE",
77002+ "CAP_SYS_RESOURCE",
77003+ "CAP_SYS_TIME",
77004+ "CAP_SYS_TTY_CONFIG",
77005+ "CAP_MKNOD",
77006+ "CAP_LEASE",
77007+ "CAP_AUDIT_WRITE",
77008+ "CAP_AUDIT_CONTROL",
77009+ "CAP_SETFCAP",
77010+ "CAP_MAC_OVERRIDE",
77011+ "CAP_MAC_ADMIN",
77012+ "CAP_SYSLOG",
77013+ "CAP_WAKE_ALARM",
77014+ "CAP_BLOCK_SUSPEND"
77015+};
77016+
77017+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
77018+
77019+int gr_is_capable(const int cap)
77020+{
77021+#ifdef CONFIG_GRKERNSEC
77022+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
77023+ return 1;
77024+ return 0;
77025+#else
77026+ return 1;
77027+#endif
77028+}
77029+
77030+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
77031+{
77032+#ifdef CONFIG_GRKERNSEC
77033+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
77034+ return 1;
77035+ return 0;
77036+#else
77037+ return 1;
77038+#endif
77039+}
77040+
77041+int gr_is_capable_nolog(const int cap)
77042+{
77043+#ifdef CONFIG_GRKERNSEC
77044+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
77045+ return 1;
77046+ return 0;
77047+#else
77048+ return 1;
77049+#endif
77050+}
77051+
77052+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
77053+{
77054+#ifdef CONFIG_GRKERNSEC
77055+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
77056+ return 1;
77057+ return 0;
77058+#else
77059+ return 1;
77060+#endif
77061+}
77062+
77063+EXPORT_SYMBOL_GPL(gr_is_capable);
77064+EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
77065+EXPORT_SYMBOL_GPL(gr_task_is_capable);
77066+EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
77067diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
77068new file mode 100644
77069index 0000000..06cc6ea
77070--- /dev/null
77071+++ b/grsecurity/grsec_fifo.c
77072@@ -0,0 +1,24 @@
77073+#include <linux/kernel.h>
77074+#include <linux/sched.h>
77075+#include <linux/fs.h>
77076+#include <linux/file.h>
77077+#include <linux/grinternal.h>
77078+
77079+int
77080+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
77081+ const struct dentry *dir, const int flag, const int acc_mode)
77082+{
77083+#ifdef CONFIG_GRKERNSEC_FIFO
77084+ const struct cred *cred = current_cred();
77085+
77086+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
77087+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
77088+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
77089+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
77090+ if (!inode_permission(dentry->d_inode, acc_mode))
77091+ 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));
77092+ return -EACCES;
77093+ }
77094+#endif
77095+ return 0;
77096+}
77097diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
77098new file mode 100644
77099index 0000000..8ca18bf
77100--- /dev/null
77101+++ b/grsecurity/grsec_fork.c
77102@@ -0,0 +1,23 @@
77103+#include <linux/kernel.h>
77104+#include <linux/sched.h>
77105+#include <linux/grsecurity.h>
77106+#include <linux/grinternal.h>
77107+#include <linux/errno.h>
77108+
77109+void
77110+gr_log_forkfail(const int retval)
77111+{
77112+#ifdef CONFIG_GRKERNSEC_FORKFAIL
77113+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
77114+ switch (retval) {
77115+ case -EAGAIN:
77116+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
77117+ break;
77118+ case -ENOMEM:
77119+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
77120+ break;
77121+ }
77122+ }
77123+#endif
77124+ return;
77125+}
77126diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
77127new file mode 100644
77128index 0000000..b7cb191
77129--- /dev/null
77130+++ b/grsecurity/grsec_init.c
77131@@ -0,0 +1,286 @@
77132+#include <linux/kernel.h>
77133+#include <linux/sched.h>
77134+#include <linux/mm.h>
77135+#include <linux/gracl.h>
77136+#include <linux/slab.h>
77137+#include <linux/vmalloc.h>
77138+#include <linux/percpu.h>
77139+#include <linux/module.h>
77140+
77141+int grsec_enable_ptrace_readexec;
77142+int grsec_enable_setxid;
77143+int grsec_enable_symlinkown;
77144+kgid_t grsec_symlinkown_gid;
77145+int grsec_enable_brute;
77146+int grsec_enable_link;
77147+int grsec_enable_dmesg;
77148+int grsec_enable_harden_ptrace;
77149+int grsec_enable_harden_ipc;
77150+int grsec_enable_fifo;
77151+int grsec_enable_execlog;
77152+int grsec_enable_signal;
77153+int grsec_enable_forkfail;
77154+int grsec_enable_audit_ptrace;
77155+int grsec_enable_time;
77156+int grsec_enable_group;
77157+kgid_t grsec_audit_gid;
77158+int grsec_enable_chdir;
77159+int grsec_enable_mount;
77160+int grsec_enable_rofs;
77161+int grsec_deny_new_usb;
77162+int grsec_enable_chroot_findtask;
77163+int grsec_enable_chroot_mount;
77164+int grsec_enable_chroot_shmat;
77165+int grsec_enable_chroot_fchdir;
77166+int grsec_enable_chroot_double;
77167+int grsec_enable_chroot_pivot;
77168+int grsec_enable_chroot_chdir;
77169+int grsec_enable_chroot_chmod;
77170+int grsec_enable_chroot_mknod;
77171+int grsec_enable_chroot_nice;
77172+int grsec_enable_chroot_execlog;
77173+int grsec_enable_chroot_caps;
77174+int grsec_enable_chroot_sysctl;
77175+int grsec_enable_chroot_unix;
77176+int grsec_enable_tpe;
77177+kgid_t grsec_tpe_gid;
77178+int grsec_enable_blackhole;
77179+#ifdef CONFIG_IPV6_MODULE
77180+EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
77181+#endif
77182+int grsec_lastack_retries;
77183+int grsec_enable_tpe_all;
77184+int grsec_enable_tpe_invert;
77185+int grsec_enable_socket_all;
77186+kgid_t grsec_socket_all_gid;
77187+int grsec_enable_socket_client;
77188+kgid_t grsec_socket_client_gid;
77189+int grsec_enable_socket_server;
77190+kgid_t grsec_socket_server_gid;
77191+int grsec_resource_logging;
77192+int grsec_disable_privio;
77193+int grsec_enable_log_rwxmaps;
77194+int grsec_lock;
77195+
77196+DEFINE_SPINLOCK(grsec_alert_lock);
77197+unsigned long grsec_alert_wtime = 0;
77198+unsigned long grsec_alert_fyet = 0;
77199+
77200+DEFINE_SPINLOCK(grsec_audit_lock);
77201+
77202+DEFINE_RWLOCK(grsec_exec_file_lock);
77203+
77204+char *gr_shared_page[4];
77205+
77206+char *gr_alert_log_fmt;
77207+char *gr_audit_log_fmt;
77208+char *gr_alert_log_buf;
77209+char *gr_audit_log_buf;
77210+
77211+extern struct gr_arg *gr_usermode;
77212+extern unsigned char *gr_system_salt;
77213+extern unsigned char *gr_system_sum;
77214+
77215+void __init
77216+grsecurity_init(void)
77217+{
77218+ int j;
77219+ /* create the per-cpu shared pages */
77220+
77221+#ifdef CONFIG_X86
77222+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
77223+#endif
77224+
77225+ for (j = 0; j < 4; j++) {
77226+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
77227+ if (gr_shared_page[j] == NULL) {
77228+ panic("Unable to allocate grsecurity shared page");
77229+ return;
77230+ }
77231+ }
77232+
77233+ /* allocate log buffers */
77234+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
77235+ if (!gr_alert_log_fmt) {
77236+ panic("Unable to allocate grsecurity alert log format buffer");
77237+ return;
77238+ }
77239+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
77240+ if (!gr_audit_log_fmt) {
77241+ panic("Unable to allocate grsecurity audit log format buffer");
77242+ return;
77243+ }
77244+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
77245+ if (!gr_alert_log_buf) {
77246+ panic("Unable to allocate grsecurity alert log buffer");
77247+ return;
77248+ }
77249+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
77250+ if (!gr_audit_log_buf) {
77251+ panic("Unable to allocate grsecurity audit log buffer");
77252+ return;
77253+ }
77254+
77255+ /* allocate memory for authentication structure */
77256+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
77257+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
77258+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
77259+
77260+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
77261+ panic("Unable to allocate grsecurity authentication structure");
77262+ return;
77263+ }
77264+
77265+#ifdef CONFIG_GRKERNSEC_IO
77266+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
77267+ grsec_disable_privio = 1;
77268+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
77269+ grsec_disable_privio = 1;
77270+#else
77271+ grsec_disable_privio = 0;
77272+#endif
77273+#endif
77274+
77275+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
77276+ /* for backward compatibility, tpe_invert always defaults to on if
77277+ enabled in the kernel
77278+ */
77279+ grsec_enable_tpe_invert = 1;
77280+#endif
77281+
77282+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
77283+#ifndef CONFIG_GRKERNSEC_SYSCTL
77284+ grsec_lock = 1;
77285+#endif
77286+
77287+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
77288+ grsec_enable_log_rwxmaps = 1;
77289+#endif
77290+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
77291+ grsec_enable_group = 1;
77292+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
77293+#endif
77294+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
77295+ grsec_enable_ptrace_readexec = 1;
77296+#endif
77297+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
77298+ grsec_enable_chdir = 1;
77299+#endif
77300+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
77301+ grsec_enable_harden_ptrace = 1;
77302+#endif
77303+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
77304+ grsec_enable_harden_ipc = 1;
77305+#endif
77306+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77307+ grsec_enable_mount = 1;
77308+#endif
77309+#ifdef CONFIG_GRKERNSEC_LINK
77310+ grsec_enable_link = 1;
77311+#endif
77312+#ifdef CONFIG_GRKERNSEC_BRUTE
77313+ grsec_enable_brute = 1;
77314+#endif
77315+#ifdef CONFIG_GRKERNSEC_DMESG
77316+ grsec_enable_dmesg = 1;
77317+#endif
77318+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77319+ grsec_enable_blackhole = 1;
77320+ grsec_lastack_retries = 4;
77321+#endif
77322+#ifdef CONFIG_GRKERNSEC_FIFO
77323+ grsec_enable_fifo = 1;
77324+#endif
77325+#ifdef CONFIG_GRKERNSEC_EXECLOG
77326+ grsec_enable_execlog = 1;
77327+#endif
77328+#ifdef CONFIG_GRKERNSEC_SETXID
77329+ grsec_enable_setxid = 1;
77330+#endif
77331+#ifdef CONFIG_GRKERNSEC_SIGNAL
77332+ grsec_enable_signal = 1;
77333+#endif
77334+#ifdef CONFIG_GRKERNSEC_FORKFAIL
77335+ grsec_enable_forkfail = 1;
77336+#endif
77337+#ifdef CONFIG_GRKERNSEC_TIME
77338+ grsec_enable_time = 1;
77339+#endif
77340+#ifdef CONFIG_GRKERNSEC_RESLOG
77341+ grsec_resource_logging = 1;
77342+#endif
77343+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
77344+ grsec_enable_chroot_findtask = 1;
77345+#endif
77346+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
77347+ grsec_enable_chroot_unix = 1;
77348+#endif
77349+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
77350+ grsec_enable_chroot_mount = 1;
77351+#endif
77352+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
77353+ grsec_enable_chroot_fchdir = 1;
77354+#endif
77355+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
77356+ grsec_enable_chroot_shmat = 1;
77357+#endif
77358+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
77359+ grsec_enable_audit_ptrace = 1;
77360+#endif
77361+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
77362+ grsec_enable_chroot_double = 1;
77363+#endif
77364+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
77365+ grsec_enable_chroot_pivot = 1;
77366+#endif
77367+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
77368+ grsec_enable_chroot_chdir = 1;
77369+#endif
77370+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
77371+ grsec_enable_chroot_chmod = 1;
77372+#endif
77373+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
77374+ grsec_enable_chroot_mknod = 1;
77375+#endif
77376+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
77377+ grsec_enable_chroot_nice = 1;
77378+#endif
77379+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
77380+ grsec_enable_chroot_execlog = 1;
77381+#endif
77382+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
77383+ grsec_enable_chroot_caps = 1;
77384+#endif
77385+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
77386+ grsec_enable_chroot_sysctl = 1;
77387+#endif
77388+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
77389+ grsec_enable_symlinkown = 1;
77390+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
77391+#endif
77392+#ifdef CONFIG_GRKERNSEC_TPE
77393+ grsec_enable_tpe = 1;
77394+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
77395+#ifdef CONFIG_GRKERNSEC_TPE_ALL
77396+ grsec_enable_tpe_all = 1;
77397+#endif
77398+#endif
77399+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
77400+ grsec_enable_socket_all = 1;
77401+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
77402+#endif
77403+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
77404+ grsec_enable_socket_client = 1;
77405+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
77406+#endif
77407+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
77408+ grsec_enable_socket_server = 1;
77409+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
77410+#endif
77411+#endif
77412+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
77413+ grsec_deny_new_usb = 1;
77414+#endif
77415+
77416+ return;
77417+}
77418diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
77419new file mode 100644
77420index 0000000..1773300
77421--- /dev/null
77422+++ b/grsecurity/grsec_ipc.c
77423@@ -0,0 +1,48 @@
77424+#include <linux/kernel.h>
77425+#include <linux/mm.h>
77426+#include <linux/sched.h>
77427+#include <linux/file.h>
77428+#include <linux/ipc.h>
77429+#include <linux/ipc_namespace.h>
77430+#include <linux/grsecurity.h>
77431+#include <linux/grinternal.h>
77432+
77433+int
77434+gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
77435+{
77436+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
77437+ int write;
77438+ int orig_granted_mode;
77439+ kuid_t euid;
77440+ kgid_t egid;
77441+
77442+ if (!grsec_enable_harden_ipc)
77443+ return 1;
77444+
77445+ euid = current_euid();
77446+ egid = current_egid();
77447+
77448+ write = requested_mode & 00002;
77449+ orig_granted_mode = ipcp->mode;
77450+
77451+ if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
77452+ orig_granted_mode >>= 6;
77453+ else {
77454+ /* if likely wrong permissions, lock to user */
77455+ if (orig_granted_mode & 0007)
77456+ orig_granted_mode = 0;
77457+ /* otherwise do a egid-only check */
77458+ else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
77459+ orig_granted_mode >>= 3;
77460+ /* otherwise, no access */
77461+ else
77462+ orig_granted_mode = 0;
77463+ }
77464+ if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
77465+ !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
77466+ gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
77467+ return 0;
77468+ }
77469+#endif
77470+ return 1;
77471+}
77472diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
77473new file mode 100644
77474index 0000000..5e05e20
77475--- /dev/null
77476+++ b/grsecurity/grsec_link.c
77477@@ -0,0 +1,58 @@
77478+#include <linux/kernel.h>
77479+#include <linux/sched.h>
77480+#include <linux/fs.h>
77481+#include <linux/file.h>
77482+#include <linux/grinternal.h>
77483+
77484+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
77485+{
77486+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
77487+ const struct inode *link_inode = link->dentry->d_inode;
77488+
77489+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
77490+ /* ignore root-owned links, e.g. /proc/self */
77491+ gr_is_global_nonroot(link_inode->i_uid) && target &&
77492+ !uid_eq(link_inode->i_uid, target->i_uid)) {
77493+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
77494+ return 1;
77495+ }
77496+#endif
77497+ return 0;
77498+}
77499+
77500+int
77501+gr_handle_follow_link(const struct inode *parent,
77502+ const struct inode *inode,
77503+ const struct dentry *dentry, const struct vfsmount *mnt)
77504+{
77505+#ifdef CONFIG_GRKERNSEC_LINK
77506+ const struct cred *cred = current_cred();
77507+
77508+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
77509+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
77510+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
77511+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
77512+ return -EACCES;
77513+ }
77514+#endif
77515+ return 0;
77516+}
77517+
77518+int
77519+gr_handle_hardlink(const struct dentry *dentry,
77520+ const struct vfsmount *mnt,
77521+ struct inode *inode, const int mode, const struct filename *to)
77522+{
77523+#ifdef CONFIG_GRKERNSEC_LINK
77524+ const struct cred *cred = current_cred();
77525+
77526+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
77527+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
77528+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
77529+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
77530+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
77531+ return -EPERM;
77532+ }
77533+#endif
77534+ return 0;
77535+}
77536diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
77537new file mode 100644
77538index 0000000..dbe0a6b
77539--- /dev/null
77540+++ b/grsecurity/grsec_log.c
77541@@ -0,0 +1,341 @@
77542+#include <linux/kernel.h>
77543+#include <linux/sched.h>
77544+#include <linux/file.h>
77545+#include <linux/tty.h>
77546+#include <linux/fs.h>
77547+#include <linux/mm.h>
77548+#include <linux/grinternal.h>
77549+
77550+#ifdef CONFIG_TREE_PREEMPT_RCU
77551+#define DISABLE_PREEMPT() preempt_disable()
77552+#define ENABLE_PREEMPT() preempt_enable()
77553+#else
77554+#define DISABLE_PREEMPT()
77555+#define ENABLE_PREEMPT()
77556+#endif
77557+
77558+#define BEGIN_LOCKS(x) \
77559+ DISABLE_PREEMPT(); \
77560+ rcu_read_lock(); \
77561+ read_lock(&tasklist_lock); \
77562+ read_lock(&grsec_exec_file_lock); \
77563+ if (x != GR_DO_AUDIT) \
77564+ spin_lock(&grsec_alert_lock); \
77565+ else \
77566+ spin_lock(&grsec_audit_lock)
77567+
77568+#define END_LOCKS(x) \
77569+ if (x != GR_DO_AUDIT) \
77570+ spin_unlock(&grsec_alert_lock); \
77571+ else \
77572+ spin_unlock(&grsec_audit_lock); \
77573+ read_unlock(&grsec_exec_file_lock); \
77574+ read_unlock(&tasklist_lock); \
77575+ rcu_read_unlock(); \
77576+ ENABLE_PREEMPT(); \
77577+ if (x == GR_DONT_AUDIT) \
77578+ gr_handle_alertkill(current)
77579+
77580+enum {
77581+ FLOODING,
77582+ NO_FLOODING
77583+};
77584+
77585+extern char *gr_alert_log_fmt;
77586+extern char *gr_audit_log_fmt;
77587+extern char *gr_alert_log_buf;
77588+extern char *gr_audit_log_buf;
77589+
77590+static int gr_log_start(int audit)
77591+{
77592+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
77593+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
77594+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77595+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
77596+ unsigned long curr_secs = get_seconds();
77597+
77598+ if (audit == GR_DO_AUDIT)
77599+ goto set_fmt;
77600+
77601+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
77602+ grsec_alert_wtime = curr_secs;
77603+ grsec_alert_fyet = 0;
77604+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
77605+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
77606+ grsec_alert_fyet++;
77607+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
77608+ grsec_alert_wtime = curr_secs;
77609+ grsec_alert_fyet++;
77610+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
77611+ return FLOODING;
77612+ }
77613+ else return FLOODING;
77614+
77615+set_fmt:
77616+#endif
77617+ memset(buf, 0, PAGE_SIZE);
77618+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
77619+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
77620+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
77621+ } else if (current->signal->curr_ip) {
77622+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
77623+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
77624+ } else if (gr_acl_is_enabled()) {
77625+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
77626+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
77627+ } else {
77628+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
77629+ strcpy(buf, fmt);
77630+ }
77631+
77632+ return NO_FLOODING;
77633+}
77634+
77635+static void gr_log_middle(int audit, const char *msg, va_list ap)
77636+ __attribute__ ((format (printf, 2, 0)));
77637+
77638+static void gr_log_middle(int audit, const char *msg, va_list ap)
77639+{
77640+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77641+ unsigned int len = strlen(buf);
77642+
77643+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
77644+
77645+ return;
77646+}
77647+
77648+static void gr_log_middle_varargs(int audit, const char *msg, ...)
77649+ __attribute__ ((format (printf, 2, 3)));
77650+
77651+static void gr_log_middle_varargs(int audit, const char *msg, ...)
77652+{
77653+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77654+ unsigned int len = strlen(buf);
77655+ va_list ap;
77656+
77657+ va_start(ap, msg);
77658+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
77659+ va_end(ap);
77660+
77661+ return;
77662+}
77663+
77664+static void gr_log_end(int audit, int append_default)
77665+{
77666+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77667+ if (append_default) {
77668+ struct task_struct *task = current;
77669+ struct task_struct *parent = task->real_parent;
77670+ const struct cred *cred = __task_cred(task);
77671+ const struct cred *pcred = __task_cred(parent);
77672+ unsigned int len = strlen(buf);
77673+
77674+ 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));
77675+ }
77676+
77677+ printk("%s\n", buf);
77678+
77679+ return;
77680+}
77681+
77682+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
77683+{
77684+ int logtype;
77685+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
77686+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
77687+ void *voidptr = NULL;
77688+ int num1 = 0, num2 = 0;
77689+ unsigned long ulong1 = 0, ulong2 = 0;
77690+ struct dentry *dentry = NULL;
77691+ struct vfsmount *mnt = NULL;
77692+ struct file *file = NULL;
77693+ struct task_struct *task = NULL;
77694+ struct vm_area_struct *vma = NULL;
77695+ const struct cred *cred, *pcred;
77696+ va_list ap;
77697+
77698+ BEGIN_LOCKS(audit);
77699+ logtype = gr_log_start(audit);
77700+ if (logtype == FLOODING) {
77701+ END_LOCKS(audit);
77702+ return;
77703+ }
77704+ va_start(ap, argtypes);
77705+ switch (argtypes) {
77706+ case GR_TTYSNIFF:
77707+ task = va_arg(ap, struct task_struct *);
77708+ 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));
77709+ break;
77710+ case GR_SYSCTL_HIDDEN:
77711+ str1 = va_arg(ap, char *);
77712+ gr_log_middle_varargs(audit, msg, result, str1);
77713+ break;
77714+ case GR_RBAC:
77715+ dentry = va_arg(ap, struct dentry *);
77716+ mnt = va_arg(ap, struct vfsmount *);
77717+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
77718+ break;
77719+ case GR_RBAC_STR:
77720+ dentry = va_arg(ap, struct dentry *);
77721+ mnt = va_arg(ap, struct vfsmount *);
77722+ str1 = va_arg(ap, char *);
77723+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
77724+ break;
77725+ case GR_STR_RBAC:
77726+ str1 = va_arg(ap, char *);
77727+ dentry = va_arg(ap, struct dentry *);
77728+ mnt = va_arg(ap, struct vfsmount *);
77729+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
77730+ break;
77731+ case GR_RBAC_MODE2:
77732+ dentry = va_arg(ap, struct dentry *);
77733+ mnt = va_arg(ap, struct vfsmount *);
77734+ str1 = va_arg(ap, char *);
77735+ str2 = va_arg(ap, char *);
77736+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
77737+ break;
77738+ case GR_RBAC_MODE3:
77739+ dentry = va_arg(ap, struct dentry *);
77740+ mnt = va_arg(ap, struct vfsmount *);
77741+ str1 = va_arg(ap, char *);
77742+ str2 = va_arg(ap, char *);
77743+ str3 = va_arg(ap, char *);
77744+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
77745+ break;
77746+ case GR_FILENAME:
77747+ dentry = va_arg(ap, struct dentry *);
77748+ mnt = va_arg(ap, struct vfsmount *);
77749+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
77750+ break;
77751+ case GR_STR_FILENAME:
77752+ str1 = va_arg(ap, char *);
77753+ dentry = va_arg(ap, struct dentry *);
77754+ mnt = va_arg(ap, struct vfsmount *);
77755+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
77756+ break;
77757+ case GR_FILENAME_STR:
77758+ dentry = va_arg(ap, struct dentry *);
77759+ mnt = va_arg(ap, struct vfsmount *);
77760+ str1 = va_arg(ap, char *);
77761+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
77762+ break;
77763+ case GR_FILENAME_TWO_INT:
77764+ dentry = va_arg(ap, struct dentry *);
77765+ mnt = va_arg(ap, struct vfsmount *);
77766+ num1 = va_arg(ap, int);
77767+ num2 = va_arg(ap, int);
77768+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
77769+ break;
77770+ case GR_FILENAME_TWO_INT_STR:
77771+ dentry = va_arg(ap, struct dentry *);
77772+ mnt = va_arg(ap, struct vfsmount *);
77773+ num1 = va_arg(ap, int);
77774+ num2 = va_arg(ap, int);
77775+ str1 = va_arg(ap, char *);
77776+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
77777+ break;
77778+ case GR_TEXTREL:
77779+ file = va_arg(ap, struct file *);
77780+ ulong1 = va_arg(ap, unsigned long);
77781+ ulong2 = va_arg(ap, unsigned long);
77782+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
77783+ break;
77784+ case GR_PTRACE:
77785+ task = va_arg(ap, struct task_struct *);
77786+ 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));
77787+ break;
77788+ case GR_RESOURCE:
77789+ task = va_arg(ap, struct task_struct *);
77790+ cred = __task_cred(task);
77791+ pcred = __task_cred(task->real_parent);
77792+ ulong1 = va_arg(ap, unsigned long);
77793+ str1 = va_arg(ap, char *);
77794+ ulong2 = va_arg(ap, unsigned long);
77795+ 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));
77796+ break;
77797+ case GR_CAP:
77798+ task = va_arg(ap, struct task_struct *);
77799+ cred = __task_cred(task);
77800+ pcred = __task_cred(task->real_parent);
77801+ str1 = va_arg(ap, char *);
77802+ 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));
77803+ break;
77804+ case GR_SIG:
77805+ str1 = va_arg(ap, char *);
77806+ voidptr = va_arg(ap, void *);
77807+ gr_log_middle_varargs(audit, msg, str1, voidptr);
77808+ break;
77809+ case GR_SIG2:
77810+ task = va_arg(ap, struct task_struct *);
77811+ cred = __task_cred(task);
77812+ pcred = __task_cred(task->real_parent);
77813+ num1 = va_arg(ap, int);
77814+ 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));
77815+ break;
77816+ case GR_CRASH1:
77817+ task = va_arg(ap, struct task_struct *);
77818+ cred = __task_cred(task);
77819+ pcred = __task_cred(task->real_parent);
77820+ ulong1 = va_arg(ap, unsigned long);
77821+ 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);
77822+ break;
77823+ case GR_CRASH2:
77824+ task = va_arg(ap, struct task_struct *);
77825+ cred = __task_cred(task);
77826+ pcred = __task_cred(task->real_parent);
77827+ ulong1 = va_arg(ap, unsigned long);
77828+ 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);
77829+ break;
77830+ case GR_RWXMAP:
77831+ file = va_arg(ap, struct file *);
77832+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
77833+ break;
77834+ case GR_RWXMAPVMA:
77835+ vma = va_arg(ap, struct vm_area_struct *);
77836+ if (vma->vm_file)
77837+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
77838+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
77839+ str1 = "<stack>";
77840+ else if (vma->vm_start <= current->mm->brk &&
77841+ vma->vm_end >= current->mm->start_brk)
77842+ str1 = "<heap>";
77843+ else
77844+ str1 = "<anonymous mapping>";
77845+ gr_log_middle_varargs(audit, msg, str1);
77846+ break;
77847+ case GR_PSACCT:
77848+ {
77849+ unsigned int wday, cday;
77850+ __u8 whr, chr;
77851+ __u8 wmin, cmin;
77852+ __u8 wsec, csec;
77853+ char cur_tty[64] = { 0 };
77854+ char parent_tty[64] = { 0 };
77855+
77856+ task = va_arg(ap, struct task_struct *);
77857+ wday = va_arg(ap, unsigned int);
77858+ cday = va_arg(ap, unsigned int);
77859+ whr = va_arg(ap, int);
77860+ chr = va_arg(ap, int);
77861+ wmin = va_arg(ap, int);
77862+ cmin = va_arg(ap, int);
77863+ wsec = va_arg(ap, int);
77864+ csec = va_arg(ap, int);
77865+ ulong1 = va_arg(ap, unsigned long);
77866+ cred = __task_cred(task);
77867+ pcred = __task_cred(task->real_parent);
77868+
77869+ 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));
77870+ }
77871+ break;
77872+ default:
77873+ gr_log_middle(audit, msg, ap);
77874+ }
77875+ va_end(ap);
77876+ // these don't need DEFAULTSECARGS printed on the end
77877+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
77878+ gr_log_end(audit, 0);
77879+ else
77880+ gr_log_end(audit, 1);
77881+ END_LOCKS(audit);
77882+}
77883diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
77884new file mode 100644
77885index 0000000..0e39d8c
77886--- /dev/null
77887+++ b/grsecurity/grsec_mem.c
77888@@ -0,0 +1,48 @@
77889+#include <linux/kernel.h>
77890+#include <linux/sched.h>
77891+#include <linux/mm.h>
77892+#include <linux/mman.h>
77893+#include <linux/module.h>
77894+#include <linux/grinternal.h>
77895+
77896+void gr_handle_msr_write(void)
77897+{
77898+ gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
77899+ return;
77900+}
77901+EXPORT_SYMBOL_GPL(gr_handle_msr_write);
77902+
77903+void
77904+gr_handle_ioperm(void)
77905+{
77906+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
77907+ return;
77908+}
77909+
77910+void
77911+gr_handle_iopl(void)
77912+{
77913+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
77914+ return;
77915+}
77916+
77917+void
77918+gr_handle_mem_readwrite(u64 from, u64 to)
77919+{
77920+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
77921+ return;
77922+}
77923+
77924+void
77925+gr_handle_vm86(void)
77926+{
77927+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
77928+ return;
77929+}
77930+
77931+void
77932+gr_log_badprocpid(const char *entry)
77933+{
77934+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
77935+ return;
77936+}
77937diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
77938new file mode 100644
77939index 0000000..6f9eb73
77940--- /dev/null
77941+++ b/grsecurity/grsec_mount.c
77942@@ -0,0 +1,65 @@
77943+#include <linux/kernel.h>
77944+#include <linux/sched.h>
77945+#include <linux/mount.h>
77946+#include <linux/major.h>
77947+#include <linux/grsecurity.h>
77948+#include <linux/grinternal.h>
77949+
77950+void
77951+gr_log_remount(const char *devname, const int retval)
77952+{
77953+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77954+ if (grsec_enable_mount && (retval >= 0))
77955+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
77956+#endif
77957+ return;
77958+}
77959+
77960+void
77961+gr_log_unmount(const char *devname, const int retval)
77962+{
77963+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77964+ if (grsec_enable_mount && (retval >= 0))
77965+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
77966+#endif
77967+ return;
77968+}
77969+
77970+void
77971+gr_log_mount(const char *from, struct path *to, const int retval)
77972+{
77973+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77974+ if (grsec_enable_mount && (retval >= 0))
77975+ gr_log_str_fs(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to->dentry, to->mnt);
77976+#endif
77977+ return;
77978+}
77979+
77980+int
77981+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
77982+{
77983+#ifdef CONFIG_GRKERNSEC_ROFS
77984+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
77985+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
77986+ return -EPERM;
77987+ } else
77988+ return 0;
77989+#endif
77990+ return 0;
77991+}
77992+
77993+int
77994+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
77995+{
77996+#ifdef CONFIG_GRKERNSEC_ROFS
77997+ struct inode *inode = dentry->d_inode;
77998+
77999+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
78000+ inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
78001+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
78002+ return -EPERM;
78003+ } else
78004+ return 0;
78005+#endif
78006+ return 0;
78007+}
78008diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
78009new file mode 100644
78010index 0000000..6ee9d50
78011--- /dev/null
78012+++ b/grsecurity/grsec_pax.c
78013@@ -0,0 +1,45 @@
78014+#include <linux/kernel.h>
78015+#include <linux/sched.h>
78016+#include <linux/mm.h>
78017+#include <linux/file.h>
78018+#include <linux/grinternal.h>
78019+#include <linux/grsecurity.h>
78020+
78021+void
78022+gr_log_textrel(struct vm_area_struct * vma)
78023+{
78024+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78025+ if (grsec_enable_log_rwxmaps)
78026+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
78027+#endif
78028+ return;
78029+}
78030+
78031+void gr_log_ptgnustack(struct file *file)
78032+{
78033+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78034+ if (grsec_enable_log_rwxmaps)
78035+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
78036+#endif
78037+ return;
78038+}
78039+
78040+void
78041+gr_log_rwxmmap(struct file *file)
78042+{
78043+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78044+ if (grsec_enable_log_rwxmaps)
78045+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
78046+#endif
78047+ return;
78048+}
78049+
78050+void
78051+gr_log_rwxmprotect(struct vm_area_struct *vma)
78052+{
78053+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78054+ if (grsec_enable_log_rwxmaps)
78055+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
78056+#endif
78057+ return;
78058+}
78059diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
78060new file mode 100644
78061index 0000000..2005a3a
78062--- /dev/null
78063+++ b/grsecurity/grsec_proc.c
78064@@ -0,0 +1,20 @@
78065+#include <linux/kernel.h>
78066+#include <linux/sched.h>
78067+#include <linux/grsecurity.h>
78068+#include <linux/grinternal.h>
78069+
78070+int gr_proc_is_restricted(void)
78071+{
78072+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78073+ const struct cred *cred = current_cred();
78074+#endif
78075+
78076+#ifdef CONFIG_GRKERNSEC_PROC_USER
78077+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
78078+ return -EACCES;
78079+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78080+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
78081+ return -EACCES;
78082+#endif
78083+ return 0;
78084+}
78085diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
78086new file mode 100644
78087index 0000000..f7f29aa
78088--- /dev/null
78089+++ b/grsecurity/grsec_ptrace.c
78090@@ -0,0 +1,30 @@
78091+#include <linux/kernel.h>
78092+#include <linux/sched.h>
78093+#include <linux/grinternal.h>
78094+#include <linux/security.h>
78095+
78096+void
78097+gr_audit_ptrace(struct task_struct *task)
78098+{
78099+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
78100+ if (grsec_enable_audit_ptrace)
78101+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
78102+#endif
78103+ return;
78104+}
78105+
78106+int
78107+gr_ptrace_readexec(struct file *file, int unsafe_flags)
78108+{
78109+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78110+ const struct dentry *dentry = file->f_path.dentry;
78111+ const struct vfsmount *mnt = file->f_path.mnt;
78112+
78113+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
78114+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
78115+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
78116+ return -EACCES;
78117+ }
78118+#endif
78119+ return 0;
78120+}
78121diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
78122new file mode 100644
78123index 0000000..3860c7e
78124--- /dev/null
78125+++ b/grsecurity/grsec_sig.c
78126@@ -0,0 +1,236 @@
78127+#include <linux/kernel.h>
78128+#include <linux/sched.h>
78129+#include <linux/fs.h>
78130+#include <linux/delay.h>
78131+#include <linux/grsecurity.h>
78132+#include <linux/grinternal.h>
78133+#include <linux/hardirq.h>
78134+
78135+char *signames[] = {
78136+ [SIGSEGV] = "Segmentation fault",
78137+ [SIGILL] = "Illegal instruction",
78138+ [SIGABRT] = "Abort",
78139+ [SIGBUS] = "Invalid alignment/Bus error"
78140+};
78141+
78142+void
78143+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
78144+{
78145+#ifdef CONFIG_GRKERNSEC_SIGNAL
78146+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
78147+ (sig == SIGABRT) || (sig == SIGBUS))) {
78148+ if (task_pid_nr(t) == task_pid_nr(current)) {
78149+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
78150+ } else {
78151+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
78152+ }
78153+ }
78154+#endif
78155+ return;
78156+}
78157+
78158+int
78159+gr_handle_signal(const struct task_struct *p, const int sig)
78160+{
78161+#ifdef CONFIG_GRKERNSEC
78162+ /* ignore the 0 signal for protected task checks */
78163+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
78164+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
78165+ return -EPERM;
78166+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
78167+ return -EPERM;
78168+ }
78169+#endif
78170+ return 0;
78171+}
78172+
78173+#ifdef CONFIG_GRKERNSEC
78174+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
78175+
78176+int gr_fake_force_sig(int sig, struct task_struct *t)
78177+{
78178+ unsigned long int flags;
78179+ int ret, blocked, ignored;
78180+ struct k_sigaction *action;
78181+
78182+ spin_lock_irqsave(&t->sighand->siglock, flags);
78183+ action = &t->sighand->action[sig-1];
78184+ ignored = action->sa.sa_handler == SIG_IGN;
78185+ blocked = sigismember(&t->blocked, sig);
78186+ if (blocked || ignored) {
78187+ action->sa.sa_handler = SIG_DFL;
78188+ if (blocked) {
78189+ sigdelset(&t->blocked, sig);
78190+ recalc_sigpending_and_wake(t);
78191+ }
78192+ }
78193+ if (action->sa.sa_handler == SIG_DFL)
78194+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
78195+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
78196+
78197+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
78198+
78199+ return ret;
78200+}
78201+#endif
78202+
78203+#define GR_USER_BAN_TIME (15 * 60)
78204+#define GR_DAEMON_BRUTE_TIME (30 * 60)
78205+
78206+void gr_handle_brute_attach(int dumpable)
78207+{
78208+#ifdef CONFIG_GRKERNSEC_BRUTE
78209+ struct task_struct *p = current;
78210+ kuid_t uid = GLOBAL_ROOT_UID;
78211+ int daemon = 0;
78212+
78213+ if (!grsec_enable_brute)
78214+ return;
78215+
78216+ rcu_read_lock();
78217+ read_lock(&tasklist_lock);
78218+ read_lock(&grsec_exec_file_lock);
78219+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
78220+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
78221+ p->real_parent->brute = 1;
78222+ daemon = 1;
78223+ } else {
78224+ const struct cred *cred = __task_cred(p), *cred2;
78225+ struct task_struct *tsk, *tsk2;
78226+
78227+ if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
78228+ struct user_struct *user;
78229+
78230+ uid = cred->uid;
78231+
78232+ /* this is put upon execution past expiration */
78233+ user = find_user(uid);
78234+ if (user == NULL)
78235+ goto unlock;
78236+ user->suid_banned = 1;
78237+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
78238+ if (user->suid_ban_expires == ~0UL)
78239+ user->suid_ban_expires--;
78240+
78241+ /* only kill other threads of the same binary, from the same user */
78242+ do_each_thread(tsk2, tsk) {
78243+ cred2 = __task_cred(tsk);
78244+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
78245+ gr_fake_force_sig(SIGKILL, tsk);
78246+ } while_each_thread(tsk2, tsk);
78247+ }
78248+ }
78249+unlock:
78250+ read_unlock(&grsec_exec_file_lock);
78251+ read_unlock(&tasklist_lock);
78252+ rcu_read_unlock();
78253+
78254+ if (gr_is_global_nonroot(uid))
78255+ 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);
78256+ else if (daemon)
78257+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
78258+
78259+#endif
78260+ return;
78261+}
78262+
78263+void gr_handle_brute_check(void)
78264+{
78265+#ifdef CONFIG_GRKERNSEC_BRUTE
78266+ struct task_struct *p = current;
78267+
78268+ if (unlikely(p->brute)) {
78269+ if (!grsec_enable_brute)
78270+ p->brute = 0;
78271+ else if (time_before(get_seconds(), p->brute_expires))
78272+ msleep(30 * 1000);
78273+ }
78274+#endif
78275+ return;
78276+}
78277+
78278+void gr_handle_kernel_exploit(void)
78279+{
78280+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78281+ const struct cred *cred;
78282+ struct task_struct *tsk, *tsk2;
78283+ struct user_struct *user;
78284+ kuid_t uid;
78285+
78286+ if (in_irq() || in_serving_softirq() || in_nmi())
78287+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
78288+
78289+ uid = current_uid();
78290+
78291+ if (gr_is_global_root(uid))
78292+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
78293+ else {
78294+ /* kill all the processes of this user, hold a reference
78295+ to their creds struct, and prevent them from creating
78296+ another process until system reset
78297+ */
78298+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
78299+ GR_GLOBAL_UID(uid));
78300+ /* we intentionally leak this ref */
78301+ user = get_uid(current->cred->user);
78302+ if (user)
78303+ user->kernel_banned = 1;
78304+
78305+ /* kill all processes of this user */
78306+ read_lock(&tasklist_lock);
78307+ do_each_thread(tsk2, tsk) {
78308+ cred = __task_cred(tsk);
78309+ if (uid_eq(cred->uid, uid))
78310+ gr_fake_force_sig(SIGKILL, tsk);
78311+ } while_each_thread(tsk2, tsk);
78312+ read_unlock(&tasklist_lock);
78313+ }
78314+#endif
78315+}
78316+
78317+#ifdef CONFIG_GRKERNSEC_BRUTE
78318+static bool suid_ban_expired(struct user_struct *user)
78319+{
78320+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
78321+ user->suid_banned = 0;
78322+ user->suid_ban_expires = 0;
78323+ free_uid(user);
78324+ return true;
78325+ }
78326+
78327+ return false;
78328+}
78329+#endif
78330+
78331+int gr_process_kernel_exec_ban(void)
78332+{
78333+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78334+ if (unlikely(current->cred->user->kernel_banned))
78335+ return -EPERM;
78336+#endif
78337+ return 0;
78338+}
78339+
78340+int gr_process_kernel_setuid_ban(struct user_struct *user)
78341+{
78342+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78343+ if (unlikely(user->kernel_banned))
78344+ gr_fake_force_sig(SIGKILL, current);
78345+#endif
78346+ return 0;
78347+}
78348+
78349+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
78350+{
78351+#ifdef CONFIG_GRKERNSEC_BRUTE
78352+ struct user_struct *user = current->cred->user;
78353+ if (unlikely(user->suid_banned)) {
78354+ if (suid_ban_expired(user))
78355+ return 0;
78356+ /* disallow execution of suid binaries only */
78357+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
78358+ return -EPERM;
78359+ }
78360+#endif
78361+ return 0;
78362+}
78363diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
78364new file mode 100644
78365index 0000000..e3650b6
78366--- /dev/null
78367+++ b/grsecurity/grsec_sock.c
78368@@ -0,0 +1,244 @@
78369+#include <linux/kernel.h>
78370+#include <linux/module.h>
78371+#include <linux/sched.h>
78372+#include <linux/file.h>
78373+#include <linux/net.h>
78374+#include <linux/in.h>
78375+#include <linux/ip.h>
78376+#include <net/sock.h>
78377+#include <net/inet_sock.h>
78378+#include <linux/grsecurity.h>
78379+#include <linux/grinternal.h>
78380+#include <linux/gracl.h>
78381+
78382+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
78383+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
78384+
78385+EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
78386+EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
78387+
78388+#ifdef CONFIG_UNIX_MODULE
78389+EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
78390+EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
78391+EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
78392+EXPORT_SYMBOL_GPL(gr_handle_create);
78393+#endif
78394+
78395+#ifdef CONFIG_GRKERNSEC
78396+#define gr_conn_table_size 32749
78397+struct conn_table_entry {
78398+ struct conn_table_entry *next;
78399+ struct signal_struct *sig;
78400+};
78401+
78402+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
78403+DEFINE_SPINLOCK(gr_conn_table_lock);
78404+
78405+extern const char * gr_socktype_to_name(unsigned char type);
78406+extern const char * gr_proto_to_name(unsigned char proto);
78407+extern const char * gr_sockfamily_to_name(unsigned char family);
78408+
78409+static __inline__ int
78410+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
78411+{
78412+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
78413+}
78414+
78415+static __inline__ int
78416+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
78417+ __u16 sport, __u16 dport)
78418+{
78419+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
78420+ sig->gr_sport == sport && sig->gr_dport == dport))
78421+ return 1;
78422+ else
78423+ return 0;
78424+}
78425+
78426+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
78427+{
78428+ struct conn_table_entry **match;
78429+ unsigned int index;
78430+
78431+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
78432+ sig->gr_sport, sig->gr_dport,
78433+ gr_conn_table_size);
78434+
78435+ newent->sig = sig;
78436+
78437+ match = &gr_conn_table[index];
78438+ newent->next = *match;
78439+ *match = newent;
78440+
78441+ return;
78442+}
78443+
78444+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
78445+{
78446+ struct conn_table_entry *match, *last = NULL;
78447+ unsigned int index;
78448+
78449+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
78450+ sig->gr_sport, sig->gr_dport,
78451+ gr_conn_table_size);
78452+
78453+ match = gr_conn_table[index];
78454+ while (match && !conn_match(match->sig,
78455+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
78456+ sig->gr_dport)) {
78457+ last = match;
78458+ match = match->next;
78459+ }
78460+
78461+ if (match) {
78462+ if (last)
78463+ last->next = match->next;
78464+ else
78465+ gr_conn_table[index] = NULL;
78466+ kfree(match);
78467+ }
78468+
78469+ return;
78470+}
78471+
78472+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
78473+ __u16 sport, __u16 dport)
78474+{
78475+ struct conn_table_entry *match;
78476+ unsigned int index;
78477+
78478+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
78479+
78480+ match = gr_conn_table[index];
78481+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
78482+ match = match->next;
78483+
78484+ if (match)
78485+ return match->sig;
78486+ else
78487+ return NULL;
78488+}
78489+
78490+#endif
78491+
78492+void gr_update_task_in_ip_table(const struct inet_sock *inet)
78493+{
78494+#ifdef CONFIG_GRKERNSEC
78495+ struct signal_struct *sig = current->signal;
78496+ struct conn_table_entry *newent;
78497+
78498+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
78499+ if (newent == NULL)
78500+ return;
78501+ /* no bh lock needed since we are called with bh disabled */
78502+ spin_lock(&gr_conn_table_lock);
78503+ gr_del_task_from_ip_table_nolock(sig);
78504+ sig->gr_saddr = inet->inet_rcv_saddr;
78505+ sig->gr_daddr = inet->inet_daddr;
78506+ sig->gr_sport = inet->inet_sport;
78507+ sig->gr_dport = inet->inet_dport;
78508+ gr_add_to_task_ip_table_nolock(sig, newent);
78509+ spin_unlock(&gr_conn_table_lock);
78510+#endif
78511+ return;
78512+}
78513+
78514+void gr_del_task_from_ip_table(struct task_struct *task)
78515+{
78516+#ifdef CONFIG_GRKERNSEC
78517+ spin_lock_bh(&gr_conn_table_lock);
78518+ gr_del_task_from_ip_table_nolock(task->signal);
78519+ spin_unlock_bh(&gr_conn_table_lock);
78520+#endif
78521+ return;
78522+}
78523+
78524+void
78525+gr_attach_curr_ip(const struct sock *sk)
78526+{
78527+#ifdef CONFIG_GRKERNSEC
78528+ struct signal_struct *p, *set;
78529+ const struct inet_sock *inet = inet_sk(sk);
78530+
78531+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
78532+ return;
78533+
78534+ set = current->signal;
78535+
78536+ spin_lock_bh(&gr_conn_table_lock);
78537+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
78538+ inet->inet_dport, inet->inet_sport);
78539+ if (unlikely(p != NULL)) {
78540+ set->curr_ip = p->curr_ip;
78541+ set->used_accept = 1;
78542+ gr_del_task_from_ip_table_nolock(p);
78543+ spin_unlock_bh(&gr_conn_table_lock);
78544+ return;
78545+ }
78546+ spin_unlock_bh(&gr_conn_table_lock);
78547+
78548+ set->curr_ip = inet->inet_daddr;
78549+ set->used_accept = 1;
78550+#endif
78551+ return;
78552+}
78553+
78554+int
78555+gr_handle_sock_all(const int family, const int type, const int protocol)
78556+{
78557+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
78558+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
78559+ (family != AF_UNIX)) {
78560+ if (family == AF_INET)
78561+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
78562+ else
78563+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
78564+ return -EACCES;
78565+ }
78566+#endif
78567+ return 0;
78568+}
78569+
78570+int
78571+gr_handle_sock_server(const struct sockaddr *sck)
78572+{
78573+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78574+ if (grsec_enable_socket_server &&
78575+ in_group_p(grsec_socket_server_gid) &&
78576+ sck && (sck->sa_family != AF_UNIX) &&
78577+ (sck->sa_family != AF_LOCAL)) {
78578+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
78579+ return -EACCES;
78580+ }
78581+#endif
78582+ return 0;
78583+}
78584+
78585+int
78586+gr_handle_sock_server_other(const struct sock *sck)
78587+{
78588+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78589+ if (grsec_enable_socket_server &&
78590+ in_group_p(grsec_socket_server_gid) &&
78591+ sck && (sck->sk_family != AF_UNIX) &&
78592+ (sck->sk_family != AF_LOCAL)) {
78593+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
78594+ return -EACCES;
78595+ }
78596+#endif
78597+ return 0;
78598+}
78599+
78600+int
78601+gr_handle_sock_client(const struct sockaddr *sck)
78602+{
78603+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
78604+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
78605+ sck && (sck->sa_family != AF_UNIX) &&
78606+ (sck->sa_family != AF_LOCAL)) {
78607+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
78608+ return -EACCES;
78609+ }
78610+#endif
78611+ return 0;
78612+}
78613diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
78614new file mode 100644
78615index 0000000..8159888
78616--- /dev/null
78617+++ b/grsecurity/grsec_sysctl.c
78618@@ -0,0 +1,479 @@
78619+#include <linux/kernel.h>
78620+#include <linux/sched.h>
78621+#include <linux/sysctl.h>
78622+#include <linux/grsecurity.h>
78623+#include <linux/grinternal.h>
78624+
78625+int
78626+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
78627+{
78628+#ifdef CONFIG_GRKERNSEC_SYSCTL
78629+ if (dirname == NULL || name == NULL)
78630+ return 0;
78631+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
78632+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
78633+ return -EACCES;
78634+ }
78635+#endif
78636+ return 0;
78637+}
78638+
78639+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
78640+static int __maybe_unused __read_only one = 1;
78641+#endif
78642+
78643+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
78644+ defined(CONFIG_GRKERNSEC_DENYUSB)
78645+struct ctl_table grsecurity_table[] = {
78646+#ifdef CONFIG_GRKERNSEC_SYSCTL
78647+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
78648+#ifdef CONFIG_GRKERNSEC_IO
78649+ {
78650+ .procname = "disable_priv_io",
78651+ .data = &grsec_disable_privio,
78652+ .maxlen = sizeof(int),
78653+ .mode = 0600,
78654+ .proc_handler = &proc_dointvec,
78655+ },
78656+#endif
78657+#endif
78658+#ifdef CONFIG_GRKERNSEC_LINK
78659+ {
78660+ .procname = "linking_restrictions",
78661+ .data = &grsec_enable_link,
78662+ .maxlen = sizeof(int),
78663+ .mode = 0600,
78664+ .proc_handler = &proc_dointvec,
78665+ },
78666+#endif
78667+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
78668+ {
78669+ .procname = "enforce_symlinksifowner",
78670+ .data = &grsec_enable_symlinkown,
78671+ .maxlen = sizeof(int),
78672+ .mode = 0600,
78673+ .proc_handler = &proc_dointvec,
78674+ },
78675+ {
78676+ .procname = "symlinkown_gid",
78677+ .data = &grsec_symlinkown_gid,
78678+ .maxlen = sizeof(int),
78679+ .mode = 0600,
78680+ .proc_handler = &proc_dointvec,
78681+ },
78682+#endif
78683+#ifdef CONFIG_GRKERNSEC_BRUTE
78684+ {
78685+ .procname = "deter_bruteforce",
78686+ .data = &grsec_enable_brute,
78687+ .maxlen = sizeof(int),
78688+ .mode = 0600,
78689+ .proc_handler = &proc_dointvec,
78690+ },
78691+#endif
78692+#ifdef CONFIG_GRKERNSEC_FIFO
78693+ {
78694+ .procname = "fifo_restrictions",
78695+ .data = &grsec_enable_fifo,
78696+ .maxlen = sizeof(int),
78697+ .mode = 0600,
78698+ .proc_handler = &proc_dointvec,
78699+ },
78700+#endif
78701+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78702+ {
78703+ .procname = "ptrace_readexec",
78704+ .data = &grsec_enable_ptrace_readexec,
78705+ .maxlen = sizeof(int),
78706+ .mode = 0600,
78707+ .proc_handler = &proc_dointvec,
78708+ },
78709+#endif
78710+#ifdef CONFIG_GRKERNSEC_SETXID
78711+ {
78712+ .procname = "consistent_setxid",
78713+ .data = &grsec_enable_setxid,
78714+ .maxlen = sizeof(int),
78715+ .mode = 0600,
78716+ .proc_handler = &proc_dointvec,
78717+ },
78718+#endif
78719+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78720+ {
78721+ .procname = "ip_blackhole",
78722+ .data = &grsec_enable_blackhole,
78723+ .maxlen = sizeof(int),
78724+ .mode = 0600,
78725+ .proc_handler = &proc_dointvec,
78726+ },
78727+ {
78728+ .procname = "lastack_retries",
78729+ .data = &grsec_lastack_retries,
78730+ .maxlen = sizeof(int),
78731+ .mode = 0600,
78732+ .proc_handler = &proc_dointvec,
78733+ },
78734+#endif
78735+#ifdef CONFIG_GRKERNSEC_EXECLOG
78736+ {
78737+ .procname = "exec_logging",
78738+ .data = &grsec_enable_execlog,
78739+ .maxlen = sizeof(int),
78740+ .mode = 0600,
78741+ .proc_handler = &proc_dointvec,
78742+ },
78743+#endif
78744+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78745+ {
78746+ .procname = "rwxmap_logging",
78747+ .data = &grsec_enable_log_rwxmaps,
78748+ .maxlen = sizeof(int),
78749+ .mode = 0600,
78750+ .proc_handler = &proc_dointvec,
78751+ },
78752+#endif
78753+#ifdef CONFIG_GRKERNSEC_SIGNAL
78754+ {
78755+ .procname = "signal_logging",
78756+ .data = &grsec_enable_signal,
78757+ .maxlen = sizeof(int),
78758+ .mode = 0600,
78759+ .proc_handler = &proc_dointvec,
78760+ },
78761+#endif
78762+#ifdef CONFIG_GRKERNSEC_FORKFAIL
78763+ {
78764+ .procname = "forkfail_logging",
78765+ .data = &grsec_enable_forkfail,
78766+ .maxlen = sizeof(int),
78767+ .mode = 0600,
78768+ .proc_handler = &proc_dointvec,
78769+ },
78770+#endif
78771+#ifdef CONFIG_GRKERNSEC_TIME
78772+ {
78773+ .procname = "timechange_logging",
78774+ .data = &grsec_enable_time,
78775+ .maxlen = sizeof(int),
78776+ .mode = 0600,
78777+ .proc_handler = &proc_dointvec,
78778+ },
78779+#endif
78780+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
78781+ {
78782+ .procname = "chroot_deny_shmat",
78783+ .data = &grsec_enable_chroot_shmat,
78784+ .maxlen = sizeof(int),
78785+ .mode = 0600,
78786+ .proc_handler = &proc_dointvec,
78787+ },
78788+#endif
78789+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
78790+ {
78791+ .procname = "chroot_deny_unix",
78792+ .data = &grsec_enable_chroot_unix,
78793+ .maxlen = sizeof(int),
78794+ .mode = 0600,
78795+ .proc_handler = &proc_dointvec,
78796+ },
78797+#endif
78798+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
78799+ {
78800+ .procname = "chroot_deny_mount",
78801+ .data = &grsec_enable_chroot_mount,
78802+ .maxlen = sizeof(int),
78803+ .mode = 0600,
78804+ .proc_handler = &proc_dointvec,
78805+ },
78806+#endif
78807+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
78808+ {
78809+ .procname = "chroot_deny_fchdir",
78810+ .data = &grsec_enable_chroot_fchdir,
78811+ .maxlen = sizeof(int),
78812+ .mode = 0600,
78813+ .proc_handler = &proc_dointvec,
78814+ },
78815+#endif
78816+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
78817+ {
78818+ .procname = "chroot_deny_chroot",
78819+ .data = &grsec_enable_chroot_double,
78820+ .maxlen = sizeof(int),
78821+ .mode = 0600,
78822+ .proc_handler = &proc_dointvec,
78823+ },
78824+#endif
78825+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
78826+ {
78827+ .procname = "chroot_deny_pivot",
78828+ .data = &grsec_enable_chroot_pivot,
78829+ .maxlen = sizeof(int),
78830+ .mode = 0600,
78831+ .proc_handler = &proc_dointvec,
78832+ },
78833+#endif
78834+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
78835+ {
78836+ .procname = "chroot_enforce_chdir",
78837+ .data = &grsec_enable_chroot_chdir,
78838+ .maxlen = sizeof(int),
78839+ .mode = 0600,
78840+ .proc_handler = &proc_dointvec,
78841+ },
78842+#endif
78843+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
78844+ {
78845+ .procname = "chroot_deny_chmod",
78846+ .data = &grsec_enable_chroot_chmod,
78847+ .maxlen = sizeof(int),
78848+ .mode = 0600,
78849+ .proc_handler = &proc_dointvec,
78850+ },
78851+#endif
78852+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
78853+ {
78854+ .procname = "chroot_deny_mknod",
78855+ .data = &grsec_enable_chroot_mknod,
78856+ .maxlen = sizeof(int),
78857+ .mode = 0600,
78858+ .proc_handler = &proc_dointvec,
78859+ },
78860+#endif
78861+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
78862+ {
78863+ .procname = "chroot_restrict_nice",
78864+ .data = &grsec_enable_chroot_nice,
78865+ .maxlen = sizeof(int),
78866+ .mode = 0600,
78867+ .proc_handler = &proc_dointvec,
78868+ },
78869+#endif
78870+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
78871+ {
78872+ .procname = "chroot_execlog",
78873+ .data = &grsec_enable_chroot_execlog,
78874+ .maxlen = sizeof(int),
78875+ .mode = 0600,
78876+ .proc_handler = &proc_dointvec,
78877+ },
78878+#endif
78879+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
78880+ {
78881+ .procname = "chroot_caps",
78882+ .data = &grsec_enable_chroot_caps,
78883+ .maxlen = sizeof(int),
78884+ .mode = 0600,
78885+ .proc_handler = &proc_dointvec,
78886+ },
78887+#endif
78888+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
78889+ {
78890+ .procname = "chroot_deny_sysctl",
78891+ .data = &grsec_enable_chroot_sysctl,
78892+ .maxlen = sizeof(int),
78893+ .mode = 0600,
78894+ .proc_handler = &proc_dointvec,
78895+ },
78896+#endif
78897+#ifdef CONFIG_GRKERNSEC_TPE
78898+ {
78899+ .procname = "tpe",
78900+ .data = &grsec_enable_tpe,
78901+ .maxlen = sizeof(int),
78902+ .mode = 0600,
78903+ .proc_handler = &proc_dointvec,
78904+ },
78905+ {
78906+ .procname = "tpe_gid",
78907+ .data = &grsec_tpe_gid,
78908+ .maxlen = sizeof(int),
78909+ .mode = 0600,
78910+ .proc_handler = &proc_dointvec,
78911+ },
78912+#endif
78913+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
78914+ {
78915+ .procname = "tpe_invert",
78916+ .data = &grsec_enable_tpe_invert,
78917+ .maxlen = sizeof(int),
78918+ .mode = 0600,
78919+ .proc_handler = &proc_dointvec,
78920+ },
78921+#endif
78922+#ifdef CONFIG_GRKERNSEC_TPE_ALL
78923+ {
78924+ .procname = "tpe_restrict_all",
78925+ .data = &grsec_enable_tpe_all,
78926+ .maxlen = sizeof(int),
78927+ .mode = 0600,
78928+ .proc_handler = &proc_dointvec,
78929+ },
78930+#endif
78931+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
78932+ {
78933+ .procname = "socket_all",
78934+ .data = &grsec_enable_socket_all,
78935+ .maxlen = sizeof(int),
78936+ .mode = 0600,
78937+ .proc_handler = &proc_dointvec,
78938+ },
78939+ {
78940+ .procname = "socket_all_gid",
78941+ .data = &grsec_socket_all_gid,
78942+ .maxlen = sizeof(int),
78943+ .mode = 0600,
78944+ .proc_handler = &proc_dointvec,
78945+ },
78946+#endif
78947+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
78948+ {
78949+ .procname = "socket_client",
78950+ .data = &grsec_enable_socket_client,
78951+ .maxlen = sizeof(int),
78952+ .mode = 0600,
78953+ .proc_handler = &proc_dointvec,
78954+ },
78955+ {
78956+ .procname = "socket_client_gid",
78957+ .data = &grsec_socket_client_gid,
78958+ .maxlen = sizeof(int),
78959+ .mode = 0600,
78960+ .proc_handler = &proc_dointvec,
78961+ },
78962+#endif
78963+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78964+ {
78965+ .procname = "socket_server",
78966+ .data = &grsec_enable_socket_server,
78967+ .maxlen = sizeof(int),
78968+ .mode = 0600,
78969+ .proc_handler = &proc_dointvec,
78970+ },
78971+ {
78972+ .procname = "socket_server_gid",
78973+ .data = &grsec_socket_server_gid,
78974+ .maxlen = sizeof(int),
78975+ .mode = 0600,
78976+ .proc_handler = &proc_dointvec,
78977+ },
78978+#endif
78979+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
78980+ {
78981+ .procname = "audit_group",
78982+ .data = &grsec_enable_group,
78983+ .maxlen = sizeof(int),
78984+ .mode = 0600,
78985+ .proc_handler = &proc_dointvec,
78986+ },
78987+ {
78988+ .procname = "audit_gid",
78989+ .data = &grsec_audit_gid,
78990+ .maxlen = sizeof(int),
78991+ .mode = 0600,
78992+ .proc_handler = &proc_dointvec,
78993+ },
78994+#endif
78995+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
78996+ {
78997+ .procname = "audit_chdir",
78998+ .data = &grsec_enable_chdir,
78999+ .maxlen = sizeof(int),
79000+ .mode = 0600,
79001+ .proc_handler = &proc_dointvec,
79002+ },
79003+#endif
79004+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
79005+ {
79006+ .procname = "audit_mount",
79007+ .data = &grsec_enable_mount,
79008+ .maxlen = sizeof(int),
79009+ .mode = 0600,
79010+ .proc_handler = &proc_dointvec,
79011+ },
79012+#endif
79013+#ifdef CONFIG_GRKERNSEC_DMESG
79014+ {
79015+ .procname = "dmesg",
79016+ .data = &grsec_enable_dmesg,
79017+ .maxlen = sizeof(int),
79018+ .mode = 0600,
79019+ .proc_handler = &proc_dointvec,
79020+ },
79021+#endif
79022+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79023+ {
79024+ .procname = "chroot_findtask",
79025+ .data = &grsec_enable_chroot_findtask,
79026+ .maxlen = sizeof(int),
79027+ .mode = 0600,
79028+ .proc_handler = &proc_dointvec,
79029+ },
79030+#endif
79031+#ifdef CONFIG_GRKERNSEC_RESLOG
79032+ {
79033+ .procname = "resource_logging",
79034+ .data = &grsec_resource_logging,
79035+ .maxlen = sizeof(int),
79036+ .mode = 0600,
79037+ .proc_handler = &proc_dointvec,
79038+ },
79039+#endif
79040+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
79041+ {
79042+ .procname = "audit_ptrace",
79043+ .data = &grsec_enable_audit_ptrace,
79044+ .maxlen = sizeof(int),
79045+ .mode = 0600,
79046+ .proc_handler = &proc_dointvec,
79047+ },
79048+#endif
79049+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
79050+ {
79051+ .procname = "harden_ptrace",
79052+ .data = &grsec_enable_harden_ptrace,
79053+ .maxlen = sizeof(int),
79054+ .mode = 0600,
79055+ .proc_handler = &proc_dointvec,
79056+ },
79057+#endif
79058+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
79059+ {
79060+ .procname = "harden_ipc",
79061+ .data = &grsec_enable_harden_ipc,
79062+ .maxlen = sizeof(int),
79063+ .mode = 0600,
79064+ .proc_handler = &proc_dointvec,
79065+ },
79066+#endif
79067+ {
79068+ .procname = "grsec_lock",
79069+ .data = &grsec_lock,
79070+ .maxlen = sizeof(int),
79071+ .mode = 0600,
79072+ .proc_handler = &proc_dointvec,
79073+ },
79074+#endif
79075+#ifdef CONFIG_GRKERNSEC_ROFS
79076+ {
79077+ .procname = "romount_protect",
79078+ .data = &grsec_enable_rofs,
79079+ .maxlen = sizeof(int),
79080+ .mode = 0600,
79081+ .proc_handler = &proc_dointvec_minmax,
79082+ .extra1 = &one,
79083+ .extra2 = &one,
79084+ },
79085+#endif
79086+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
79087+ {
79088+ .procname = "deny_new_usb",
79089+ .data = &grsec_deny_new_usb,
79090+ .maxlen = sizeof(int),
79091+ .mode = 0600,
79092+ .proc_handler = &proc_dointvec,
79093+ },
79094+#endif
79095+ { }
79096+};
79097+#endif
79098diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
79099new file mode 100644
79100index 0000000..61b514e
79101--- /dev/null
79102+++ b/grsecurity/grsec_time.c
79103@@ -0,0 +1,16 @@
79104+#include <linux/kernel.h>
79105+#include <linux/sched.h>
79106+#include <linux/grinternal.h>
79107+#include <linux/module.h>
79108+
79109+void
79110+gr_log_timechange(void)
79111+{
79112+#ifdef CONFIG_GRKERNSEC_TIME
79113+ if (grsec_enable_time)
79114+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
79115+#endif
79116+ return;
79117+}
79118+
79119+EXPORT_SYMBOL_GPL(gr_log_timechange);
79120diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
79121new file mode 100644
79122index 0000000..d1953de
79123--- /dev/null
79124+++ b/grsecurity/grsec_tpe.c
79125@@ -0,0 +1,78 @@
79126+#include <linux/kernel.h>
79127+#include <linux/sched.h>
79128+#include <linux/file.h>
79129+#include <linux/fs.h>
79130+#include <linux/grinternal.h>
79131+
79132+extern int gr_acl_tpe_check(void);
79133+
79134+int
79135+gr_tpe_allow(const struct file *file)
79136+{
79137+#ifdef CONFIG_GRKERNSEC
79138+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
79139+ struct inode *file_inode = file->f_path.dentry->d_inode;
79140+ const struct cred *cred = current_cred();
79141+ char *msg = NULL;
79142+ char *msg2 = NULL;
79143+
79144+ // never restrict root
79145+ if (gr_is_global_root(cred->uid))
79146+ return 1;
79147+
79148+ if (grsec_enable_tpe) {
79149+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
79150+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
79151+ msg = "not being in trusted group";
79152+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
79153+ msg = "being in untrusted group";
79154+#else
79155+ if (in_group_p(grsec_tpe_gid))
79156+ msg = "being in untrusted group";
79157+#endif
79158+ }
79159+ if (!msg && gr_acl_tpe_check())
79160+ msg = "being in untrusted role";
79161+
79162+ // not in any affected group/role
79163+ if (!msg)
79164+ goto next_check;
79165+
79166+ if (gr_is_global_nonroot(inode->i_uid))
79167+ msg2 = "file in non-root-owned directory";
79168+ else if (inode->i_mode & S_IWOTH)
79169+ msg2 = "file in world-writable directory";
79170+ else if (inode->i_mode & S_IWGRP)
79171+ msg2 = "file in group-writable directory";
79172+ else if (file_inode->i_mode & S_IWOTH)
79173+ msg2 = "file is world-writable";
79174+
79175+ if (msg && msg2) {
79176+ char fullmsg[70] = {0};
79177+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
79178+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
79179+ return 0;
79180+ }
79181+ msg = NULL;
79182+next_check:
79183+#ifdef CONFIG_GRKERNSEC_TPE_ALL
79184+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
79185+ return 1;
79186+
79187+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
79188+ msg = "directory not owned by user";
79189+ else if (inode->i_mode & S_IWOTH)
79190+ msg = "file in world-writable directory";
79191+ else if (inode->i_mode & S_IWGRP)
79192+ msg = "file in group-writable directory";
79193+ else if (file_inode->i_mode & S_IWOTH)
79194+ msg = "file is world-writable";
79195+
79196+ if (msg) {
79197+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
79198+ return 0;
79199+ }
79200+#endif
79201+#endif
79202+ return 1;
79203+}
79204diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
79205new file mode 100644
79206index 0000000..ae02d8e
79207--- /dev/null
79208+++ b/grsecurity/grsec_usb.c
79209@@ -0,0 +1,15 @@
79210+#include <linux/kernel.h>
79211+#include <linux/grinternal.h>
79212+#include <linux/module.h>
79213+
79214+int gr_handle_new_usb(void)
79215+{
79216+#ifdef CONFIG_GRKERNSEC_DENYUSB
79217+ if (grsec_deny_new_usb) {
79218+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
79219+ return 1;
79220+ }
79221+#endif
79222+ return 0;
79223+}
79224+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
79225diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
79226new file mode 100644
79227index 0000000..158b330
79228--- /dev/null
79229+++ b/grsecurity/grsum.c
79230@@ -0,0 +1,64 @@
79231+#include <linux/err.h>
79232+#include <linux/kernel.h>
79233+#include <linux/sched.h>
79234+#include <linux/mm.h>
79235+#include <linux/scatterlist.h>
79236+#include <linux/crypto.h>
79237+#include <linux/gracl.h>
79238+
79239+
79240+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
79241+#error "crypto and sha256 must be built into the kernel"
79242+#endif
79243+
79244+int
79245+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
79246+{
79247+ struct crypto_hash *tfm;
79248+ struct hash_desc desc;
79249+ struct scatterlist sg[2];
79250+ unsigned char temp_sum[GR_SHA_LEN] __attribute__((aligned(__alignof__(unsigned long))));
79251+ unsigned long *tmpsumptr = (unsigned long *)temp_sum;
79252+ unsigned long *sumptr = (unsigned long *)sum;
79253+ int cryptres;
79254+ int retval = 1;
79255+ volatile int mismatched = 0;
79256+ volatile int dummy = 0;
79257+ unsigned int i;
79258+
79259+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
79260+ if (IS_ERR(tfm)) {
79261+ /* should never happen, since sha256 should be built in */
79262+ memset(entry->pw, 0, GR_PW_LEN);
79263+ return 1;
79264+ }
79265+
79266+ sg_init_table(sg, 2);
79267+ sg_set_buf(&sg[0], salt, GR_SALT_LEN);
79268+ sg_set_buf(&sg[1], entry->pw, strlen(entry->pw));
79269+
79270+ desc.tfm = tfm;
79271+ desc.flags = 0;
79272+
79273+ cryptres = crypto_hash_digest(&desc, sg, GR_SALT_LEN + strlen(entry->pw),
79274+ temp_sum);
79275+
79276+ memset(entry->pw, 0, GR_PW_LEN);
79277+
79278+ if (cryptres)
79279+ goto out;
79280+
79281+ for (i = 0; i < GR_SHA_LEN/sizeof(tmpsumptr[0]); i++)
79282+ if (sumptr[i] != tmpsumptr[i])
79283+ mismatched = 1;
79284+ else
79285+ dummy = 1; // waste a cycle
79286+
79287+ if (!mismatched)
79288+ retval = dummy - 1;
79289+
79290+out:
79291+ crypto_free_hash(tfm);
79292+
79293+ return retval;
79294+}
79295diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
79296index 77ff547..181834f 100644
79297--- a/include/asm-generic/4level-fixup.h
79298+++ b/include/asm-generic/4level-fixup.h
79299@@ -13,8 +13,10 @@
79300 #define pmd_alloc(mm, pud, address) \
79301 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
79302 NULL: pmd_offset(pud, address))
79303+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
79304
79305 #define pud_alloc(mm, pgd, address) (pgd)
79306+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
79307 #define pud_offset(pgd, start) (pgd)
79308 #define pud_none(pud) 0
79309 #define pud_bad(pud) 0
79310diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
79311index b7babf0..1e4b4f1 100644
79312--- a/include/asm-generic/atomic-long.h
79313+++ b/include/asm-generic/atomic-long.h
79314@@ -22,6 +22,12 @@
79315
79316 typedef atomic64_t atomic_long_t;
79317
79318+#ifdef CONFIG_PAX_REFCOUNT
79319+typedef atomic64_unchecked_t atomic_long_unchecked_t;
79320+#else
79321+typedef atomic64_t atomic_long_unchecked_t;
79322+#endif
79323+
79324 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
79325
79326 static inline long atomic_long_read(atomic_long_t *l)
79327@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
79328 return (long)atomic64_read(v);
79329 }
79330
79331+#ifdef CONFIG_PAX_REFCOUNT
79332+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
79333+{
79334+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79335+
79336+ return (long)atomic64_read_unchecked(v);
79337+}
79338+#endif
79339+
79340 static inline void atomic_long_set(atomic_long_t *l, long i)
79341 {
79342 atomic64_t *v = (atomic64_t *)l;
79343@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
79344 atomic64_set(v, i);
79345 }
79346
79347+#ifdef CONFIG_PAX_REFCOUNT
79348+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
79349+{
79350+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79351+
79352+ atomic64_set_unchecked(v, i);
79353+}
79354+#endif
79355+
79356 static inline void atomic_long_inc(atomic_long_t *l)
79357 {
79358 atomic64_t *v = (atomic64_t *)l;
79359@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
79360 atomic64_inc(v);
79361 }
79362
79363+#ifdef CONFIG_PAX_REFCOUNT
79364+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
79365+{
79366+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79367+
79368+ atomic64_inc_unchecked(v);
79369+}
79370+#endif
79371+
79372 static inline void atomic_long_dec(atomic_long_t *l)
79373 {
79374 atomic64_t *v = (atomic64_t *)l;
79375@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
79376 atomic64_dec(v);
79377 }
79378
79379+#ifdef CONFIG_PAX_REFCOUNT
79380+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
79381+{
79382+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79383+
79384+ atomic64_dec_unchecked(v);
79385+}
79386+#endif
79387+
79388 static inline void atomic_long_add(long i, atomic_long_t *l)
79389 {
79390 atomic64_t *v = (atomic64_t *)l;
79391@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
79392 atomic64_add(i, v);
79393 }
79394
79395+#ifdef CONFIG_PAX_REFCOUNT
79396+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
79397+{
79398+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79399+
79400+ atomic64_add_unchecked(i, v);
79401+}
79402+#endif
79403+
79404 static inline void atomic_long_sub(long i, atomic_long_t *l)
79405 {
79406 atomic64_t *v = (atomic64_t *)l;
79407@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
79408 atomic64_sub(i, v);
79409 }
79410
79411+#ifdef CONFIG_PAX_REFCOUNT
79412+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
79413+{
79414+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79415+
79416+ atomic64_sub_unchecked(i, v);
79417+}
79418+#endif
79419+
79420 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
79421 {
79422 atomic64_t *v = (atomic64_t *)l;
79423@@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
79424 return atomic64_add_negative(i, v);
79425 }
79426
79427-static inline long atomic_long_add_return(long i, atomic_long_t *l)
79428+static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
79429 {
79430 atomic64_t *v = (atomic64_t *)l;
79431
79432 return (long)atomic64_add_return(i, v);
79433 }
79434
79435+#ifdef CONFIG_PAX_REFCOUNT
79436+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
79437+{
79438+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79439+
79440+ return (long)atomic64_add_return_unchecked(i, v);
79441+}
79442+#endif
79443+
79444 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
79445 {
79446 atomic64_t *v = (atomic64_t *)l;
79447@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
79448 return (long)atomic64_inc_return(v);
79449 }
79450
79451+#ifdef CONFIG_PAX_REFCOUNT
79452+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
79453+{
79454+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79455+
79456+ return (long)atomic64_inc_return_unchecked(v);
79457+}
79458+#endif
79459+
79460 static inline long atomic_long_dec_return(atomic_long_t *l)
79461 {
79462 atomic64_t *v = (atomic64_t *)l;
79463@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
79464
79465 typedef atomic_t atomic_long_t;
79466
79467+#ifdef CONFIG_PAX_REFCOUNT
79468+typedef atomic_unchecked_t atomic_long_unchecked_t;
79469+#else
79470+typedef atomic_t atomic_long_unchecked_t;
79471+#endif
79472+
79473 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
79474 static inline long atomic_long_read(atomic_long_t *l)
79475 {
79476@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
79477 return (long)atomic_read(v);
79478 }
79479
79480+#ifdef CONFIG_PAX_REFCOUNT
79481+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
79482+{
79483+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79484+
79485+ return (long)atomic_read_unchecked(v);
79486+}
79487+#endif
79488+
79489 static inline void atomic_long_set(atomic_long_t *l, long i)
79490 {
79491 atomic_t *v = (atomic_t *)l;
79492@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
79493 atomic_set(v, i);
79494 }
79495
79496+#ifdef CONFIG_PAX_REFCOUNT
79497+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
79498+{
79499+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79500+
79501+ atomic_set_unchecked(v, i);
79502+}
79503+#endif
79504+
79505 static inline void atomic_long_inc(atomic_long_t *l)
79506 {
79507 atomic_t *v = (atomic_t *)l;
79508@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
79509 atomic_inc(v);
79510 }
79511
79512+#ifdef CONFIG_PAX_REFCOUNT
79513+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
79514+{
79515+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79516+
79517+ atomic_inc_unchecked(v);
79518+}
79519+#endif
79520+
79521 static inline void atomic_long_dec(atomic_long_t *l)
79522 {
79523 atomic_t *v = (atomic_t *)l;
79524@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
79525 atomic_dec(v);
79526 }
79527
79528+#ifdef CONFIG_PAX_REFCOUNT
79529+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
79530+{
79531+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79532+
79533+ atomic_dec_unchecked(v);
79534+}
79535+#endif
79536+
79537 static inline void atomic_long_add(long i, atomic_long_t *l)
79538 {
79539 atomic_t *v = (atomic_t *)l;
79540@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
79541 atomic_add(i, v);
79542 }
79543
79544+#ifdef CONFIG_PAX_REFCOUNT
79545+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
79546+{
79547+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79548+
79549+ atomic_add_unchecked(i, v);
79550+}
79551+#endif
79552+
79553 static inline void atomic_long_sub(long i, atomic_long_t *l)
79554 {
79555 atomic_t *v = (atomic_t *)l;
79556@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
79557 atomic_sub(i, v);
79558 }
79559
79560+#ifdef CONFIG_PAX_REFCOUNT
79561+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
79562+{
79563+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79564+
79565+ atomic_sub_unchecked(i, v);
79566+}
79567+#endif
79568+
79569 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
79570 {
79571 atomic_t *v = (atomic_t *)l;
79572@@ -211,13 +349,23 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
79573 return atomic_add_negative(i, v);
79574 }
79575
79576-static inline long atomic_long_add_return(long i, atomic_long_t *l)
79577+static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
79578 {
79579 atomic_t *v = (atomic_t *)l;
79580
79581 return (long)atomic_add_return(i, v);
79582 }
79583
79584+#ifdef CONFIG_PAX_REFCOUNT
79585+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
79586+{
79587+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79588+
79589+ return (long)atomic_add_return_unchecked(i, v);
79590+}
79591+
79592+#endif
79593+
79594 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
79595 {
79596 atomic_t *v = (atomic_t *)l;
79597@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
79598 return (long)atomic_inc_return(v);
79599 }
79600
79601+#ifdef CONFIG_PAX_REFCOUNT
79602+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
79603+{
79604+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79605+
79606+ return (long)atomic_inc_return_unchecked(v);
79607+}
79608+#endif
79609+
79610 static inline long atomic_long_dec_return(atomic_long_t *l)
79611 {
79612 atomic_t *v = (atomic_t *)l;
79613@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
79614
79615 #endif /* BITS_PER_LONG == 64 */
79616
79617+#ifdef CONFIG_PAX_REFCOUNT
79618+static inline void pax_refcount_needs_these_functions(void)
79619+{
79620+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
79621+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
79622+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
79623+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
79624+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
79625+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
79626+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
79627+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
79628+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
79629+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
79630+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
79631+#ifdef CONFIG_X86
79632+ atomic_clear_mask_unchecked(0, NULL);
79633+ atomic_set_mask_unchecked(0, NULL);
79634+#endif
79635+
79636+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
79637+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
79638+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
79639+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
79640+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
79641+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
79642+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
79643+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
79644+}
79645+#else
79646+#define atomic_read_unchecked(v) atomic_read(v)
79647+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
79648+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
79649+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
79650+#define atomic_inc_unchecked(v) atomic_inc(v)
79651+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
79652+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
79653+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
79654+#define atomic_dec_unchecked(v) atomic_dec(v)
79655+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
79656+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
79657+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
79658+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
79659+
79660+#define atomic_long_read_unchecked(v) atomic_long_read(v)
79661+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
79662+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
79663+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
79664+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
79665+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
79666+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
79667+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
79668+#endif
79669+
79670 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
79671diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
79672index 30ad9c8..c70c170 100644
79673--- a/include/asm-generic/atomic64.h
79674+++ b/include/asm-generic/atomic64.h
79675@@ -16,6 +16,8 @@ typedef struct {
79676 long long counter;
79677 } atomic64_t;
79678
79679+typedef atomic64_t atomic64_unchecked_t;
79680+
79681 #define ATOMIC64_INIT(i) { (i) }
79682
79683 extern long long atomic64_read(const atomic64_t *v);
79684@@ -51,4 +53,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
79685 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
79686 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
79687
79688+#define atomic64_read_unchecked(v) atomic64_read(v)
79689+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
79690+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
79691+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
79692+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
79693+#define atomic64_inc_unchecked(v) atomic64_inc(v)
79694+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
79695+#define atomic64_dec_unchecked(v) atomic64_dec(v)
79696+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
79697+
79698 #endif /* _ASM_GENERIC_ATOMIC64_H */
79699diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
79700index 1402fa8..025a736 100644
79701--- a/include/asm-generic/barrier.h
79702+++ b/include/asm-generic/barrier.h
79703@@ -74,7 +74,7 @@
79704 do { \
79705 compiletime_assert_atomic_type(*p); \
79706 smp_mb(); \
79707- ACCESS_ONCE(*p) = (v); \
79708+ ACCESS_ONCE_RW(*p) = (v); \
79709 } while (0)
79710
79711 #define smp_load_acquire(p) \
79712diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
79713index a60a7cc..0fe12f2 100644
79714--- a/include/asm-generic/bitops/__fls.h
79715+++ b/include/asm-generic/bitops/__fls.h
79716@@ -9,7 +9,7 @@
79717 *
79718 * Undefined if no set bit exists, so code should check against 0 first.
79719 */
79720-static __always_inline unsigned long __fls(unsigned long word)
79721+static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
79722 {
79723 int num = BITS_PER_LONG - 1;
79724
79725diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
79726index 0576d1f..dad6c71 100644
79727--- a/include/asm-generic/bitops/fls.h
79728+++ b/include/asm-generic/bitops/fls.h
79729@@ -9,7 +9,7 @@
79730 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
79731 */
79732
79733-static __always_inline int fls(int x)
79734+static __always_inline int __intentional_overflow(-1) fls(int x)
79735 {
79736 int r = 32;
79737
79738diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
79739index b097cf8..3d40e14 100644
79740--- a/include/asm-generic/bitops/fls64.h
79741+++ b/include/asm-generic/bitops/fls64.h
79742@@ -15,7 +15,7 @@
79743 * at position 64.
79744 */
79745 #if BITS_PER_LONG == 32
79746-static __always_inline int fls64(__u64 x)
79747+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
79748 {
79749 __u32 h = x >> 32;
79750 if (h)
79751@@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
79752 return fls(x);
79753 }
79754 #elif BITS_PER_LONG == 64
79755-static __always_inline int fls64(__u64 x)
79756+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
79757 {
79758 if (x == 0)
79759 return 0;
79760diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
79761index 1bfcfe5..e04c5c9 100644
79762--- a/include/asm-generic/cache.h
79763+++ b/include/asm-generic/cache.h
79764@@ -6,7 +6,7 @@
79765 * cache lines need to provide their own cache.h.
79766 */
79767
79768-#define L1_CACHE_SHIFT 5
79769-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
79770+#define L1_CACHE_SHIFT 5UL
79771+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
79772
79773 #endif /* __ASM_GENERIC_CACHE_H */
79774diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
79775index 0d68a1e..b74a761 100644
79776--- a/include/asm-generic/emergency-restart.h
79777+++ b/include/asm-generic/emergency-restart.h
79778@@ -1,7 +1,7 @@
79779 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
79780 #define _ASM_GENERIC_EMERGENCY_RESTART_H
79781
79782-static inline void machine_emergency_restart(void)
79783+static inline __noreturn void machine_emergency_restart(void)
79784 {
79785 machine_restart(NULL);
79786 }
79787diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
79788index b8fdc57..c6d5a5c 100644
79789--- a/include/asm-generic/io.h
79790+++ b/include/asm-generic/io.h
79791@@ -289,7 +289,7 @@ static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
79792 * These are pretty trivial
79793 */
79794 #ifndef virt_to_phys
79795-static inline unsigned long virt_to_phys(volatile void *address)
79796+static inline unsigned long __intentional_overflow(-1) virt_to_phys(volatile void *address)
79797 {
79798 return __pa((unsigned long)address);
79799 }
79800diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
79801index 90f99c7..00ce236 100644
79802--- a/include/asm-generic/kmap_types.h
79803+++ b/include/asm-generic/kmap_types.h
79804@@ -2,9 +2,9 @@
79805 #define _ASM_GENERIC_KMAP_TYPES_H
79806
79807 #ifdef __WITH_KM_FENCE
79808-# define KM_TYPE_NR 41
79809+# define KM_TYPE_NR 42
79810 #else
79811-# define KM_TYPE_NR 20
79812+# define KM_TYPE_NR 21
79813 #endif
79814
79815 #endif
79816diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
79817index 9ceb03b..62b0b8f 100644
79818--- a/include/asm-generic/local.h
79819+++ b/include/asm-generic/local.h
79820@@ -23,24 +23,37 @@ typedef struct
79821 atomic_long_t a;
79822 } local_t;
79823
79824+typedef struct {
79825+ atomic_long_unchecked_t a;
79826+} local_unchecked_t;
79827+
79828 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
79829
79830 #define local_read(l) atomic_long_read(&(l)->a)
79831+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
79832 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
79833+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
79834 #define local_inc(l) atomic_long_inc(&(l)->a)
79835+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
79836 #define local_dec(l) atomic_long_dec(&(l)->a)
79837+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
79838 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
79839+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
79840 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
79841+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
79842
79843 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
79844 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
79845 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
79846 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
79847 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
79848+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
79849 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
79850 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
79851+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
79852
79853 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
79854+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
79855 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
79856 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
79857 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
79858diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
79859index 725612b..9cc513a 100644
79860--- a/include/asm-generic/pgtable-nopmd.h
79861+++ b/include/asm-generic/pgtable-nopmd.h
79862@@ -1,14 +1,19 @@
79863 #ifndef _PGTABLE_NOPMD_H
79864 #define _PGTABLE_NOPMD_H
79865
79866-#ifndef __ASSEMBLY__
79867-
79868 #include <asm-generic/pgtable-nopud.h>
79869
79870-struct mm_struct;
79871-
79872 #define __PAGETABLE_PMD_FOLDED
79873
79874+#define PMD_SHIFT PUD_SHIFT
79875+#define PTRS_PER_PMD 1
79876+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
79877+#define PMD_MASK (~(PMD_SIZE-1))
79878+
79879+#ifndef __ASSEMBLY__
79880+
79881+struct mm_struct;
79882+
79883 /*
79884 * Having the pmd type consist of a pud gets the size right, and allows
79885 * us to conceptually access the pud entry that this pmd is folded into
79886@@ -16,11 +21,6 @@ struct mm_struct;
79887 */
79888 typedef struct { pud_t pud; } pmd_t;
79889
79890-#define PMD_SHIFT PUD_SHIFT
79891-#define PTRS_PER_PMD 1
79892-#define PMD_SIZE (1UL << PMD_SHIFT)
79893-#define PMD_MASK (~(PMD_SIZE-1))
79894-
79895 /*
79896 * The "pud_xxx()" functions here are trivial for a folded two-level
79897 * setup: the pmd is never bad, and a pmd always exists (as it's folded
79898diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
79899index 810431d..0ec4804f 100644
79900--- a/include/asm-generic/pgtable-nopud.h
79901+++ b/include/asm-generic/pgtable-nopud.h
79902@@ -1,10 +1,15 @@
79903 #ifndef _PGTABLE_NOPUD_H
79904 #define _PGTABLE_NOPUD_H
79905
79906-#ifndef __ASSEMBLY__
79907-
79908 #define __PAGETABLE_PUD_FOLDED
79909
79910+#define PUD_SHIFT PGDIR_SHIFT
79911+#define PTRS_PER_PUD 1
79912+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
79913+#define PUD_MASK (~(PUD_SIZE-1))
79914+
79915+#ifndef __ASSEMBLY__
79916+
79917 /*
79918 * Having the pud type consist of a pgd gets the size right, and allows
79919 * us to conceptually access the pgd entry that this pud is folded into
79920@@ -12,11 +17,6 @@
79921 */
79922 typedef struct { pgd_t pgd; } pud_t;
79923
79924-#define PUD_SHIFT PGDIR_SHIFT
79925-#define PTRS_PER_PUD 1
79926-#define PUD_SIZE (1UL << PUD_SHIFT)
79927-#define PUD_MASK (~(PUD_SIZE-1))
79928-
79929 /*
79930 * The "pgd_xxx()" functions here are trivial for a folded two-level
79931 * setup: the pud is never bad, and a pud always exists (as it's folded
79932@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
79933 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
79934
79935 #define pgd_populate(mm, pgd, pud) do { } while (0)
79936+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
79937 /*
79938 * (puds are folded into pgds so this doesn't get actually called,
79939 * but the define is needed for a generic inline function.)
79940diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
79941index 752e30d..87f172d 100644
79942--- a/include/asm-generic/pgtable.h
79943+++ b/include/asm-generic/pgtable.h
79944@@ -828,6 +828,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
79945 }
79946 #endif /* CONFIG_NUMA_BALANCING */
79947
79948+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
79949+#ifdef CONFIG_PAX_KERNEXEC
79950+#error KERNEXEC requires pax_open_kernel
79951+#else
79952+static inline unsigned long pax_open_kernel(void) { return 0; }
79953+#endif
79954+#endif
79955+
79956+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
79957+#ifdef CONFIG_PAX_KERNEXEC
79958+#error KERNEXEC requires pax_close_kernel
79959+#else
79960+static inline unsigned long pax_close_kernel(void) { return 0; }
79961+#endif
79962+#endif
79963+
79964 #endif /* CONFIG_MMU */
79965
79966 #endif /* !__ASSEMBLY__ */
79967diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
79968index 72d8803..cb9749c 100644
79969--- a/include/asm-generic/uaccess.h
79970+++ b/include/asm-generic/uaccess.h
79971@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
79972 return __clear_user(to, n);
79973 }
79974
79975+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
79976+#ifdef CONFIG_PAX_MEMORY_UDEREF
79977+#error UDEREF requires pax_open_userland
79978+#else
79979+static inline unsigned long pax_open_userland(void) { return 0; }
79980+#endif
79981+#endif
79982+
79983+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
79984+#ifdef CONFIG_PAX_MEMORY_UDEREF
79985+#error UDEREF requires pax_close_userland
79986+#else
79987+static inline unsigned long pax_close_userland(void) { return 0; }
79988+#endif
79989+#endif
79990+
79991 #endif /* __ASM_GENERIC_UACCESS_H */
79992diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
79993index aa70cbd..fd72c7a 100644
79994--- a/include/asm-generic/vmlinux.lds.h
79995+++ b/include/asm-generic/vmlinux.lds.h
79996@@ -233,6 +233,7 @@
79997 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
79998 VMLINUX_SYMBOL(__start_rodata) = .; \
79999 *(.rodata) *(.rodata.*) \
80000+ *(.data..read_only) \
80001 *(__vermagic) /* Kernel version magic */ \
80002 . = ALIGN(8); \
80003 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
80004@@ -724,17 +725,18 @@
80005 * section in the linker script will go there too. @phdr should have
80006 * a leading colon.
80007 *
80008- * Note that this macros defines __per_cpu_load as an absolute symbol.
80009+ * Note that this macros defines per_cpu_load as an absolute symbol.
80010 * If there is no need to put the percpu section at a predetermined
80011 * address, use PERCPU_SECTION.
80012 */
80013 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
80014- VMLINUX_SYMBOL(__per_cpu_load) = .; \
80015- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
80016+ per_cpu_load = .; \
80017+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
80018 - LOAD_OFFSET) { \
80019+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
80020 PERCPU_INPUT(cacheline) \
80021 } phdr \
80022- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
80023+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
80024
80025 /**
80026 * PERCPU_SECTION - define output section for percpu area, simple version
80027diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
80028index 623a59c..1e79ab9 100644
80029--- a/include/crypto/algapi.h
80030+++ b/include/crypto/algapi.h
80031@@ -34,7 +34,7 @@ struct crypto_type {
80032 unsigned int maskclear;
80033 unsigned int maskset;
80034 unsigned int tfmsize;
80035-};
80036+} __do_const;
80037
80038 struct crypto_instance {
80039 struct crypto_alg alg;
80040diff --git a/include/drm/drmP.h b/include/drm/drmP.h
80041index 53ed876..5bb09be 100644
80042--- a/include/drm/drmP.h
80043+++ b/include/drm/drmP.h
80044@@ -59,6 +59,7 @@
80045
80046 #include <asm/mman.h>
80047 #include <asm/pgalloc.h>
80048+#include <asm/local.h>
80049 #include <asm/uaccess.h>
80050
80051 #include <uapi/drm/drm.h>
80052@@ -223,10 +224,12 @@ void drm_err(const char *func, const char *format, ...);
80053 * \param cmd command.
80054 * \param arg argument.
80055 */
80056-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
80057+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
80058+ struct drm_file *file_priv);
80059+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
80060 struct drm_file *file_priv);
80061
80062-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
80063+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
80064 unsigned long arg);
80065
80066 #define DRM_IOCTL_NR(n) _IOC_NR(n)
80067@@ -242,10 +245,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
80068 struct drm_ioctl_desc {
80069 unsigned int cmd;
80070 int flags;
80071- drm_ioctl_t *func;
80072+ drm_ioctl_t func;
80073 unsigned int cmd_drv;
80074 const char *name;
80075-};
80076+} __do_const;
80077
80078 /**
80079 * Creates a driver or general drm_ioctl_desc array entry for the given
80080@@ -629,7 +632,8 @@ struct drm_info_list {
80081 int (*show)(struct seq_file*, void*); /** show callback */
80082 u32 driver_features; /**< Required driver features for this entry */
80083 void *data;
80084-};
80085+} __do_const;
80086+typedef struct drm_info_list __no_const drm_info_list_no_const;
80087
80088 /**
80089 * debugfs node structure. This structure represents a debugfs file.
80090@@ -713,7 +717,7 @@ struct drm_device {
80091
80092 /** \name Usage Counters */
80093 /*@{ */
80094- int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
80095+ local_t open_count; /**< Outstanding files open, protected by drm_global_mutex. */
80096 spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */
80097 int buf_use; /**< Buffers in use -- cannot alloc */
80098 atomic_t buf_alloc; /**< Buffer allocation in progress */
80099diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
80100index a3d75fe..6802f9c 100644
80101--- a/include/drm/drm_crtc_helper.h
80102+++ b/include/drm/drm_crtc_helper.h
80103@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
80104 struct drm_connector *connector);
80105 /* disable encoder when not in use - more explicit than dpms off */
80106 void (*disable)(struct drm_encoder *encoder);
80107-};
80108+} __no_const;
80109
80110 /**
80111 * drm_connector_helper_funcs - helper operations for connectors
80112diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
80113index a70d456..6ea07cd 100644
80114--- a/include/drm/i915_pciids.h
80115+++ b/include/drm/i915_pciids.h
80116@@ -37,7 +37,7 @@
80117 */
80118 #define INTEL_VGA_DEVICE(id, info) { \
80119 0x8086, id, \
80120- ~0, ~0, \
80121+ PCI_ANY_ID, PCI_ANY_ID, \
80122 0x030000, 0xff0000, \
80123 (unsigned long) info }
80124
80125diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
80126index 72dcbe8..8db58d7 100644
80127--- a/include/drm/ttm/ttm_memory.h
80128+++ b/include/drm/ttm/ttm_memory.h
80129@@ -48,7 +48,7 @@
80130
80131 struct ttm_mem_shrink {
80132 int (*do_shrink) (struct ttm_mem_shrink *);
80133-};
80134+} __no_const;
80135
80136 /**
80137 * struct ttm_mem_global - Global memory accounting structure.
80138diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
80139index 49a8284..9643967 100644
80140--- a/include/drm/ttm/ttm_page_alloc.h
80141+++ b/include/drm/ttm/ttm_page_alloc.h
80142@@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
80143 */
80144 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
80145
80146+struct device;
80147 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
80148 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
80149
80150diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
80151index 4b840e8..155d235 100644
80152--- a/include/keys/asymmetric-subtype.h
80153+++ b/include/keys/asymmetric-subtype.h
80154@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
80155 /* Verify the signature on a key of this subtype (optional) */
80156 int (*verify_signature)(const struct key *key,
80157 const struct public_key_signature *sig);
80158-};
80159+} __do_const;
80160
80161 /**
80162 * asymmetric_key_subtype - Get the subtype from an asymmetric key
80163diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
80164index c1da539..1dcec55 100644
80165--- a/include/linux/atmdev.h
80166+++ b/include/linux/atmdev.h
80167@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
80168 #endif
80169
80170 struct k_atm_aal_stats {
80171-#define __HANDLE_ITEM(i) atomic_t i
80172+#define __HANDLE_ITEM(i) atomic_unchecked_t i
80173 __AAL_STAT_ITEMS
80174 #undef __HANDLE_ITEM
80175 };
80176@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
80177 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
80178 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
80179 struct module *owner;
80180-};
80181+} __do_const ;
80182
80183 struct atmphy_ops {
80184 int (*start)(struct atm_dev *dev);
80185diff --git a/include/linux/audit.h b/include/linux/audit.h
80186index e58fe7d..be9f6d8 100644
80187--- a/include/linux/audit.h
80188+++ b/include/linux/audit.h
80189@@ -215,7 +215,7 @@ static inline void audit_ptrace(struct task_struct *t)
80190 extern unsigned int audit_serial(void);
80191 extern int auditsc_get_stamp(struct audit_context *ctx,
80192 struct timespec *t, unsigned int *serial);
80193-extern int audit_set_loginuid(kuid_t loginuid);
80194+extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
80195
80196 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
80197 {
80198diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
80199index 61f29e5..e67c658 100644
80200--- a/include/linux/binfmts.h
80201+++ b/include/linux/binfmts.h
80202@@ -44,7 +44,7 @@ struct linux_binprm {
80203 unsigned interp_flags;
80204 unsigned interp_data;
80205 unsigned long loader, exec;
80206-};
80207+} __randomize_layout;
80208
80209 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
80210 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
80211@@ -73,8 +73,10 @@ struct linux_binfmt {
80212 int (*load_binary)(struct linux_binprm *);
80213 int (*load_shlib)(struct file *);
80214 int (*core_dump)(struct coredump_params *cprm);
80215+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
80216+ void (*handle_mmap)(struct file *);
80217 unsigned long min_coredump; /* minimal dump size */
80218-};
80219+} __do_const __randomize_layout;
80220
80221 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
80222
80223diff --git a/include/linux/bitops.h b/include/linux/bitops.h
80224index 5d858e0..336c1d9 100644
80225--- a/include/linux/bitops.h
80226+++ b/include/linux/bitops.h
80227@@ -105,7 +105,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
80228 * @word: value to rotate
80229 * @shift: bits to roll
80230 */
80231-static inline __u32 rol32(__u32 word, unsigned int shift)
80232+static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
80233 {
80234 return (word << shift) | (word >> (32 - shift));
80235 }
80236@@ -115,7 +115,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
80237 * @word: value to rotate
80238 * @shift: bits to roll
80239 */
80240-static inline __u32 ror32(__u32 word, unsigned int shift)
80241+static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
80242 {
80243 return (word >> shift) | (word << (32 - shift));
80244 }
80245@@ -171,7 +171,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
80246 return (__s32)(value << shift) >> shift;
80247 }
80248
80249-static inline unsigned fls_long(unsigned long l)
80250+static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
80251 {
80252 if (sizeof(l) == 4)
80253 return fls(l);
80254diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
80255index aac0f9e..73c9869 100644
80256--- a/include/linux/blkdev.h
80257+++ b/include/linux/blkdev.h
80258@@ -1615,7 +1615,7 @@ struct block_device_operations {
80259 /* this callback is with swap_lock and sometimes page table lock held */
80260 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
80261 struct module *owner;
80262-};
80263+} __do_const;
80264
80265 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
80266 unsigned long);
80267diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
80268index afc1343..9735539 100644
80269--- a/include/linux/blktrace_api.h
80270+++ b/include/linux/blktrace_api.h
80271@@ -25,7 +25,7 @@ struct blk_trace {
80272 struct dentry *dropped_file;
80273 struct dentry *msg_file;
80274 struct list_head running_list;
80275- atomic_t dropped;
80276+ atomic_unchecked_t dropped;
80277 };
80278
80279 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
80280diff --git a/include/linux/cache.h b/include/linux/cache.h
80281index 17e7e82..1d7da26 100644
80282--- a/include/linux/cache.h
80283+++ b/include/linux/cache.h
80284@@ -16,6 +16,14 @@
80285 #define __read_mostly
80286 #endif
80287
80288+#ifndef __read_only
80289+#ifdef CONFIG_PAX_KERNEXEC
80290+#error KERNEXEC requires __read_only
80291+#else
80292+#define __read_only __read_mostly
80293+#endif
80294+#endif
80295+
80296 #ifndef ____cacheline_aligned
80297 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
80298 #endif
80299diff --git a/include/linux/capability.h b/include/linux/capability.h
80300index aa93e5e..985a1b0 100644
80301--- a/include/linux/capability.h
80302+++ b/include/linux/capability.h
80303@@ -214,9 +214,14 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
80304 extern bool capable(int cap);
80305 extern bool ns_capable(struct user_namespace *ns, int cap);
80306 extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
80307+extern bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap);
80308 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
80309+extern bool capable_nolog(int cap);
80310+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
80311
80312 /* audit system wants to get cap info from files as well */
80313 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
80314
80315+extern int is_privileged_binary(const struct dentry *dentry);
80316+
80317 #endif /* !_LINUX_CAPABILITY_H */
80318diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
80319index 8609d57..86e4d79 100644
80320--- a/include/linux/cdrom.h
80321+++ b/include/linux/cdrom.h
80322@@ -87,7 +87,6 @@ struct cdrom_device_ops {
80323
80324 /* driver specifications */
80325 const int capability; /* capability flags */
80326- int n_minors; /* number of active minor devices */
80327 /* handle uniform packets for scsi type devices (scsi,atapi) */
80328 int (*generic_packet) (struct cdrom_device_info *,
80329 struct packet_command *);
80330diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
80331index 4ce9056..86caac6 100644
80332--- a/include/linux/cleancache.h
80333+++ b/include/linux/cleancache.h
80334@@ -31,7 +31,7 @@ struct cleancache_ops {
80335 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
80336 void (*invalidate_inode)(int, struct cleancache_filekey);
80337 void (*invalidate_fs)(int);
80338-};
80339+} __no_const;
80340
80341 extern struct cleancache_ops *
80342 cleancache_register_ops(struct cleancache_ops *ops);
80343diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
80344index 2839c63..5b06b6b 100644
80345--- a/include/linux/clk-provider.h
80346+++ b/include/linux/clk-provider.h
80347@@ -191,6 +191,7 @@ struct clk_ops {
80348 void (*init)(struct clk_hw *hw);
80349 int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
80350 };
80351+typedef struct clk_ops __no_const clk_ops_no_const;
80352
80353 /**
80354 * struct clk_init_data - holds init data that's common to all clocks and is
80355diff --git a/include/linux/compat.h b/include/linux/compat.h
80356index e649426..a74047b 100644
80357--- a/include/linux/compat.h
80358+++ b/include/linux/compat.h
80359@@ -316,7 +316,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
80360 compat_size_t __user *len_ptr);
80361
80362 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
80363-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
80364+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
80365 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
80366 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
80367 compat_ssize_t msgsz, int msgflg);
80368@@ -436,7 +436,7 @@ extern int compat_ptrace_request(struct task_struct *child,
80369 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
80370 compat_ulong_t addr, compat_ulong_t data);
80371 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
80372- compat_long_t addr, compat_long_t data);
80373+ compat_ulong_t addr, compat_ulong_t data);
80374
80375 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
80376 /*
80377diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
80378index d1a5582..4424efa 100644
80379--- a/include/linux/compiler-gcc4.h
80380+++ b/include/linux/compiler-gcc4.h
80381@@ -39,9 +39,34 @@
80382 # define __compiletime_warning(message) __attribute__((warning(message)))
80383 # define __compiletime_error(message) __attribute__((error(message)))
80384 #endif /* __CHECKER__ */
80385+
80386+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
80387+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
80388+#define __bos0(ptr) __bos((ptr), 0)
80389+#define __bos1(ptr) __bos((ptr), 1)
80390 #endif /* GCC_VERSION >= 40300 */
80391
80392 #if GCC_VERSION >= 40500
80393+
80394+#ifdef RANDSTRUCT_PLUGIN
80395+#define __randomize_layout __attribute__((randomize_layout))
80396+#define __no_randomize_layout __attribute__((no_randomize_layout))
80397+#endif
80398+
80399+#ifdef CONSTIFY_PLUGIN
80400+#define __no_const __attribute__((no_const))
80401+#define __do_const __attribute__((do_const))
80402+#endif
80403+
80404+#ifdef SIZE_OVERFLOW_PLUGIN
80405+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
80406+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
80407+#endif
80408+
80409+#ifdef LATENT_ENTROPY_PLUGIN
80410+#define __latent_entropy __attribute__((latent_entropy))
80411+#endif
80412+
80413 /*
80414 * Mark a position in code as unreachable. This can be used to
80415 * suppress control flow warnings after asm blocks that transfer
80416diff --git a/include/linux/compiler.h b/include/linux/compiler.h
80417index d5ad7b1..3b74638 100644
80418--- a/include/linux/compiler.h
80419+++ b/include/linux/compiler.h
80420@@ -5,11 +5,14 @@
80421
80422 #ifdef __CHECKER__
80423 # define __user __attribute__((noderef, address_space(1)))
80424+# define __force_user __force __user
80425 # define __kernel __attribute__((address_space(0)))
80426+# define __force_kernel __force __kernel
80427 # define __safe __attribute__((safe))
80428 # define __force __attribute__((force))
80429 # define __nocast __attribute__((nocast))
80430 # define __iomem __attribute__((noderef, address_space(2)))
80431+# define __force_iomem __force __iomem
80432 # define __must_hold(x) __attribute__((context(x,1,1)))
80433 # define __acquires(x) __attribute__((context(x,0,1)))
80434 # define __releases(x) __attribute__((context(x,1,0)))
80435@@ -17,20 +20,37 @@
80436 # define __release(x) __context__(x,-1)
80437 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
80438 # define __percpu __attribute__((noderef, address_space(3)))
80439+# define __force_percpu __force __percpu
80440 #ifdef CONFIG_SPARSE_RCU_POINTER
80441 # define __rcu __attribute__((noderef, address_space(4)))
80442+# define __force_rcu __force __rcu
80443 #else
80444 # define __rcu
80445+# define __force_rcu
80446 #endif
80447 extern void __chk_user_ptr(const volatile void __user *);
80448 extern void __chk_io_ptr(const volatile void __iomem *);
80449 #else
80450-# define __user
80451-# define __kernel
80452+# ifdef CHECKER_PLUGIN
80453+//# define __user
80454+//# define __force_user
80455+//# define __kernel
80456+//# define __force_kernel
80457+# else
80458+# ifdef STRUCTLEAK_PLUGIN
80459+# define __user __attribute__((user))
80460+# else
80461+# define __user
80462+# endif
80463+# define __force_user
80464+# define __kernel
80465+# define __force_kernel
80466+# endif
80467 # define __safe
80468 # define __force
80469 # define __nocast
80470 # define __iomem
80471+# define __force_iomem
80472 # define __chk_user_ptr(x) (void)0
80473 # define __chk_io_ptr(x) (void)0
80474 # define __builtin_warning(x, y...) (1)
80475@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
80476 # define __release(x) (void)0
80477 # define __cond_lock(x,c) (c)
80478 # define __percpu
80479+# define __force_percpu
80480 # define __rcu
80481+# define __force_rcu
80482 #endif
80483
80484 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
80485@@ -286,6 +308,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80486 # define __attribute_const__ /* unimplemented */
80487 #endif
80488
80489+#ifndef __randomize_layout
80490+# define __randomize_layout
80491+#endif
80492+
80493+#ifndef __no_randomize_layout
80494+# define __no_randomize_layout
80495+#endif
80496+
80497+#ifndef __no_const
80498+# define __no_const
80499+#endif
80500+
80501+#ifndef __do_const
80502+# define __do_const
80503+#endif
80504+
80505+#ifndef __size_overflow
80506+# define __size_overflow(...)
80507+#endif
80508+
80509+#ifndef __intentional_overflow
80510+# define __intentional_overflow(...)
80511+#endif
80512+
80513+#ifndef __latent_entropy
80514+# define __latent_entropy
80515+#endif
80516+
80517 /*
80518 * Tell gcc if a function is cold. The compiler will assume any path
80519 * directly leading to the call is unlikely.
80520@@ -295,6 +345,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80521 #define __cold
80522 #endif
80523
80524+#ifndef __alloc_size
80525+#define __alloc_size(...)
80526+#endif
80527+
80528+#ifndef __bos
80529+#define __bos(ptr, arg)
80530+#endif
80531+
80532+#ifndef __bos0
80533+#define __bos0(ptr)
80534+#endif
80535+
80536+#ifndef __bos1
80537+#define __bos1(ptr)
80538+#endif
80539+
80540 /* Simple shorthand for a section definition */
80541 #ifndef __section
80542 # define __section(S) __attribute__ ((__section__(#S)))
80543@@ -378,7 +444,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80544 * use is to mediate communication between process-level code and irq/NMI
80545 * handlers, all running on the same CPU.
80546 */
80547-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
80548+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
80549+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
80550
80551 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
80552 #ifdef CONFIG_KPROBES
80553diff --git a/include/linux/completion.h b/include/linux/completion.h
80554index 5d5aaae..0ea9b84 100644
80555--- a/include/linux/completion.h
80556+++ b/include/linux/completion.h
80557@@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
80558
80559 extern void wait_for_completion(struct completion *);
80560 extern void wait_for_completion_io(struct completion *);
80561-extern int wait_for_completion_interruptible(struct completion *x);
80562-extern int wait_for_completion_killable(struct completion *x);
80563+extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
80564+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
80565 extern unsigned long wait_for_completion_timeout(struct completion *x,
80566- unsigned long timeout);
80567+ unsigned long timeout) __intentional_overflow(-1);
80568 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
80569- unsigned long timeout);
80570+ unsigned long timeout) __intentional_overflow(-1);
80571 extern long wait_for_completion_interruptible_timeout(
80572- struct completion *x, unsigned long timeout);
80573+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
80574 extern long wait_for_completion_killable_timeout(
80575- struct completion *x, unsigned long timeout);
80576+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
80577 extern bool try_wait_for_completion(struct completion *x);
80578 extern bool completion_done(struct completion *x);
80579
80580diff --git a/include/linux/configfs.h b/include/linux/configfs.h
80581index 34025df..d94bbbc 100644
80582--- a/include/linux/configfs.h
80583+++ b/include/linux/configfs.h
80584@@ -125,7 +125,7 @@ struct configfs_attribute {
80585 const char *ca_name;
80586 struct module *ca_owner;
80587 umode_t ca_mode;
80588-};
80589+} __do_const;
80590
80591 /*
80592 * Users often need to create attribute structures for their configurable
80593diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
80594index 503b085b..1638c9e 100644
80595--- a/include/linux/cpufreq.h
80596+++ b/include/linux/cpufreq.h
80597@@ -206,6 +206,7 @@ struct global_attr {
80598 ssize_t (*store)(struct kobject *a, struct attribute *b,
80599 const char *c, size_t count);
80600 };
80601+typedef struct global_attr __no_const global_attr_no_const;
80602
80603 #define define_one_global_ro(_name) \
80604 static struct global_attr _name = \
80605@@ -273,7 +274,7 @@ struct cpufreq_driver {
80606 bool boost_supported;
80607 bool boost_enabled;
80608 int (*set_boost) (int state);
80609-};
80610+} __do_const;
80611
80612 /* flags */
80613 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
80614diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
80615index 25e0df6..952dffd 100644
80616--- a/include/linux/cpuidle.h
80617+++ b/include/linux/cpuidle.h
80618@@ -50,7 +50,8 @@ struct cpuidle_state {
80619 int index);
80620
80621 int (*enter_dead) (struct cpuidle_device *dev, int index);
80622-};
80623+} __do_const;
80624+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
80625
80626 /* Idle State Flags */
80627 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
80628@@ -209,7 +210,7 @@ struct cpuidle_governor {
80629 void (*reflect) (struct cpuidle_device *dev, int index);
80630
80631 struct module *owner;
80632-};
80633+} __do_const;
80634
80635 #ifdef CONFIG_CPU_IDLE
80636 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
80637diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
80638index 0a9a6da..ea597ca 100644
80639--- a/include/linux/cpumask.h
80640+++ b/include/linux/cpumask.h
80641@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
80642 }
80643
80644 /* Valid inputs for n are -1 and 0. */
80645-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80646+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
80647 {
80648 return n+1;
80649 }
80650
80651-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80652+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
80653 {
80654 return n+1;
80655 }
80656
80657-static inline unsigned int cpumask_next_and(int n,
80658+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
80659 const struct cpumask *srcp,
80660 const struct cpumask *andp)
80661 {
80662@@ -174,7 +174,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
80663 *
80664 * Returns >= nr_cpu_ids if no further cpus set.
80665 */
80666-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80667+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
80668 {
80669 /* -1 is a legal arg here. */
80670 if (n != -1)
80671@@ -189,7 +189,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80672 *
80673 * Returns >= nr_cpu_ids if no further cpus unset.
80674 */
80675-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80676+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
80677 {
80678 /* -1 is a legal arg here. */
80679 if (n != -1)
80680@@ -197,7 +197,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80681 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
80682 }
80683
80684-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
80685+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
80686 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
80687 int cpumask_set_cpu_local_first(int i, int numa_node, cpumask_t *dstp);
80688
80689diff --git a/include/linux/cred.h b/include/linux/cred.h
80690index b2d0820..2ecafd3 100644
80691--- a/include/linux/cred.h
80692+++ b/include/linux/cred.h
80693@@ -35,7 +35,7 @@ struct group_info {
80694 int nblocks;
80695 kgid_t small_block[NGROUPS_SMALL];
80696 kgid_t *blocks[0];
80697-};
80698+} __randomize_layout;
80699
80700 /**
80701 * get_group_info - Get a reference to a group info structure
80702@@ -136,7 +136,7 @@ struct cred {
80703 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
80704 struct group_info *group_info; /* supplementary groups for euid/fsgid */
80705 struct rcu_head rcu; /* RCU deletion hook */
80706-};
80707+} __randomize_layout;
80708
80709 extern void __put_cred(struct cred *);
80710 extern void exit_creds(struct task_struct *);
80711@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
80712 static inline void validate_process_creds(void)
80713 {
80714 }
80715+static inline void validate_task_creds(struct task_struct *task)
80716+{
80717+}
80718 #endif
80719
80720 /**
80721@@ -331,6 +334,7 @@ static inline void put_cred(const struct cred *_cred)
80722
80723 #define task_uid(task) (task_cred_xxx((task), uid))
80724 #define task_euid(task) (task_cred_xxx((task), euid))
80725+#define task_securebits(task) (task_cred_xxx((task), securebits))
80726
80727 #define current_cred_xxx(xxx) \
80728 ({ \
80729diff --git a/include/linux/crypto.h b/include/linux/crypto.h
80730index d45e949..51cf5ea 100644
80731--- a/include/linux/crypto.h
80732+++ b/include/linux/crypto.h
80733@@ -373,7 +373,7 @@ struct cipher_tfm {
80734 const u8 *key, unsigned int keylen);
80735 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
80736 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
80737-};
80738+} __no_const;
80739
80740 struct hash_tfm {
80741 int (*init)(struct hash_desc *desc);
80742@@ -394,13 +394,13 @@ struct compress_tfm {
80743 int (*cot_decompress)(struct crypto_tfm *tfm,
80744 const u8 *src, unsigned int slen,
80745 u8 *dst, unsigned int *dlen);
80746-};
80747+} __no_const;
80748
80749 struct rng_tfm {
80750 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
80751 unsigned int dlen);
80752 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
80753-};
80754+} __no_const;
80755
80756 #define crt_ablkcipher crt_u.ablkcipher
80757 #define crt_aead crt_u.aead
80758diff --git a/include/linux/ctype.h b/include/linux/ctype.h
80759index 653589e..4ef254a 100644
80760--- a/include/linux/ctype.h
80761+++ b/include/linux/ctype.h
80762@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
80763 * Fast implementation of tolower() for internal usage. Do not use in your
80764 * code.
80765 */
80766-static inline char _tolower(const char c)
80767+static inline unsigned char _tolower(const unsigned char c)
80768 {
80769 return c | 0x20;
80770 }
80771diff --git a/include/linux/dcache.h b/include/linux/dcache.h
80772index 1c2f1b8..c67151e 100644
80773--- a/include/linux/dcache.h
80774+++ b/include/linux/dcache.h
80775@@ -133,7 +133,7 @@ struct dentry {
80776 struct hlist_node d_alias; /* inode alias list */
80777 struct rcu_head d_rcu;
80778 } d_u;
80779-};
80780+} __randomize_layout;
80781
80782 /*
80783 * dentry->d_lock spinlock nesting subclasses:
80784diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
80785index 7925bf0..d5143d2 100644
80786--- a/include/linux/decompress/mm.h
80787+++ b/include/linux/decompress/mm.h
80788@@ -77,7 +77,7 @@ static void free(void *where)
80789 * warnings when not needed (indeed large_malloc / large_free are not
80790 * needed by inflate */
80791
80792-#define malloc(a) kmalloc(a, GFP_KERNEL)
80793+#define malloc(a) kmalloc((a), GFP_KERNEL)
80794 #define free(a) kfree(a)
80795
80796 #define large_malloc(a) vmalloc(a)
80797diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
80798index f1863dc..5c26074 100644
80799--- a/include/linux/devfreq.h
80800+++ b/include/linux/devfreq.h
80801@@ -114,7 +114,7 @@ struct devfreq_governor {
80802 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
80803 int (*event_handler)(struct devfreq *devfreq,
80804 unsigned int event, void *data);
80805-};
80806+} __do_const;
80807
80808 /**
80809 * struct devfreq - Device devfreq structure
80810diff --git a/include/linux/device.h b/include/linux/device.h
80811index ce1f2160..189bc33 100644
80812--- a/include/linux/device.h
80813+++ b/include/linux/device.h
80814@@ -311,7 +311,7 @@ struct subsys_interface {
80815 struct list_head node;
80816 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
80817 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
80818-};
80819+} __do_const;
80820
80821 int subsys_interface_register(struct subsys_interface *sif);
80822 void subsys_interface_unregister(struct subsys_interface *sif);
80823@@ -507,7 +507,7 @@ struct device_type {
80824 void (*release)(struct device *dev);
80825
80826 const struct dev_pm_ops *pm;
80827-};
80828+} __do_const;
80829
80830 /* interface for exporting device attributes */
80831 struct device_attribute {
80832@@ -517,11 +517,12 @@ struct device_attribute {
80833 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
80834 const char *buf, size_t count);
80835 };
80836+typedef struct device_attribute __no_const device_attribute_no_const;
80837
80838 struct dev_ext_attribute {
80839 struct device_attribute attr;
80840 void *var;
80841-};
80842+} __do_const;
80843
80844 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
80845 char *buf);
80846diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
80847index d5d3881..7ed54af 100644
80848--- a/include/linux/dma-mapping.h
80849+++ b/include/linux/dma-mapping.h
80850@@ -60,7 +60,7 @@ struct dma_map_ops {
80851 u64 (*get_required_mask)(struct device *dev);
80852 #endif
80853 int is_phys;
80854-};
80855+} __do_const;
80856
80857 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
80858
80859diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
80860index 653a1fd..9133cd1 100644
80861--- a/include/linux/dmaengine.h
80862+++ b/include/linux/dmaengine.h
80863@@ -1136,9 +1136,9 @@ struct dma_pinned_list {
80864 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
80865 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
80866
80867-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
80868+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
80869 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
80870-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
80871+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
80872 struct dma_pinned_list *pinned_list, struct page *page,
80873 unsigned int offset, size_t len);
80874
80875diff --git a/include/linux/efi.h b/include/linux/efi.h
80876index 0949f9c..04cb9a5 100644
80877--- a/include/linux/efi.h
80878+++ b/include/linux/efi.h
80879@@ -1050,6 +1050,7 @@ struct efivar_operations {
80880 efi_set_variable_nonblocking_t *set_variable_nonblocking;
80881 efi_query_variable_store_t *query_variable_store;
80882 };
80883+typedef struct efivar_operations __no_const efivar_operations_no_const;
80884
80885 struct efivars {
80886 /*
80887diff --git a/include/linux/elf.h b/include/linux/elf.h
80888index 67a5fa7..b817372 100644
80889--- a/include/linux/elf.h
80890+++ b/include/linux/elf.h
80891@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
80892 #define elf_note elf32_note
80893 #define elf_addr_t Elf32_Off
80894 #define Elf_Half Elf32_Half
80895+#define elf_dyn Elf32_Dyn
80896
80897 #else
80898
80899@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
80900 #define elf_note elf64_note
80901 #define elf_addr_t Elf64_Off
80902 #define Elf_Half Elf64_Half
80903+#define elf_dyn Elf64_Dyn
80904
80905 #endif
80906
80907diff --git a/include/linux/err.h b/include/linux/err.h
80908index a729120..6ede2c9 100644
80909--- a/include/linux/err.h
80910+++ b/include/linux/err.h
80911@@ -20,12 +20,12 @@
80912
80913 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
80914
80915-static inline void * __must_check ERR_PTR(long error)
80916+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
80917 {
80918 return (void *) error;
80919 }
80920
80921-static inline long __must_check PTR_ERR(__force const void *ptr)
80922+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
80923 {
80924 return (long) ptr;
80925 }
80926diff --git a/include/linux/extcon.h b/include/linux/extcon.h
80927index 36f49c4..a2a1f4c 100644
80928--- a/include/linux/extcon.h
80929+++ b/include/linux/extcon.h
80930@@ -135,7 +135,7 @@ struct extcon_dev {
80931 /* /sys/class/extcon/.../mutually_exclusive/... */
80932 struct attribute_group attr_g_muex;
80933 struct attribute **attrs_muex;
80934- struct device_attribute *d_attrs_muex;
80935+ device_attribute_no_const *d_attrs_muex;
80936 };
80937
80938 /**
80939diff --git a/include/linux/fb.h b/include/linux/fb.h
80940index 09bb7a1..d98870a 100644
80941--- a/include/linux/fb.h
80942+++ b/include/linux/fb.h
80943@@ -305,7 +305,7 @@ struct fb_ops {
80944 /* called at KDB enter and leave time to prepare the console */
80945 int (*fb_debug_enter)(struct fb_info *info);
80946 int (*fb_debug_leave)(struct fb_info *info);
80947-};
80948+} __do_const;
80949
80950 #ifdef CONFIG_FB_TILEBLITTING
80951 #define FB_TILE_CURSOR_NONE 0
80952diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
80953index 230f87b..1fd0485 100644
80954--- a/include/linux/fdtable.h
80955+++ b/include/linux/fdtable.h
80956@@ -100,7 +100,7 @@ struct files_struct *get_files_struct(struct task_struct *);
80957 void put_files_struct(struct files_struct *fs);
80958 void reset_files_struct(struct files_struct *);
80959 int unshare_files(struct files_struct **);
80960-struct files_struct *dup_fd(struct files_struct *, int *);
80961+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
80962 void do_close_on_exec(struct files_struct *);
80963 int iterate_fd(struct files_struct *, unsigned,
80964 int (*)(const void *, struct file *, unsigned),
80965diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
80966index 8293262..2b3b8bd 100644
80967--- a/include/linux/frontswap.h
80968+++ b/include/linux/frontswap.h
80969@@ -11,7 +11,7 @@ struct frontswap_ops {
80970 int (*load)(unsigned, pgoff_t, struct page *);
80971 void (*invalidate_page)(unsigned, pgoff_t);
80972 void (*invalidate_area)(unsigned);
80973-};
80974+} __no_const;
80975
80976 extern bool frontswap_enabled;
80977 extern struct frontswap_ops *
80978diff --git a/include/linux/fs.h b/include/linux/fs.h
80979index 9ab779e..0c636f2 100644
80980--- a/include/linux/fs.h
80981+++ b/include/linux/fs.h
80982@@ -412,7 +412,7 @@ struct address_space {
80983 spinlock_t private_lock; /* for use by the address_space */
80984 struct list_head private_list; /* ditto */
80985 void *private_data; /* ditto */
80986-} __attribute__((aligned(sizeof(long))));
80987+} __attribute__((aligned(sizeof(long)))) __randomize_layout;
80988 /*
80989 * On most architectures that alignment is already the case; but
80990 * must be enforced here for CRIS, to let the least significant bit
80991@@ -455,7 +455,7 @@ struct block_device {
80992 int bd_fsfreeze_count;
80993 /* Mutex for freeze */
80994 struct mutex bd_fsfreeze_mutex;
80995-};
80996+} __randomize_layout;
80997
80998 /*
80999 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
81000@@ -624,7 +624,7 @@ struct inode {
81001 #endif
81002
81003 void *i_private; /* fs or device private pointer */
81004-};
81005+} __randomize_layout;
81006
81007 static inline int inode_unhashed(struct inode *inode)
81008 {
81009@@ -820,7 +820,7 @@ struct file {
81010 struct list_head f_tfile_llink;
81011 #endif /* #ifdef CONFIG_EPOLL */
81012 struct address_space *f_mapping;
81013-} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
81014+} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
81015
81016 struct file_handle {
81017 __u32 handle_bytes;
81018@@ -945,7 +945,7 @@ struct file_lock {
81019 int state; /* state of grant or error if -ve */
81020 } afs;
81021 } fl_u;
81022-};
81023+} __randomize_layout;
81024
81025 /* The following constant reflects the upper bound of the file/locking space */
81026 #ifndef OFFSET_MAX
81027@@ -1287,7 +1287,7 @@ struct super_block {
81028 * Indicates how deep in a filesystem stack this SB is
81029 */
81030 int s_stack_depth;
81031-};
81032+} __randomize_layout;
81033
81034 extern struct timespec current_fs_time(struct super_block *sb);
81035
81036@@ -1514,7 +1514,8 @@ struct file_operations {
81037 long (*fallocate)(struct file *file, int mode, loff_t offset,
81038 loff_t len);
81039 int (*show_fdinfo)(struct seq_file *m, struct file *f);
81040-};
81041+} __do_const __randomize_layout;
81042+typedef struct file_operations __no_const file_operations_no_const;
81043
81044 struct inode_operations {
81045 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
81046@@ -2823,4 +2824,14 @@ static inline bool dir_relax(struct inode *inode)
81047 return !IS_DEADDIR(inode);
81048 }
81049
81050+static inline bool is_sidechannel_device(const struct inode *inode)
81051+{
81052+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
81053+ umode_t mode = inode->i_mode;
81054+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
81055+#else
81056+ return false;
81057+#endif
81058+}
81059+
81060 #endif /* _LINUX_FS_H */
81061diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
81062index 0efc3e6..fd23610 100644
81063--- a/include/linux/fs_struct.h
81064+++ b/include/linux/fs_struct.h
81065@@ -6,13 +6,13 @@
81066 #include <linux/seqlock.h>
81067
81068 struct fs_struct {
81069- int users;
81070+ atomic_t users;
81071 spinlock_t lock;
81072 seqcount_t seq;
81073 int umask;
81074 int in_exec;
81075 struct path root, pwd;
81076-};
81077+} __randomize_layout;
81078
81079 extern struct kmem_cache *fs_cachep;
81080
81081diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
81082index 7714849..a4a5c7a 100644
81083--- a/include/linux/fscache-cache.h
81084+++ b/include/linux/fscache-cache.h
81085@@ -113,7 +113,7 @@ struct fscache_operation {
81086 fscache_operation_release_t release;
81087 };
81088
81089-extern atomic_t fscache_op_debug_id;
81090+extern atomic_unchecked_t fscache_op_debug_id;
81091 extern void fscache_op_work_func(struct work_struct *work);
81092
81093 extern void fscache_enqueue_operation(struct fscache_operation *);
81094@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
81095 INIT_WORK(&op->work, fscache_op_work_func);
81096 atomic_set(&op->usage, 1);
81097 op->state = FSCACHE_OP_ST_INITIALISED;
81098- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
81099+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
81100 op->processor = processor;
81101 op->release = release;
81102 INIT_LIST_HEAD(&op->pend_link);
81103diff --git a/include/linux/fscache.h b/include/linux/fscache.h
81104index 115bb81..e7b812b 100644
81105--- a/include/linux/fscache.h
81106+++ b/include/linux/fscache.h
81107@@ -152,7 +152,7 @@ struct fscache_cookie_def {
81108 * - this is mandatory for any object that may have data
81109 */
81110 void (*now_uncached)(void *cookie_netfs_data);
81111-};
81112+} __do_const;
81113
81114 /*
81115 * fscache cached network filesystem type
81116diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
81117index 1c804b0..1432c2b 100644
81118--- a/include/linux/fsnotify.h
81119+++ b/include/linux/fsnotify.h
81120@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
81121 struct inode *inode = file_inode(file);
81122 __u32 mask = FS_ACCESS;
81123
81124+ if (is_sidechannel_device(inode))
81125+ return;
81126+
81127 if (S_ISDIR(inode->i_mode))
81128 mask |= FS_ISDIR;
81129
81130@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
81131 struct inode *inode = file_inode(file);
81132 __u32 mask = FS_MODIFY;
81133
81134+ if (is_sidechannel_device(inode))
81135+ return;
81136+
81137 if (S_ISDIR(inode->i_mode))
81138 mask |= FS_ISDIR;
81139
81140@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
81141 */
81142 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
81143 {
81144- return kstrdup(name, GFP_KERNEL);
81145+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
81146 }
81147
81148 /*
81149diff --git a/include/linux/genhd.h b/include/linux/genhd.h
81150index ec274e0..e678159 100644
81151--- a/include/linux/genhd.h
81152+++ b/include/linux/genhd.h
81153@@ -194,7 +194,7 @@ struct gendisk {
81154 struct kobject *slave_dir;
81155
81156 struct timer_rand_state *random;
81157- atomic_t sync_io; /* RAID */
81158+ atomic_unchecked_t sync_io; /* RAID */
81159 struct disk_events *ev;
81160 #ifdef CONFIG_BLK_DEV_INTEGRITY
81161 struct blk_integrity *integrity;
81162@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
81163 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
81164
81165 /* drivers/char/random.c */
81166-extern void add_disk_randomness(struct gendisk *disk);
81167+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
81168 extern void rand_initialize_disk(struct gendisk *disk);
81169
81170 static inline sector_t get_start_sect(struct block_device *bdev)
81171diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
81172index 667c311..abac2a7 100644
81173--- a/include/linux/genl_magic_func.h
81174+++ b/include/linux/genl_magic_func.h
81175@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
81176 },
81177
81178 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
81179-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
81180+static struct genl_ops ZZZ_genl_ops[] = {
81181 #include GENL_MAGIC_INCLUDE_FILE
81182 };
81183
81184diff --git a/include/linux/gfp.h b/include/linux/gfp.h
81185index 41b30fd..a3718cf 100644
81186--- a/include/linux/gfp.h
81187+++ b/include/linux/gfp.h
81188@@ -34,6 +34,13 @@ struct vm_area_struct;
81189 #define ___GFP_NO_KSWAPD 0x400000u
81190 #define ___GFP_OTHER_NODE 0x800000u
81191 #define ___GFP_WRITE 0x1000000u
81192+
81193+#ifdef CONFIG_PAX_USERCOPY_SLABS
81194+#define ___GFP_USERCOPY 0x2000000u
81195+#else
81196+#define ___GFP_USERCOPY 0
81197+#endif
81198+
81199 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
81200
81201 /*
81202@@ -90,6 +97,7 @@ struct vm_area_struct;
81203 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
81204 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
81205 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
81206+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
81207
81208 /*
81209 * This may seem redundant, but it's a way of annotating false positives vs.
81210@@ -97,7 +105,7 @@ struct vm_area_struct;
81211 */
81212 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
81213
81214-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
81215+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
81216 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
81217
81218 /* This equals 0, but use constants in case they ever change */
81219@@ -155,6 +163,8 @@ struct vm_area_struct;
81220 /* 4GB DMA on some platforms */
81221 #define GFP_DMA32 __GFP_DMA32
81222
81223+#define GFP_USERCOPY __GFP_USERCOPY
81224+
81225 /* Convert GFP flags to their corresponding migrate type */
81226 static inline int gfpflags_to_migratetype(const gfp_t gfp_flags)
81227 {
81228diff --git a/include/linux/gracl.h b/include/linux/gracl.h
81229new file mode 100644
81230index 0000000..edb2cb6
81231--- /dev/null
81232+++ b/include/linux/gracl.h
81233@@ -0,0 +1,340 @@
81234+#ifndef GR_ACL_H
81235+#define GR_ACL_H
81236+
81237+#include <linux/grdefs.h>
81238+#include <linux/resource.h>
81239+#include <linux/capability.h>
81240+#include <linux/dcache.h>
81241+#include <asm/resource.h>
81242+
81243+/* Major status information */
81244+
81245+#define GR_VERSION "grsecurity 3.0"
81246+#define GRSECURITY_VERSION 0x3000
81247+
81248+enum {
81249+ GR_SHUTDOWN = 0,
81250+ GR_ENABLE = 1,
81251+ GR_SPROLE = 2,
81252+ GR_OLDRELOAD = 3,
81253+ GR_SEGVMOD = 4,
81254+ GR_STATUS = 5,
81255+ GR_UNSPROLE = 6,
81256+ GR_PASSSET = 7,
81257+ GR_SPROLEPAM = 8,
81258+ GR_RELOAD = 9,
81259+};
81260+
81261+/* Password setup definitions
81262+ * kernel/grhash.c */
81263+enum {
81264+ GR_PW_LEN = 128,
81265+ GR_SALT_LEN = 16,
81266+ GR_SHA_LEN = 32,
81267+};
81268+
81269+enum {
81270+ GR_SPROLE_LEN = 64,
81271+};
81272+
81273+enum {
81274+ GR_NO_GLOB = 0,
81275+ GR_REG_GLOB,
81276+ GR_CREATE_GLOB
81277+};
81278+
81279+#define GR_NLIMITS 32
81280+
81281+/* Begin Data Structures */
81282+
81283+struct sprole_pw {
81284+ unsigned char *rolename;
81285+ unsigned char salt[GR_SALT_LEN];
81286+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
81287+};
81288+
81289+struct name_entry {
81290+ __u32 key;
81291+ ino_t inode;
81292+ dev_t device;
81293+ char *name;
81294+ __u16 len;
81295+ __u8 deleted;
81296+ struct name_entry *prev;
81297+ struct name_entry *next;
81298+};
81299+
81300+struct inodev_entry {
81301+ struct name_entry *nentry;
81302+ struct inodev_entry *prev;
81303+ struct inodev_entry *next;
81304+};
81305+
81306+struct acl_role_db {
81307+ struct acl_role_label **r_hash;
81308+ __u32 r_size;
81309+};
81310+
81311+struct inodev_db {
81312+ struct inodev_entry **i_hash;
81313+ __u32 i_size;
81314+};
81315+
81316+struct name_db {
81317+ struct name_entry **n_hash;
81318+ __u32 n_size;
81319+};
81320+
81321+struct crash_uid {
81322+ uid_t uid;
81323+ unsigned long expires;
81324+};
81325+
81326+struct gr_hash_struct {
81327+ void **table;
81328+ void **nametable;
81329+ void *first;
81330+ __u32 table_size;
81331+ __u32 used_size;
81332+ int type;
81333+};
81334+
81335+/* Userspace Grsecurity ACL data structures */
81336+
81337+struct acl_subject_label {
81338+ char *filename;
81339+ ino_t inode;
81340+ dev_t device;
81341+ __u32 mode;
81342+ kernel_cap_t cap_mask;
81343+ kernel_cap_t cap_lower;
81344+ kernel_cap_t cap_invert_audit;
81345+
81346+ struct rlimit res[GR_NLIMITS];
81347+ __u32 resmask;
81348+
81349+ __u8 user_trans_type;
81350+ __u8 group_trans_type;
81351+ uid_t *user_transitions;
81352+ gid_t *group_transitions;
81353+ __u16 user_trans_num;
81354+ __u16 group_trans_num;
81355+
81356+ __u32 sock_families[2];
81357+ __u32 ip_proto[8];
81358+ __u32 ip_type;
81359+ struct acl_ip_label **ips;
81360+ __u32 ip_num;
81361+ __u32 inaddr_any_override;
81362+
81363+ __u32 crashes;
81364+ unsigned long expires;
81365+
81366+ struct acl_subject_label *parent_subject;
81367+ struct gr_hash_struct *hash;
81368+ struct acl_subject_label *prev;
81369+ struct acl_subject_label *next;
81370+
81371+ struct acl_object_label **obj_hash;
81372+ __u32 obj_hash_size;
81373+ __u16 pax_flags;
81374+};
81375+
81376+struct role_allowed_ip {
81377+ __u32 addr;
81378+ __u32 netmask;
81379+
81380+ struct role_allowed_ip *prev;
81381+ struct role_allowed_ip *next;
81382+};
81383+
81384+struct role_transition {
81385+ char *rolename;
81386+
81387+ struct role_transition *prev;
81388+ struct role_transition *next;
81389+};
81390+
81391+struct acl_role_label {
81392+ char *rolename;
81393+ uid_t uidgid;
81394+ __u16 roletype;
81395+
81396+ __u16 auth_attempts;
81397+ unsigned long expires;
81398+
81399+ struct acl_subject_label *root_label;
81400+ struct gr_hash_struct *hash;
81401+
81402+ struct acl_role_label *prev;
81403+ struct acl_role_label *next;
81404+
81405+ struct role_transition *transitions;
81406+ struct role_allowed_ip *allowed_ips;
81407+ uid_t *domain_children;
81408+ __u16 domain_child_num;
81409+
81410+ umode_t umask;
81411+
81412+ struct acl_subject_label **subj_hash;
81413+ __u32 subj_hash_size;
81414+};
81415+
81416+struct user_acl_role_db {
81417+ struct acl_role_label **r_table;
81418+ __u32 num_pointers; /* Number of allocations to track */
81419+ __u32 num_roles; /* Number of roles */
81420+ __u32 num_domain_children; /* Number of domain children */
81421+ __u32 num_subjects; /* Number of subjects */
81422+ __u32 num_objects; /* Number of objects */
81423+};
81424+
81425+struct acl_object_label {
81426+ char *filename;
81427+ ino_t inode;
81428+ dev_t device;
81429+ __u32 mode;
81430+
81431+ struct acl_subject_label *nested;
81432+ struct acl_object_label *globbed;
81433+
81434+ /* next two structures not used */
81435+
81436+ struct acl_object_label *prev;
81437+ struct acl_object_label *next;
81438+};
81439+
81440+struct acl_ip_label {
81441+ char *iface;
81442+ __u32 addr;
81443+ __u32 netmask;
81444+ __u16 low, high;
81445+ __u8 mode;
81446+ __u32 type;
81447+ __u32 proto[8];
81448+
81449+ /* next two structures not used */
81450+
81451+ struct acl_ip_label *prev;
81452+ struct acl_ip_label *next;
81453+};
81454+
81455+struct gr_arg {
81456+ struct user_acl_role_db role_db;
81457+ unsigned char pw[GR_PW_LEN];
81458+ unsigned char salt[GR_SALT_LEN];
81459+ unsigned char sum[GR_SHA_LEN];
81460+ unsigned char sp_role[GR_SPROLE_LEN];
81461+ struct sprole_pw *sprole_pws;
81462+ dev_t segv_device;
81463+ ino_t segv_inode;
81464+ uid_t segv_uid;
81465+ __u16 num_sprole_pws;
81466+ __u16 mode;
81467+};
81468+
81469+struct gr_arg_wrapper {
81470+ struct gr_arg *arg;
81471+ __u32 version;
81472+ __u32 size;
81473+};
81474+
81475+struct subject_map {
81476+ struct acl_subject_label *user;
81477+ struct acl_subject_label *kernel;
81478+ struct subject_map *prev;
81479+ struct subject_map *next;
81480+};
81481+
81482+struct acl_subj_map_db {
81483+ struct subject_map **s_hash;
81484+ __u32 s_size;
81485+};
81486+
81487+struct gr_policy_state {
81488+ struct sprole_pw **acl_special_roles;
81489+ __u16 num_sprole_pws;
81490+ struct acl_role_label *kernel_role;
81491+ struct acl_role_label *role_list;
81492+ struct acl_role_label *default_role;
81493+ struct acl_role_db acl_role_set;
81494+ struct acl_subj_map_db subj_map_set;
81495+ struct name_db name_set;
81496+ struct inodev_db inodev_set;
81497+};
81498+
81499+struct gr_alloc_state {
81500+ unsigned long alloc_stack_next;
81501+ unsigned long alloc_stack_size;
81502+ void **alloc_stack;
81503+};
81504+
81505+struct gr_reload_state {
81506+ struct gr_policy_state oldpolicy;
81507+ struct gr_alloc_state oldalloc;
81508+ struct gr_policy_state newpolicy;
81509+ struct gr_alloc_state newalloc;
81510+ struct gr_policy_state *oldpolicy_ptr;
81511+ struct gr_alloc_state *oldalloc_ptr;
81512+ unsigned char oldmode;
81513+};
81514+
81515+/* End Data Structures Section */
81516+
81517+/* Hash functions generated by empirical testing by Brad Spengler
81518+ Makes good use of the low bits of the inode. Generally 0-1 times
81519+ in loop for successful match. 0-3 for unsuccessful match.
81520+ Shift/add algorithm with modulus of table size and an XOR*/
81521+
81522+static __inline__ unsigned int
81523+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
81524+{
81525+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
81526+}
81527+
81528+ static __inline__ unsigned int
81529+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
81530+{
81531+ return ((const unsigned long)userp % sz);
81532+}
81533+
81534+static __inline__ unsigned int
81535+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
81536+{
81537+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
81538+}
81539+
81540+static __inline__ unsigned int
81541+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
81542+{
81543+ return full_name_hash((const unsigned char *)name, len) % sz;
81544+}
81545+
81546+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
81547+ subj = NULL; \
81548+ iter = 0; \
81549+ while (iter < role->subj_hash_size) { \
81550+ if (subj == NULL) \
81551+ subj = role->subj_hash[iter]; \
81552+ if (subj == NULL) { \
81553+ iter++; \
81554+ continue; \
81555+ }
81556+
81557+#define FOR_EACH_SUBJECT_END(subj,iter) \
81558+ subj = subj->next; \
81559+ if (subj == NULL) \
81560+ iter++; \
81561+ }
81562+
81563+
81564+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
81565+ subj = role->hash->first; \
81566+ while (subj != NULL) {
81567+
81568+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
81569+ subj = subj->next; \
81570+ }
81571+
81572+#endif
81573+
81574diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
81575new file mode 100644
81576index 0000000..33ebd1f
81577--- /dev/null
81578+++ b/include/linux/gracl_compat.h
81579@@ -0,0 +1,156 @@
81580+#ifndef GR_ACL_COMPAT_H
81581+#define GR_ACL_COMPAT_H
81582+
81583+#include <linux/resource.h>
81584+#include <asm/resource.h>
81585+
81586+struct sprole_pw_compat {
81587+ compat_uptr_t rolename;
81588+ unsigned char salt[GR_SALT_LEN];
81589+ unsigned char sum[GR_SHA_LEN];
81590+};
81591+
81592+struct gr_hash_struct_compat {
81593+ compat_uptr_t table;
81594+ compat_uptr_t nametable;
81595+ compat_uptr_t first;
81596+ __u32 table_size;
81597+ __u32 used_size;
81598+ int type;
81599+};
81600+
81601+struct acl_subject_label_compat {
81602+ compat_uptr_t filename;
81603+ compat_ino_t inode;
81604+ __u32 device;
81605+ __u32 mode;
81606+ kernel_cap_t cap_mask;
81607+ kernel_cap_t cap_lower;
81608+ kernel_cap_t cap_invert_audit;
81609+
81610+ struct compat_rlimit res[GR_NLIMITS];
81611+ __u32 resmask;
81612+
81613+ __u8 user_trans_type;
81614+ __u8 group_trans_type;
81615+ compat_uptr_t user_transitions;
81616+ compat_uptr_t group_transitions;
81617+ __u16 user_trans_num;
81618+ __u16 group_trans_num;
81619+
81620+ __u32 sock_families[2];
81621+ __u32 ip_proto[8];
81622+ __u32 ip_type;
81623+ compat_uptr_t ips;
81624+ __u32 ip_num;
81625+ __u32 inaddr_any_override;
81626+
81627+ __u32 crashes;
81628+ compat_ulong_t expires;
81629+
81630+ compat_uptr_t parent_subject;
81631+ compat_uptr_t hash;
81632+ compat_uptr_t prev;
81633+ compat_uptr_t next;
81634+
81635+ compat_uptr_t obj_hash;
81636+ __u32 obj_hash_size;
81637+ __u16 pax_flags;
81638+};
81639+
81640+struct role_allowed_ip_compat {
81641+ __u32 addr;
81642+ __u32 netmask;
81643+
81644+ compat_uptr_t prev;
81645+ compat_uptr_t next;
81646+};
81647+
81648+struct role_transition_compat {
81649+ compat_uptr_t rolename;
81650+
81651+ compat_uptr_t prev;
81652+ compat_uptr_t next;
81653+};
81654+
81655+struct acl_role_label_compat {
81656+ compat_uptr_t rolename;
81657+ uid_t uidgid;
81658+ __u16 roletype;
81659+
81660+ __u16 auth_attempts;
81661+ compat_ulong_t expires;
81662+
81663+ compat_uptr_t root_label;
81664+ compat_uptr_t hash;
81665+
81666+ compat_uptr_t prev;
81667+ compat_uptr_t next;
81668+
81669+ compat_uptr_t transitions;
81670+ compat_uptr_t allowed_ips;
81671+ compat_uptr_t domain_children;
81672+ __u16 domain_child_num;
81673+
81674+ umode_t umask;
81675+
81676+ compat_uptr_t subj_hash;
81677+ __u32 subj_hash_size;
81678+};
81679+
81680+struct user_acl_role_db_compat {
81681+ compat_uptr_t r_table;
81682+ __u32 num_pointers;
81683+ __u32 num_roles;
81684+ __u32 num_domain_children;
81685+ __u32 num_subjects;
81686+ __u32 num_objects;
81687+};
81688+
81689+struct acl_object_label_compat {
81690+ compat_uptr_t filename;
81691+ compat_ino_t inode;
81692+ __u32 device;
81693+ __u32 mode;
81694+
81695+ compat_uptr_t nested;
81696+ compat_uptr_t globbed;
81697+
81698+ compat_uptr_t prev;
81699+ compat_uptr_t next;
81700+};
81701+
81702+struct acl_ip_label_compat {
81703+ compat_uptr_t iface;
81704+ __u32 addr;
81705+ __u32 netmask;
81706+ __u16 low, high;
81707+ __u8 mode;
81708+ __u32 type;
81709+ __u32 proto[8];
81710+
81711+ compat_uptr_t prev;
81712+ compat_uptr_t next;
81713+};
81714+
81715+struct gr_arg_compat {
81716+ struct user_acl_role_db_compat role_db;
81717+ unsigned char pw[GR_PW_LEN];
81718+ unsigned char salt[GR_SALT_LEN];
81719+ unsigned char sum[GR_SHA_LEN];
81720+ unsigned char sp_role[GR_SPROLE_LEN];
81721+ compat_uptr_t sprole_pws;
81722+ __u32 segv_device;
81723+ compat_ino_t segv_inode;
81724+ uid_t segv_uid;
81725+ __u16 num_sprole_pws;
81726+ __u16 mode;
81727+};
81728+
81729+struct gr_arg_wrapper_compat {
81730+ compat_uptr_t arg;
81731+ __u32 version;
81732+ __u32 size;
81733+};
81734+
81735+#endif
81736diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
81737new file mode 100644
81738index 0000000..323ecf2
81739--- /dev/null
81740+++ b/include/linux/gralloc.h
81741@@ -0,0 +1,9 @@
81742+#ifndef __GRALLOC_H
81743+#define __GRALLOC_H
81744+
81745+void acl_free_all(void);
81746+int acl_alloc_stack_init(unsigned long size);
81747+void *acl_alloc(unsigned long len);
81748+void *acl_alloc_num(unsigned long num, unsigned long len);
81749+
81750+#endif
81751diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
81752new file mode 100644
81753index 0000000..be66033
81754--- /dev/null
81755+++ b/include/linux/grdefs.h
81756@@ -0,0 +1,140 @@
81757+#ifndef GRDEFS_H
81758+#define GRDEFS_H
81759+
81760+/* Begin grsecurity status declarations */
81761+
81762+enum {
81763+ GR_READY = 0x01,
81764+ GR_STATUS_INIT = 0x00 // disabled state
81765+};
81766+
81767+/* Begin ACL declarations */
81768+
81769+/* Role flags */
81770+
81771+enum {
81772+ GR_ROLE_USER = 0x0001,
81773+ GR_ROLE_GROUP = 0x0002,
81774+ GR_ROLE_DEFAULT = 0x0004,
81775+ GR_ROLE_SPECIAL = 0x0008,
81776+ GR_ROLE_AUTH = 0x0010,
81777+ GR_ROLE_NOPW = 0x0020,
81778+ GR_ROLE_GOD = 0x0040,
81779+ GR_ROLE_LEARN = 0x0080,
81780+ GR_ROLE_TPE = 0x0100,
81781+ GR_ROLE_DOMAIN = 0x0200,
81782+ GR_ROLE_PAM = 0x0400,
81783+ GR_ROLE_PERSIST = 0x0800
81784+};
81785+
81786+/* ACL Subject and Object mode flags */
81787+enum {
81788+ GR_DELETED = 0x80000000
81789+};
81790+
81791+/* ACL Object-only mode flags */
81792+enum {
81793+ GR_READ = 0x00000001,
81794+ GR_APPEND = 0x00000002,
81795+ GR_WRITE = 0x00000004,
81796+ GR_EXEC = 0x00000008,
81797+ GR_FIND = 0x00000010,
81798+ GR_INHERIT = 0x00000020,
81799+ GR_SETID = 0x00000040,
81800+ GR_CREATE = 0x00000080,
81801+ GR_DELETE = 0x00000100,
81802+ GR_LINK = 0x00000200,
81803+ GR_AUDIT_READ = 0x00000400,
81804+ GR_AUDIT_APPEND = 0x00000800,
81805+ GR_AUDIT_WRITE = 0x00001000,
81806+ GR_AUDIT_EXEC = 0x00002000,
81807+ GR_AUDIT_FIND = 0x00004000,
81808+ GR_AUDIT_INHERIT= 0x00008000,
81809+ GR_AUDIT_SETID = 0x00010000,
81810+ GR_AUDIT_CREATE = 0x00020000,
81811+ GR_AUDIT_DELETE = 0x00040000,
81812+ GR_AUDIT_LINK = 0x00080000,
81813+ GR_PTRACERD = 0x00100000,
81814+ GR_NOPTRACE = 0x00200000,
81815+ GR_SUPPRESS = 0x00400000,
81816+ GR_NOLEARN = 0x00800000,
81817+ GR_INIT_TRANSFER= 0x01000000
81818+};
81819+
81820+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
81821+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
81822+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
81823+
81824+/* ACL subject-only mode flags */
81825+enum {
81826+ GR_KILL = 0x00000001,
81827+ GR_VIEW = 0x00000002,
81828+ GR_PROTECTED = 0x00000004,
81829+ GR_LEARN = 0x00000008,
81830+ GR_OVERRIDE = 0x00000010,
81831+ /* just a placeholder, this mode is only used in userspace */
81832+ GR_DUMMY = 0x00000020,
81833+ GR_PROTSHM = 0x00000040,
81834+ GR_KILLPROC = 0x00000080,
81835+ GR_KILLIPPROC = 0x00000100,
81836+ /* just a placeholder, this mode is only used in userspace */
81837+ GR_NOTROJAN = 0x00000200,
81838+ GR_PROTPROCFD = 0x00000400,
81839+ GR_PROCACCT = 0x00000800,
81840+ GR_RELAXPTRACE = 0x00001000,
81841+ //GR_NESTED = 0x00002000,
81842+ GR_INHERITLEARN = 0x00004000,
81843+ GR_PROCFIND = 0x00008000,
81844+ GR_POVERRIDE = 0x00010000,
81845+ GR_KERNELAUTH = 0x00020000,
81846+ GR_ATSECURE = 0x00040000,
81847+ GR_SHMEXEC = 0x00080000
81848+};
81849+
81850+enum {
81851+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
81852+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
81853+ GR_PAX_ENABLE_MPROTECT = 0x0004,
81854+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
81855+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
81856+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
81857+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
81858+ GR_PAX_DISABLE_MPROTECT = 0x0400,
81859+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
81860+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
81861+};
81862+
81863+enum {
81864+ GR_ID_USER = 0x01,
81865+ GR_ID_GROUP = 0x02,
81866+};
81867+
81868+enum {
81869+ GR_ID_ALLOW = 0x01,
81870+ GR_ID_DENY = 0x02,
81871+};
81872+
81873+#define GR_CRASH_RES 31
81874+#define GR_UIDTABLE_MAX 500
81875+
81876+/* begin resource learning section */
81877+enum {
81878+ GR_RLIM_CPU_BUMP = 60,
81879+ GR_RLIM_FSIZE_BUMP = 50000,
81880+ GR_RLIM_DATA_BUMP = 10000,
81881+ GR_RLIM_STACK_BUMP = 1000,
81882+ GR_RLIM_CORE_BUMP = 10000,
81883+ GR_RLIM_RSS_BUMP = 500000,
81884+ GR_RLIM_NPROC_BUMP = 1,
81885+ GR_RLIM_NOFILE_BUMP = 5,
81886+ GR_RLIM_MEMLOCK_BUMP = 50000,
81887+ GR_RLIM_AS_BUMP = 500000,
81888+ GR_RLIM_LOCKS_BUMP = 2,
81889+ GR_RLIM_SIGPENDING_BUMP = 5,
81890+ GR_RLIM_MSGQUEUE_BUMP = 10000,
81891+ GR_RLIM_NICE_BUMP = 1,
81892+ GR_RLIM_RTPRIO_BUMP = 1,
81893+ GR_RLIM_RTTIME_BUMP = 1000000
81894+};
81895+
81896+#endif
81897diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
81898new file mode 100644
81899index 0000000..d25522e
81900--- /dev/null
81901+++ b/include/linux/grinternal.h
81902@@ -0,0 +1,229 @@
81903+#ifndef __GRINTERNAL_H
81904+#define __GRINTERNAL_H
81905+
81906+#ifdef CONFIG_GRKERNSEC
81907+
81908+#include <linux/fs.h>
81909+#include <linux/mnt_namespace.h>
81910+#include <linux/nsproxy.h>
81911+#include <linux/gracl.h>
81912+#include <linux/grdefs.h>
81913+#include <linux/grmsg.h>
81914+
81915+void gr_add_learn_entry(const char *fmt, ...)
81916+ __attribute__ ((format (printf, 1, 2)));
81917+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
81918+ const struct vfsmount *mnt);
81919+__u32 gr_check_create(const struct dentry *new_dentry,
81920+ const struct dentry *parent,
81921+ const struct vfsmount *mnt, const __u32 mode);
81922+int gr_check_protected_task(const struct task_struct *task);
81923+__u32 to_gr_audit(const __u32 reqmode);
81924+int gr_set_acls(const int type);
81925+int gr_acl_is_enabled(void);
81926+char gr_roletype_to_char(void);
81927+
81928+void gr_handle_alertkill(struct task_struct *task);
81929+char *gr_to_filename(const struct dentry *dentry,
81930+ const struct vfsmount *mnt);
81931+char *gr_to_filename1(const struct dentry *dentry,
81932+ const struct vfsmount *mnt);
81933+char *gr_to_filename2(const struct dentry *dentry,
81934+ const struct vfsmount *mnt);
81935+char *gr_to_filename3(const struct dentry *dentry,
81936+ const struct vfsmount *mnt);
81937+
81938+extern int grsec_enable_ptrace_readexec;
81939+extern int grsec_enable_harden_ptrace;
81940+extern int grsec_enable_link;
81941+extern int grsec_enable_fifo;
81942+extern int grsec_enable_execve;
81943+extern int grsec_enable_shm;
81944+extern int grsec_enable_execlog;
81945+extern int grsec_enable_signal;
81946+extern int grsec_enable_audit_ptrace;
81947+extern int grsec_enable_forkfail;
81948+extern int grsec_enable_time;
81949+extern int grsec_enable_rofs;
81950+extern int grsec_deny_new_usb;
81951+extern int grsec_enable_chroot_shmat;
81952+extern int grsec_enable_chroot_mount;
81953+extern int grsec_enable_chroot_double;
81954+extern int grsec_enable_chroot_pivot;
81955+extern int grsec_enable_chroot_chdir;
81956+extern int grsec_enable_chroot_chmod;
81957+extern int grsec_enable_chroot_mknod;
81958+extern int grsec_enable_chroot_fchdir;
81959+extern int grsec_enable_chroot_nice;
81960+extern int grsec_enable_chroot_execlog;
81961+extern int grsec_enable_chroot_caps;
81962+extern int grsec_enable_chroot_sysctl;
81963+extern int grsec_enable_chroot_unix;
81964+extern int grsec_enable_symlinkown;
81965+extern kgid_t grsec_symlinkown_gid;
81966+extern int grsec_enable_tpe;
81967+extern kgid_t grsec_tpe_gid;
81968+extern int grsec_enable_tpe_all;
81969+extern int grsec_enable_tpe_invert;
81970+extern int grsec_enable_socket_all;
81971+extern kgid_t grsec_socket_all_gid;
81972+extern int grsec_enable_socket_client;
81973+extern kgid_t grsec_socket_client_gid;
81974+extern int grsec_enable_socket_server;
81975+extern kgid_t grsec_socket_server_gid;
81976+extern kgid_t grsec_audit_gid;
81977+extern int grsec_enable_group;
81978+extern int grsec_enable_log_rwxmaps;
81979+extern int grsec_enable_mount;
81980+extern int grsec_enable_chdir;
81981+extern int grsec_resource_logging;
81982+extern int grsec_enable_blackhole;
81983+extern int grsec_lastack_retries;
81984+extern int grsec_enable_brute;
81985+extern int grsec_enable_harden_ipc;
81986+extern int grsec_lock;
81987+
81988+extern spinlock_t grsec_alert_lock;
81989+extern unsigned long grsec_alert_wtime;
81990+extern unsigned long grsec_alert_fyet;
81991+
81992+extern spinlock_t grsec_audit_lock;
81993+
81994+extern rwlock_t grsec_exec_file_lock;
81995+
81996+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
81997+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
81998+ (tsk)->exec_file->f_path.mnt) : "/")
81999+
82000+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
82001+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
82002+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
82003+
82004+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
82005+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
82006+ (tsk)->exec_file->f_path.mnt) : "/")
82007+
82008+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
82009+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
82010+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
82011+
82012+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
82013+
82014+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
82015+
82016+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
82017+{
82018+ if (file1 && file2) {
82019+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
82020+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
82021+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
82022+ return true;
82023+ }
82024+
82025+ return false;
82026+}
82027+
82028+#define GR_CHROOT_CAPS {{ \
82029+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
82030+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
82031+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
82032+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
82033+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
82034+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
82035+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
82036+
82037+#define security_learn(normal_msg,args...) \
82038+({ \
82039+ read_lock(&grsec_exec_file_lock); \
82040+ gr_add_learn_entry(normal_msg "\n", ## args); \
82041+ read_unlock(&grsec_exec_file_lock); \
82042+})
82043+
82044+enum {
82045+ GR_DO_AUDIT,
82046+ GR_DONT_AUDIT,
82047+ /* used for non-audit messages that we shouldn't kill the task on */
82048+ GR_DONT_AUDIT_GOOD
82049+};
82050+
82051+enum {
82052+ GR_TTYSNIFF,
82053+ GR_RBAC,
82054+ GR_RBAC_STR,
82055+ GR_STR_RBAC,
82056+ GR_RBAC_MODE2,
82057+ GR_RBAC_MODE3,
82058+ GR_FILENAME,
82059+ GR_SYSCTL_HIDDEN,
82060+ GR_NOARGS,
82061+ GR_ONE_INT,
82062+ GR_ONE_INT_TWO_STR,
82063+ GR_ONE_STR,
82064+ GR_STR_INT,
82065+ GR_TWO_STR_INT,
82066+ GR_TWO_INT,
82067+ GR_TWO_U64,
82068+ GR_THREE_INT,
82069+ GR_FIVE_INT_TWO_STR,
82070+ GR_TWO_STR,
82071+ GR_THREE_STR,
82072+ GR_FOUR_STR,
82073+ GR_STR_FILENAME,
82074+ GR_FILENAME_STR,
82075+ GR_FILENAME_TWO_INT,
82076+ GR_FILENAME_TWO_INT_STR,
82077+ GR_TEXTREL,
82078+ GR_PTRACE,
82079+ GR_RESOURCE,
82080+ GR_CAP,
82081+ GR_SIG,
82082+ GR_SIG2,
82083+ GR_CRASH1,
82084+ GR_CRASH2,
82085+ GR_PSACCT,
82086+ GR_RWXMAP,
82087+ GR_RWXMAPVMA
82088+};
82089+
82090+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
82091+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
82092+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
82093+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
82094+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
82095+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
82096+#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)
82097+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
82098+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
82099+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
82100+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
82101+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
82102+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
82103+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
82104+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
82105+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
82106+#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)
82107+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
82108+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
82109+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
82110+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
82111+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
82112+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
82113+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
82114+#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)
82115+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
82116+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
82117+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
82118+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
82119+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
82120+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
82121+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
82122+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
82123+#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)
82124+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
82125+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
82126+
82127+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
82128+
82129+#endif
82130+
82131+#endif
82132diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
82133new file mode 100644
82134index 0000000..b02ba9d
82135--- /dev/null
82136+++ b/include/linux/grmsg.h
82137@@ -0,0 +1,117 @@
82138+#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"
82139+#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"
82140+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
82141+#define GR_STOPMOD_MSG "denied modification of module state by "
82142+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
82143+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
82144+#define GR_IOPERM_MSG "denied use of ioperm() by "
82145+#define GR_IOPL_MSG "denied use of iopl() by "
82146+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
82147+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
82148+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
82149+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
82150+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
82151+#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"
82152+#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"
82153+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
82154+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
82155+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
82156+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
82157+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
82158+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
82159+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
82160+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
82161+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
82162+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
82163+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
82164+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
82165+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
82166+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
82167+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
82168+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
82169+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
82170+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
82171+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
82172+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
82173+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
82174+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
82175+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
82176+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
82177+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
82178+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
82179+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
82180+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
82181+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
82182+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
82183+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
82184+#define GR_CHROOT_FHANDLE_MSG "denied use of file handles inside chroot by "
82185+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
82186+#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
82187+#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
82188+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
82189+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
82190+#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"
82191+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
82192+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
82193+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
82194+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
82195+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
82196+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
82197+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
82198+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
82199+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
82200+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
82201+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
82202+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
82203+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
82204+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
82205+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
82206+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
82207+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
82208+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
82209+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
82210+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
82211+#define GR_FAILFORK_MSG "failed fork with errno %s by "
82212+#define GR_NICE_CHROOT_MSG "denied priority change by "
82213+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
82214+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
82215+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
82216+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
82217+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
82218+#define GR_TIME_MSG "time set by "
82219+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
82220+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
82221+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
82222+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
82223+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
82224+#define GR_BIND_MSG "denied bind() by "
82225+#define GR_CONNECT_MSG "denied connect() by "
82226+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
82227+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
82228+#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"
82229+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
82230+#define GR_CAP_ACL_MSG "use of %s denied for "
82231+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
82232+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
82233+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
82234+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
82235+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
82236+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
82237+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
82238+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
82239+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
82240+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
82241+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
82242+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
82243+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
82244+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
82245+#define GR_VM86_MSG "denied use of vm86 by "
82246+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
82247+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
82248+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
82249+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
82250+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
82251+#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 "
82252+#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 "
82253+#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
82254+#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
82255diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
82256new file mode 100644
82257index 0000000..c3b0738
82258--- /dev/null
82259+++ b/include/linux/grsecurity.h
82260@@ -0,0 +1,244 @@
82261+#ifndef GR_SECURITY_H
82262+#define GR_SECURITY_H
82263+#include <linux/fs.h>
82264+#include <linux/fs_struct.h>
82265+#include <linux/binfmts.h>
82266+#include <linux/gracl.h>
82267+
82268+/* notify of brain-dead configs */
82269+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82270+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
82271+#endif
82272+#if defined(CONFIG_GRKERNSEC_PROC) && !defined(CONFIG_GRKERNSEC_PROC_USER) && !defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82273+#error "CONFIG_GRKERNSEC_PROC enabled, but neither CONFIG_GRKERNSEC_PROC_USER nor CONFIG_GRKERNSEC_PROC_USERGROUP enabled"
82274+#endif
82275+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
82276+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
82277+#endif
82278+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
82279+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
82280+#endif
82281+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
82282+#error "CONFIG_PAX enabled, but no PaX options are enabled."
82283+#endif
82284+
82285+int gr_handle_new_usb(void);
82286+
82287+void gr_handle_brute_attach(int dumpable);
82288+void gr_handle_brute_check(void);
82289+void gr_handle_kernel_exploit(void);
82290+
82291+char gr_roletype_to_char(void);
82292+
82293+int gr_proc_is_restricted(void);
82294+
82295+int gr_acl_enable_at_secure(void);
82296+
82297+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
82298+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
82299+
82300+int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap);
82301+
82302+void gr_del_task_from_ip_table(struct task_struct *p);
82303+
82304+int gr_pid_is_chrooted(struct task_struct *p);
82305+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
82306+int gr_handle_chroot_nice(void);
82307+int gr_handle_chroot_sysctl(const int op);
82308+int gr_handle_chroot_setpriority(struct task_struct *p,
82309+ const int niceval);
82310+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
82311+int gr_chroot_fhandle(void);
82312+int gr_handle_chroot_chroot(const struct dentry *dentry,
82313+ const struct vfsmount *mnt);
82314+void gr_handle_chroot_chdir(const struct path *path);
82315+int gr_handle_chroot_chmod(const struct dentry *dentry,
82316+ const struct vfsmount *mnt, const int mode);
82317+int gr_handle_chroot_mknod(const struct dentry *dentry,
82318+ const struct vfsmount *mnt, const int mode);
82319+int gr_handle_chroot_mount(const struct dentry *dentry,
82320+ const struct vfsmount *mnt,
82321+ const char *dev_name);
82322+int gr_handle_chroot_pivot(void);
82323+int gr_handle_chroot_unix(const pid_t pid);
82324+
82325+int gr_handle_rawio(const struct inode *inode);
82326+
82327+void gr_handle_ioperm(void);
82328+void gr_handle_iopl(void);
82329+void gr_handle_msr_write(void);
82330+
82331+umode_t gr_acl_umask(void);
82332+
82333+int gr_tpe_allow(const struct file *file);
82334+
82335+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
82336+void gr_clear_chroot_entries(struct task_struct *task);
82337+
82338+void gr_log_forkfail(const int retval);
82339+void gr_log_timechange(void);
82340+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
82341+void gr_log_chdir(const struct dentry *dentry,
82342+ const struct vfsmount *mnt);
82343+void gr_log_chroot_exec(const struct dentry *dentry,
82344+ const struct vfsmount *mnt);
82345+void gr_log_remount(const char *devname, const int retval);
82346+void gr_log_unmount(const char *devname, const int retval);
82347+void gr_log_mount(const char *from, struct path *to, const int retval);
82348+void gr_log_textrel(struct vm_area_struct *vma);
82349+void gr_log_ptgnustack(struct file *file);
82350+void gr_log_rwxmmap(struct file *file);
82351+void gr_log_rwxmprotect(struct vm_area_struct *vma);
82352+
82353+int gr_handle_follow_link(const struct inode *parent,
82354+ const struct inode *inode,
82355+ const struct dentry *dentry,
82356+ const struct vfsmount *mnt);
82357+int gr_handle_fifo(const struct dentry *dentry,
82358+ const struct vfsmount *mnt,
82359+ const struct dentry *dir, const int flag,
82360+ const int acc_mode);
82361+int gr_handle_hardlink(const struct dentry *dentry,
82362+ const struct vfsmount *mnt,
82363+ struct inode *inode,
82364+ const int mode, const struct filename *to);
82365+
82366+int gr_is_capable(const int cap);
82367+int gr_is_capable_nolog(const int cap);
82368+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
82369+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
82370+
82371+void gr_copy_label(struct task_struct *tsk);
82372+void gr_handle_crash(struct task_struct *task, const int sig);
82373+int gr_handle_signal(const struct task_struct *p, const int sig);
82374+int gr_check_crash_uid(const kuid_t uid);
82375+int gr_check_protected_task(const struct task_struct *task);
82376+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
82377+int gr_acl_handle_mmap(const struct file *file,
82378+ const unsigned long prot);
82379+int gr_acl_handle_mprotect(const struct file *file,
82380+ const unsigned long prot);
82381+int gr_check_hidden_task(const struct task_struct *tsk);
82382+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
82383+ const struct vfsmount *mnt);
82384+__u32 gr_acl_handle_utime(const struct dentry *dentry,
82385+ const struct vfsmount *mnt);
82386+__u32 gr_acl_handle_access(const struct dentry *dentry,
82387+ const struct vfsmount *mnt, const int fmode);
82388+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
82389+ const struct vfsmount *mnt, umode_t *mode);
82390+__u32 gr_acl_handle_chown(const struct dentry *dentry,
82391+ const struct vfsmount *mnt);
82392+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
82393+ const struct vfsmount *mnt);
82394+__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
82395+ const struct vfsmount *mnt);
82396+int gr_handle_ptrace(struct task_struct *task, const long request);
82397+int gr_handle_proc_ptrace(struct task_struct *task);
82398+__u32 gr_acl_handle_execve(const struct dentry *dentry,
82399+ const struct vfsmount *mnt);
82400+int gr_check_crash_exec(const struct file *filp);
82401+int gr_acl_is_enabled(void);
82402+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
82403+ const kgid_t gid);
82404+int gr_set_proc_label(const struct dentry *dentry,
82405+ const struct vfsmount *mnt,
82406+ const int unsafe_flags);
82407+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
82408+ const struct vfsmount *mnt);
82409+__u32 gr_acl_handle_open(const struct dentry *dentry,
82410+ const struct vfsmount *mnt, int acc_mode);
82411+__u32 gr_acl_handle_creat(const struct dentry *dentry,
82412+ const struct dentry *p_dentry,
82413+ const struct vfsmount *p_mnt,
82414+ int open_flags, int acc_mode, const int imode);
82415+void gr_handle_create(const struct dentry *dentry,
82416+ const struct vfsmount *mnt);
82417+void gr_handle_proc_create(const struct dentry *dentry,
82418+ const struct inode *inode);
82419+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
82420+ const struct dentry *parent_dentry,
82421+ const struct vfsmount *parent_mnt,
82422+ const int mode);
82423+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
82424+ const struct dentry *parent_dentry,
82425+ const struct vfsmount *parent_mnt);
82426+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
82427+ const struct vfsmount *mnt);
82428+void gr_handle_delete(const ino_t ino, const dev_t dev);
82429+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
82430+ const struct vfsmount *mnt);
82431+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
82432+ const struct dentry *parent_dentry,
82433+ const struct vfsmount *parent_mnt,
82434+ const struct filename *from);
82435+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
82436+ const struct dentry *parent_dentry,
82437+ const struct vfsmount *parent_mnt,
82438+ const struct dentry *old_dentry,
82439+ const struct vfsmount *old_mnt, const struct filename *to);
82440+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
82441+int gr_acl_handle_rename(struct dentry *new_dentry,
82442+ struct dentry *parent_dentry,
82443+ const struct vfsmount *parent_mnt,
82444+ struct dentry *old_dentry,
82445+ struct inode *old_parent_inode,
82446+ struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags);
82447+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
82448+ struct dentry *old_dentry,
82449+ struct dentry *new_dentry,
82450+ struct vfsmount *mnt, const __u8 replace, unsigned int flags);
82451+__u32 gr_check_link(const struct dentry *new_dentry,
82452+ const struct dentry *parent_dentry,
82453+ const struct vfsmount *parent_mnt,
82454+ const struct dentry *old_dentry,
82455+ const struct vfsmount *old_mnt);
82456+int gr_acl_handle_filldir(const struct file *file, const char *name,
82457+ const unsigned int namelen, const ino_t ino);
82458+
82459+__u32 gr_acl_handle_unix(const struct dentry *dentry,
82460+ const struct vfsmount *mnt);
82461+void gr_acl_handle_exit(void);
82462+void gr_acl_handle_psacct(struct task_struct *task, const long code);
82463+int gr_acl_handle_procpidmem(const struct task_struct *task);
82464+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
82465+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
82466+void gr_audit_ptrace(struct task_struct *task);
82467+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
82468+void gr_put_exec_file(struct task_struct *task);
82469+
82470+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
82471+
82472+#ifdef CONFIG_GRKERNSEC_RESLOG
82473+extern void gr_log_resource(const struct task_struct *task, const int res,
82474+ const unsigned long wanted, const int gt);
82475+#else
82476+static inline void gr_log_resource(const struct task_struct *task, const int res,
82477+ const unsigned long wanted, const int gt)
82478+{
82479+}
82480+#endif
82481+
82482+#ifdef CONFIG_GRKERNSEC
82483+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
82484+void gr_handle_vm86(void);
82485+void gr_handle_mem_readwrite(u64 from, u64 to);
82486+
82487+void gr_log_badprocpid(const char *entry);
82488+
82489+extern int grsec_enable_dmesg;
82490+extern int grsec_disable_privio;
82491+
82492+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
82493+extern kgid_t grsec_proc_gid;
82494+#endif
82495+
82496+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
82497+extern int grsec_enable_chroot_findtask;
82498+#endif
82499+#ifdef CONFIG_GRKERNSEC_SETXID
82500+extern int grsec_enable_setxid;
82501+#endif
82502+#endif
82503+
82504+#endif
82505diff --git a/include/linux/grsock.h b/include/linux/grsock.h
82506new file mode 100644
82507index 0000000..e7ffaaf
82508--- /dev/null
82509+++ b/include/linux/grsock.h
82510@@ -0,0 +1,19 @@
82511+#ifndef __GRSOCK_H
82512+#define __GRSOCK_H
82513+
82514+extern void gr_attach_curr_ip(const struct sock *sk);
82515+extern int gr_handle_sock_all(const int family, const int type,
82516+ const int protocol);
82517+extern int gr_handle_sock_server(const struct sockaddr *sck);
82518+extern int gr_handle_sock_server_other(const struct sock *sck);
82519+extern int gr_handle_sock_client(const struct sockaddr *sck);
82520+extern int gr_search_connect(struct socket * sock,
82521+ struct sockaddr_in * addr);
82522+extern int gr_search_bind(struct socket * sock,
82523+ struct sockaddr_in * addr);
82524+extern int gr_search_listen(struct socket * sock);
82525+extern int gr_search_accept(struct socket * sock);
82526+extern int gr_search_socket(const int domain, const int type,
82527+ const int protocol);
82528+
82529+#endif
82530diff --git a/include/linux/hash.h b/include/linux/hash.h
82531index d0494c3..69b7715 100644
82532--- a/include/linux/hash.h
82533+++ b/include/linux/hash.h
82534@@ -87,7 +87,7 @@ static inline u32 hash32_ptr(const void *ptr)
82535 struct fast_hash_ops {
82536 u32 (*hash)(const void *data, u32 len, u32 seed);
82537 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
82538-};
82539+} __no_const;
82540
82541 /**
82542 * arch_fast_hash - Caclulates a hash over a given buffer that can have
82543diff --git a/include/linux/highmem.h b/include/linux/highmem.h
82544index 9286a46..373f27f 100644
82545--- a/include/linux/highmem.h
82546+++ b/include/linux/highmem.h
82547@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
82548 kunmap_atomic(kaddr);
82549 }
82550
82551+static inline void sanitize_highpage(struct page *page)
82552+{
82553+ void *kaddr;
82554+ unsigned long flags;
82555+
82556+ local_irq_save(flags);
82557+ kaddr = kmap_atomic(page);
82558+ clear_page(kaddr);
82559+ kunmap_atomic(kaddr);
82560+ local_irq_restore(flags);
82561+}
82562+
82563 static inline void zero_user_segments(struct page *page,
82564 unsigned start1, unsigned end1,
82565 unsigned start2, unsigned end2)
82566diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
82567index 1c7b89a..7dda400 100644
82568--- a/include/linux/hwmon-sysfs.h
82569+++ b/include/linux/hwmon-sysfs.h
82570@@ -25,7 +25,8 @@
82571 struct sensor_device_attribute{
82572 struct device_attribute dev_attr;
82573 int index;
82574-};
82575+} __do_const;
82576+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
82577 #define to_sensor_dev_attr(_dev_attr) \
82578 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
82579
82580@@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
82581 struct device_attribute dev_attr;
82582 u8 index;
82583 u8 nr;
82584-};
82585+} __do_const;
82586+typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
82587 #define to_sensor_dev_attr_2(_dev_attr) \
82588 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
82589
82590diff --git a/include/linux/i2c.h b/include/linux/i2c.h
82591index b556e0a..c10a515 100644
82592--- a/include/linux/i2c.h
82593+++ b/include/linux/i2c.h
82594@@ -378,6 +378,7 @@ struct i2c_algorithm {
82595 /* To determine what the adapter supports */
82596 u32 (*functionality) (struct i2c_adapter *);
82597 };
82598+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
82599
82600 /**
82601 * struct i2c_bus_recovery_info - I2C bus recovery information
82602diff --git a/include/linux/i2o.h b/include/linux/i2o.h
82603index d23c3c2..eb63c81 100644
82604--- a/include/linux/i2o.h
82605+++ b/include/linux/i2o.h
82606@@ -565,7 +565,7 @@ struct i2o_controller {
82607 struct i2o_device *exec; /* Executive */
82608 #if BITS_PER_LONG == 64
82609 spinlock_t context_list_lock; /* lock for context_list */
82610- atomic_t context_list_counter; /* needed for unique contexts */
82611+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
82612 struct list_head context_list; /* list of context id's
82613 and pointers */
82614 #endif
82615diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
82616index aff7ad8..3942bbd 100644
82617--- a/include/linux/if_pppox.h
82618+++ b/include/linux/if_pppox.h
82619@@ -76,7 +76,7 @@ struct pppox_proto {
82620 int (*ioctl)(struct socket *sock, unsigned int cmd,
82621 unsigned long arg);
82622 struct module *owner;
82623-};
82624+} __do_const;
82625
82626 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
82627 extern void unregister_pppox_proto(int proto_num);
82628diff --git a/include/linux/init.h b/include/linux/init.h
82629index 2df8e8d..3e1280d 100644
82630--- a/include/linux/init.h
82631+++ b/include/linux/init.h
82632@@ -37,9 +37,17 @@
82633 * section.
82634 */
82635
82636+#define add_init_latent_entropy __latent_entropy
82637+
82638+#ifdef CONFIG_MEMORY_HOTPLUG
82639+#define add_meminit_latent_entropy
82640+#else
82641+#define add_meminit_latent_entropy __latent_entropy
82642+#endif
82643+
82644 /* These are for everybody (although not all archs will actually
82645 discard it in modules) */
82646-#define __init __section(.init.text) __cold notrace
82647+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
82648 #define __initdata __section(.init.data)
82649 #define __initconst __constsection(.init.rodata)
82650 #define __exitdata __section(.exit.data)
82651@@ -100,7 +108,7 @@
82652 #define __cpuexitconst
82653
82654 /* Used for MEMORY_HOTPLUG */
82655-#define __meminit __section(.meminit.text) __cold notrace
82656+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
82657 #define __meminitdata __section(.meminit.data)
82658 #define __meminitconst __constsection(.meminit.rodata)
82659 #define __memexit __section(.memexit.text) __exitused __cold notrace
82660diff --git a/include/linux/init_task.h b/include/linux/init_task.h
82661index 77fc43f..73caf92 100644
82662--- a/include/linux/init_task.h
82663+++ b/include/linux/init_task.h
82664@@ -158,6 +158,12 @@ extern struct task_group root_task_group;
82665
82666 #define INIT_TASK_COMM "swapper"
82667
82668+#ifdef CONFIG_X86
82669+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
82670+#else
82671+#define INIT_TASK_THREAD_INFO
82672+#endif
82673+
82674 #ifdef CONFIG_RT_MUTEXES
82675 # define INIT_RT_MUTEXES(tsk) \
82676 .pi_waiters = RB_ROOT, \
82677@@ -205,6 +211,7 @@ extern struct task_group root_task_group;
82678 RCU_POINTER_INITIALIZER(cred, &init_cred), \
82679 .comm = INIT_TASK_COMM, \
82680 .thread = INIT_THREAD, \
82681+ INIT_TASK_THREAD_INFO \
82682 .fs = &init_fs, \
82683 .files = &init_files, \
82684 .signal = &init_signals, \
82685diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
82686index 69517a2..6b12d37 100644
82687--- a/include/linux/interrupt.h
82688+++ b/include/linux/interrupt.h
82689@@ -413,8 +413,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
82690
82691 struct softirq_action
82692 {
82693- void (*action)(struct softirq_action *);
82694-};
82695+ void (*action)(void);
82696+} __no_const;
82697
82698 asmlinkage void do_softirq(void);
82699 asmlinkage void __do_softirq(void);
82700@@ -428,7 +428,7 @@ static inline void do_softirq_own_stack(void)
82701 }
82702 #endif
82703
82704-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
82705+extern void open_softirq(int nr, void (*action)(void));
82706 extern void softirq_init(void);
82707 extern void __raise_softirq_irqoff(unsigned int nr);
82708
82709diff --git a/include/linux/iommu.h b/include/linux/iommu.h
82710index e6a7c9f..5804745 100644
82711--- a/include/linux/iommu.h
82712+++ b/include/linux/iommu.h
82713@@ -133,7 +133,7 @@ struct iommu_ops {
82714 u32 (*domain_get_windows)(struct iommu_domain *domain);
82715
82716 unsigned long pgsize_bitmap;
82717-};
82718+} __do_const;
82719
82720 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
82721 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
82722diff --git a/include/linux/ioport.h b/include/linux/ioport.h
82723index 2c525022..345b106 100644
82724--- a/include/linux/ioport.h
82725+++ b/include/linux/ioport.h
82726@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
82727 int adjust_resource(struct resource *res, resource_size_t start,
82728 resource_size_t size);
82729 resource_size_t resource_alignment(struct resource *res);
82730-static inline resource_size_t resource_size(const struct resource *res)
82731+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
82732 {
82733 return res->end - res->start + 1;
82734 }
82735diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
82736index 35e7eca..6afb7ad 100644
82737--- a/include/linux/ipc_namespace.h
82738+++ b/include/linux/ipc_namespace.h
82739@@ -69,7 +69,7 @@ struct ipc_namespace {
82740 struct user_namespace *user_ns;
82741
82742 unsigned int proc_inum;
82743-};
82744+} __randomize_layout;
82745
82746 extern struct ipc_namespace init_ipc_ns;
82747 extern atomic_t nr_ipc_ns;
82748diff --git a/include/linux/irq.h b/include/linux/irq.h
82749index 03f48d9..e86af0c 100644
82750--- a/include/linux/irq.h
82751+++ b/include/linux/irq.h
82752@@ -352,7 +352,8 @@ struct irq_chip {
82753 void (*irq_release_resources)(struct irq_data *data);
82754
82755 unsigned long flags;
82756-};
82757+} __do_const;
82758+typedef struct irq_chip __no_const irq_chip_no_const;
82759
82760 /*
82761 * irq_chip specific flags
82762diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
82763index 13eed92..3261c86 100644
82764--- a/include/linux/irqchip/arm-gic.h
82765+++ b/include/linux/irqchip/arm-gic.h
82766@@ -91,9 +91,11 @@
82767
82768 #ifndef __ASSEMBLY__
82769
82770+#include <linux/irq.h>
82771+
82772 struct device_node;
82773
82774-extern struct irq_chip gic_arch_extn;
82775+extern irq_chip_no_const gic_arch_extn;
82776
82777 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
82778 u32 offset, struct device_node *);
82779diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
82780index c367cbd..c9b79e6 100644
82781--- a/include/linux/jiffies.h
82782+++ b/include/linux/jiffies.h
82783@@ -280,20 +280,20 @@ extern unsigned long preset_lpj;
82784 /*
82785 * Convert various time units to each other:
82786 */
82787-extern unsigned int jiffies_to_msecs(const unsigned long j);
82788-extern unsigned int jiffies_to_usecs(const unsigned long j);
82789+extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
82790+extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
82791
82792-static inline u64 jiffies_to_nsecs(const unsigned long j)
82793+static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
82794 {
82795 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
82796 }
82797
82798-extern unsigned long msecs_to_jiffies(const unsigned int m);
82799-extern unsigned long usecs_to_jiffies(const unsigned int u);
82800+extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
82801+extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
82802 extern unsigned long timespec_to_jiffies(const struct timespec *value);
82803 extern void jiffies_to_timespec(const unsigned long jiffies,
82804- struct timespec *value);
82805-extern unsigned long timeval_to_jiffies(const struct timeval *value);
82806+ struct timespec *value) __intentional_overflow(-1);
82807+extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
82808 extern void jiffies_to_timeval(const unsigned long jiffies,
82809 struct timeval *value);
82810
82811diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
82812index 6883e19..e854fcb 100644
82813--- a/include/linux/kallsyms.h
82814+++ b/include/linux/kallsyms.h
82815@@ -15,7 +15,8 @@
82816
82817 struct module;
82818
82819-#ifdef CONFIG_KALLSYMS
82820+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
82821+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
82822 /* Lookup the address for a symbol. Returns 0 if not found. */
82823 unsigned long kallsyms_lookup_name(const char *name);
82824
82825@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
82826 /* Stupid that this does nothing, but I didn't create this mess. */
82827 #define __print_symbol(fmt, addr)
82828 #endif /*CONFIG_KALLSYMS*/
82829+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
82830+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
82831+extern unsigned long kallsyms_lookup_name(const char *name);
82832+extern void __print_symbol(const char *fmt, unsigned long address);
82833+extern int sprint_backtrace(char *buffer, unsigned long address);
82834+extern int sprint_symbol(char *buffer, unsigned long address);
82835+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
82836+const char *kallsyms_lookup(unsigned long addr,
82837+ unsigned long *symbolsize,
82838+ unsigned long *offset,
82839+ char **modname, char *namebuf);
82840+extern int kallsyms_lookup_size_offset(unsigned long addr,
82841+ unsigned long *symbolsize,
82842+ unsigned long *offset);
82843+#endif
82844
82845 /* This macro allows us to keep printk typechecking */
82846 static __printf(1, 2)
82847diff --git a/include/linux/key-type.h b/include/linux/key-type.h
82848index ff9f1d3..6712be5 100644
82849--- a/include/linux/key-type.h
82850+++ b/include/linux/key-type.h
82851@@ -152,7 +152,7 @@ struct key_type {
82852 /* internal fields */
82853 struct list_head link; /* link in types list */
82854 struct lock_class_key lock_class; /* key->sem lock class */
82855-};
82856+} __do_const;
82857
82858 extern struct key_type key_type_keyring;
82859
82860diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
82861index e465bb1..19f605f 100644
82862--- a/include/linux/kgdb.h
82863+++ b/include/linux/kgdb.h
82864@@ -52,7 +52,7 @@ extern int kgdb_connected;
82865 extern int kgdb_io_module_registered;
82866
82867 extern atomic_t kgdb_setting_breakpoint;
82868-extern atomic_t kgdb_cpu_doing_single_step;
82869+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
82870
82871 extern struct task_struct *kgdb_usethread;
82872 extern struct task_struct *kgdb_contthread;
82873@@ -254,7 +254,7 @@ struct kgdb_arch {
82874 void (*correct_hw_break)(void);
82875
82876 void (*enable_nmi)(bool on);
82877-};
82878+} __do_const;
82879
82880 /**
82881 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
82882@@ -279,7 +279,7 @@ struct kgdb_io {
82883 void (*pre_exception) (void);
82884 void (*post_exception) (void);
82885 int is_console;
82886-};
82887+} __do_const;
82888
82889 extern struct kgdb_arch arch_kgdb_ops;
82890
82891diff --git a/include/linux/kmod.h b/include/linux/kmod.h
82892index 0555cc6..40116ce 100644
82893--- a/include/linux/kmod.h
82894+++ b/include/linux/kmod.h
82895@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
82896 * usually useless though. */
82897 extern __printf(2, 3)
82898 int __request_module(bool wait, const char *name, ...);
82899+extern __printf(3, 4)
82900+int ___request_module(bool wait, char *param_name, const char *name, ...);
82901 #define request_module(mod...) __request_module(true, mod)
82902 #define request_module_nowait(mod...) __request_module(false, mod)
82903 #define try_then_request_module(x, mod...) \
82904@@ -57,6 +59,9 @@ struct subprocess_info {
82905 struct work_struct work;
82906 struct completion *complete;
82907 char *path;
82908+#ifdef CONFIG_GRKERNSEC
82909+ char *origpath;
82910+#endif
82911 char **argv;
82912 char **envp;
82913 int wait;
82914diff --git a/include/linux/kobject.h b/include/linux/kobject.h
82915index 2d61b90..a1d0a13 100644
82916--- a/include/linux/kobject.h
82917+++ b/include/linux/kobject.h
82918@@ -118,7 +118,7 @@ struct kobj_type {
82919 struct attribute **default_attrs;
82920 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
82921 const void *(*namespace)(struct kobject *kobj);
82922-};
82923+} __do_const;
82924
82925 struct kobj_uevent_env {
82926 char *argv[3];
82927@@ -142,6 +142,7 @@ struct kobj_attribute {
82928 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
82929 const char *buf, size_t count);
82930 };
82931+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
82932
82933 extern const struct sysfs_ops kobj_sysfs_ops;
82934
82935@@ -169,7 +170,7 @@ struct kset {
82936 spinlock_t list_lock;
82937 struct kobject kobj;
82938 const struct kset_uevent_ops *uevent_ops;
82939-};
82940+} __randomize_layout;
82941
82942 extern void kset_init(struct kset *kset);
82943 extern int __must_check kset_register(struct kset *kset);
82944diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
82945index df32d25..fb52e27 100644
82946--- a/include/linux/kobject_ns.h
82947+++ b/include/linux/kobject_ns.h
82948@@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
82949 const void *(*netlink_ns)(struct sock *sk);
82950 const void *(*initial_ns)(void);
82951 void (*drop_ns)(void *);
82952-};
82953+} __do_const;
82954
82955 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
82956 int kobj_ns_type_registered(enum kobj_ns_type type);
82957diff --git a/include/linux/kref.h b/include/linux/kref.h
82958index 484604d..0f6c5b6 100644
82959--- a/include/linux/kref.h
82960+++ b/include/linux/kref.h
82961@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
82962 static inline int kref_sub(struct kref *kref, unsigned int count,
82963 void (*release)(struct kref *kref))
82964 {
82965- WARN_ON(release == NULL);
82966+ BUG_ON(release == NULL);
82967
82968 if (atomic_sub_and_test((int) count, &kref->refcount)) {
82969 release(kref);
82970diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
82971index a6059bd..8126d5c 100644
82972--- a/include/linux/kvm_host.h
82973+++ b/include/linux/kvm_host.h
82974@@ -460,7 +460,7 @@ static inline void kvm_irqfd_exit(void)
82975 {
82976 }
82977 #endif
82978-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
82979+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
82980 struct module *module);
82981 void kvm_exit(void);
82982
82983@@ -629,7 +629,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
82984 struct kvm_guest_debug *dbg);
82985 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
82986
82987-int kvm_arch_init(void *opaque);
82988+int kvm_arch_init(const void *opaque);
82989 void kvm_arch_exit(void);
82990
82991 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
82992diff --git a/include/linux/libata.h b/include/linux/libata.h
82993index bd5fefe..2a8a8d2 100644
82994--- a/include/linux/libata.h
82995+++ b/include/linux/libata.h
82996@@ -976,7 +976,7 @@ struct ata_port_operations {
82997 * fields must be pointers.
82998 */
82999 const struct ata_port_operations *inherits;
83000-};
83001+} __do_const;
83002
83003 struct ata_port_info {
83004 unsigned long flags;
83005diff --git a/include/linux/linkage.h b/include/linux/linkage.h
83006index a6a42dd..6c5ebce 100644
83007--- a/include/linux/linkage.h
83008+++ b/include/linux/linkage.h
83009@@ -36,6 +36,7 @@
83010 #endif
83011
83012 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
83013+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
83014 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
83015
83016 /*
83017diff --git a/include/linux/list.h b/include/linux/list.h
83018index f33f831..1ffe5e2 100644
83019--- a/include/linux/list.h
83020+++ b/include/linux/list.h
83021@@ -113,6 +113,19 @@ extern void __list_del_entry(struct list_head *entry);
83022 extern void list_del(struct list_head *entry);
83023 #endif
83024
83025+extern void __pax_list_add(struct list_head *new,
83026+ struct list_head *prev,
83027+ struct list_head *next);
83028+static inline void pax_list_add(struct list_head *new, struct list_head *head)
83029+{
83030+ __pax_list_add(new, head, head->next);
83031+}
83032+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
83033+{
83034+ __pax_list_add(new, head->prev, head);
83035+}
83036+extern void pax_list_del(struct list_head *entry);
83037+
83038 /**
83039 * list_replace - replace old entry by new one
83040 * @old : the element to be replaced
83041@@ -146,6 +159,8 @@ static inline void list_del_init(struct list_head *entry)
83042 INIT_LIST_HEAD(entry);
83043 }
83044
83045+extern void pax_list_del_init(struct list_head *entry);
83046+
83047 /**
83048 * list_move - delete from one list and add as another's head
83049 * @list: the entry to move
83050diff --git a/include/linux/lockref.h b/include/linux/lockref.h
83051index 4bfde0e..d6e2e09 100644
83052--- a/include/linux/lockref.h
83053+++ b/include/linux/lockref.h
83054@@ -47,4 +47,36 @@ static inline int __lockref_is_dead(const struct lockref *l)
83055 return ((int)l->count < 0);
83056 }
83057
83058+static inline unsigned int __lockref_read(struct lockref *lockref)
83059+{
83060+ return lockref->count;
83061+}
83062+
83063+static inline void __lockref_set(struct lockref *lockref, unsigned int count)
83064+{
83065+ lockref->count = count;
83066+}
83067+
83068+static inline void __lockref_inc(struct lockref *lockref)
83069+{
83070+
83071+#ifdef CONFIG_PAX_REFCOUNT
83072+ atomic_inc((atomic_t *)&lockref->count);
83073+#else
83074+ lockref->count++;
83075+#endif
83076+
83077+}
83078+
83079+static inline void __lockref_dec(struct lockref *lockref)
83080+{
83081+
83082+#ifdef CONFIG_PAX_REFCOUNT
83083+ atomic_dec((atomic_t *)&lockref->count);
83084+#else
83085+ lockref->count--;
83086+#endif
83087+
83088+}
83089+
83090 #endif /* __LINUX_LOCKREF_H */
83091diff --git a/include/linux/math64.h b/include/linux/math64.h
83092index c45c089..298841c 100644
83093--- a/include/linux/math64.h
83094+++ b/include/linux/math64.h
83095@@ -15,7 +15,7 @@
83096 * This is commonly provided by 32bit archs to provide an optimized 64bit
83097 * divide.
83098 */
83099-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83100+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83101 {
83102 *remainder = dividend % divisor;
83103 return dividend / divisor;
83104@@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
83105 /**
83106 * div64_u64 - unsigned 64bit divide with 64bit divisor
83107 */
83108-static inline u64 div64_u64(u64 dividend, u64 divisor)
83109+static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
83110 {
83111 return dividend / divisor;
83112 }
83113@@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
83114 #define div64_ul(x, y) div_u64((x), (y))
83115
83116 #ifndef div_u64_rem
83117-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83118+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83119 {
83120 *remainder = do_div(dividend, divisor);
83121 return dividend;
83122@@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
83123 #endif
83124
83125 #ifndef div64_u64
83126-extern u64 div64_u64(u64 dividend, u64 divisor);
83127+extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
83128 #endif
83129
83130 #ifndef div64_s64
83131@@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
83132 * divide.
83133 */
83134 #ifndef div_u64
83135-static inline u64 div_u64(u64 dividend, u32 divisor)
83136+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
83137 {
83138 u32 remainder;
83139 return div_u64_rem(dividend, divisor, &remainder);
83140diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
83141index 3d385c8..deacb6a 100644
83142--- a/include/linux/mempolicy.h
83143+++ b/include/linux/mempolicy.h
83144@@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
83145 }
83146
83147 #define vma_policy(vma) ((vma)->vm_policy)
83148+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
83149+{
83150+ vma->vm_policy = pol;
83151+}
83152
83153 static inline void mpol_get(struct mempolicy *pol)
83154 {
83155@@ -229,6 +233,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
83156 }
83157
83158 #define vma_policy(vma) NULL
83159+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
83160+{
83161+}
83162
83163 static inline int
83164 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
83165diff --git a/include/linux/mm.h b/include/linux/mm.h
83166index b464611..77cbfc1 100644
83167--- a/include/linux/mm.h
83168+++ b/include/linux/mm.h
83169@@ -128,6 +128,11 @@ extern unsigned int kobjsize(const void *objp);
83170 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
83171 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
83172 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
83173+
83174+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
83175+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
83176+#endif
83177+
83178 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
83179
83180 #ifdef CONFIG_MEM_SOFT_DIRTY
83181@@ -238,8 +243,8 @@ struct vm_operations_struct {
83182 /* called by access_process_vm when get_user_pages() fails, typically
83183 * for use by special VMAs that can switch between memory and hardware
83184 */
83185- int (*access)(struct vm_area_struct *vma, unsigned long addr,
83186- void *buf, int len, int write);
83187+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
83188+ void *buf, size_t len, int write);
83189
83190 /* Called by the /proc/PID/maps code to ask the vma whether it
83191 * has a special name. Returning non-NULL will also cause this
83192@@ -275,6 +280,7 @@ struct vm_operations_struct {
83193 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
83194 unsigned long size, pgoff_t pgoff);
83195 };
83196+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
83197
83198 struct mmu_gather;
83199 struct inode;
83200@@ -1165,8 +1171,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
83201 unsigned long *pfn);
83202 int follow_phys(struct vm_area_struct *vma, unsigned long address,
83203 unsigned int flags, unsigned long *prot, resource_size_t *phys);
83204-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
83205- void *buf, int len, int write);
83206+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
83207+ void *buf, size_t len, int write);
83208
83209 static inline void unmap_shared_mapping_range(struct address_space *mapping,
83210 loff_t const holebegin, loff_t const holelen)
83211@@ -1206,9 +1212,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
83212 }
83213 #endif
83214
83215-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
83216-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
83217- void *buf, int len, int write);
83218+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
83219+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
83220+ void *buf, size_t len, int write);
83221
83222 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
83223 unsigned long start, unsigned long nr_pages,
83224@@ -1240,34 +1246,6 @@ int set_page_dirty_lock(struct page *page);
83225 int clear_page_dirty_for_io(struct page *page);
83226 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
83227
83228-/* Is the vma a continuation of the stack vma above it? */
83229-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
83230-{
83231- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
83232-}
83233-
83234-static inline int stack_guard_page_start(struct vm_area_struct *vma,
83235- unsigned long addr)
83236-{
83237- return (vma->vm_flags & VM_GROWSDOWN) &&
83238- (vma->vm_start == addr) &&
83239- !vma_growsdown(vma->vm_prev, addr);
83240-}
83241-
83242-/* Is the vma a continuation of the stack vma below it? */
83243-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
83244-{
83245- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
83246-}
83247-
83248-static inline int stack_guard_page_end(struct vm_area_struct *vma,
83249- unsigned long addr)
83250-{
83251- return (vma->vm_flags & VM_GROWSUP) &&
83252- (vma->vm_end == addr) &&
83253- !vma_growsup(vma->vm_next, addr);
83254-}
83255-
83256 extern struct task_struct *task_of_stack(struct task_struct *task,
83257 struct vm_area_struct *vma, bool in_group);
83258
83259@@ -1385,8 +1363,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
83260 {
83261 return 0;
83262 }
83263+
83264+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
83265+ unsigned long address)
83266+{
83267+ return 0;
83268+}
83269 #else
83270 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
83271+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
83272 #endif
83273
83274 #ifdef __PAGETABLE_PMD_FOLDED
83275@@ -1395,8 +1380,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
83276 {
83277 return 0;
83278 }
83279+
83280+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
83281+ unsigned long address)
83282+{
83283+ return 0;
83284+}
83285 #else
83286 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
83287+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
83288 #endif
83289
83290 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
83291@@ -1414,11 +1406,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
83292 NULL: pud_offset(pgd, address);
83293 }
83294
83295+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
83296+{
83297+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
83298+ NULL: pud_offset(pgd, address);
83299+}
83300+
83301 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
83302 {
83303 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
83304 NULL: pmd_offset(pud, address);
83305 }
83306+
83307+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
83308+{
83309+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
83310+ NULL: pmd_offset(pud, address);
83311+}
83312 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
83313
83314 #if USE_SPLIT_PTE_PTLOCKS
83315@@ -1801,12 +1805,23 @@ extern struct vm_area_struct *copy_vma(struct vm_area_struct **,
83316 bool *need_rmap_locks);
83317 extern void exit_mmap(struct mm_struct *);
83318
83319+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
83320+extern void gr_learn_resource(const struct task_struct *task, const int res,
83321+ const unsigned long wanted, const int gt);
83322+#else
83323+static inline void gr_learn_resource(const struct task_struct *task, const int res,
83324+ const unsigned long wanted, const int gt)
83325+{
83326+}
83327+#endif
83328+
83329 static inline int check_data_rlimit(unsigned long rlim,
83330 unsigned long new,
83331 unsigned long start,
83332 unsigned long end_data,
83333 unsigned long start_data)
83334 {
83335+ gr_learn_resource(current, RLIMIT_DATA, (new - start) + (end_data - start_data), 1);
83336 if (rlim < RLIM_INFINITY) {
83337 if (((new - start) + (end_data - start_data)) > rlim)
83338 return -ENOSPC;
83339@@ -1831,7 +1846,7 @@ extern int install_special_mapping(struct mm_struct *mm,
83340 unsigned long addr, unsigned long len,
83341 unsigned long flags, struct page **pages);
83342
83343-extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
83344+extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
83345
83346 extern unsigned long mmap_region(struct file *file, unsigned long addr,
83347 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
83348@@ -1839,6 +1854,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
83349 unsigned long len, unsigned long prot, unsigned long flags,
83350 unsigned long pgoff, unsigned long *populate);
83351 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
83352+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
83353
83354 #ifdef CONFIG_MMU
83355 extern int __mm_populate(unsigned long addr, unsigned long len,
83356@@ -1867,10 +1883,11 @@ struct vm_unmapped_area_info {
83357 unsigned long high_limit;
83358 unsigned long align_mask;
83359 unsigned long align_offset;
83360+ unsigned long threadstack_offset;
83361 };
83362
83363-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
83364-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
83365+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
83366+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
83367
83368 /*
83369 * Search for an unmapped address range.
83370@@ -1882,7 +1899,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
83371 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
83372 */
83373 static inline unsigned long
83374-vm_unmapped_area(struct vm_unmapped_area_info *info)
83375+vm_unmapped_area(const struct vm_unmapped_area_info *info)
83376 {
83377 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
83378 return unmapped_area(info);
83379@@ -1944,6 +1961,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
83380 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
83381 struct vm_area_struct **pprev);
83382
83383+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
83384+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
83385+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
83386+
83387 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
83388 NULL if none. Assume start_addr < end_addr. */
83389 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
83390@@ -1973,10 +1994,10 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
83391 }
83392
83393 #ifdef CONFIG_MMU
83394-pgprot_t vm_get_page_prot(unsigned long vm_flags);
83395+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
83396 void vma_set_page_prot(struct vm_area_struct *vma);
83397 #else
83398-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
83399+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
83400 {
83401 return __pgprot(0);
83402 }
83403@@ -2038,6 +2059,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
83404 static inline void vm_stat_account(struct mm_struct *mm,
83405 unsigned long flags, struct file *file, long pages)
83406 {
83407+
83408+#ifdef CONFIG_PAX_RANDMMAP
83409+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
83410+#endif
83411+
83412 mm->total_vm += pages;
83413 }
83414 #endif /* CONFIG_PROC_FS */
83415@@ -2126,7 +2152,7 @@ extern int unpoison_memory(unsigned long pfn);
83416 extern int sysctl_memory_failure_early_kill;
83417 extern int sysctl_memory_failure_recovery;
83418 extern void shake_page(struct page *p, int access);
83419-extern atomic_long_t num_poisoned_pages;
83420+extern atomic_long_unchecked_t num_poisoned_pages;
83421 extern int soft_offline_page(struct page *page, int flags);
83422
83423 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
83424@@ -2161,5 +2187,11 @@ void __init setup_nr_node_ids(void);
83425 static inline void setup_nr_node_ids(void) {}
83426 #endif
83427
83428+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83429+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
83430+#else
83431+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
83432+#endif
83433+
83434 #endif /* __KERNEL__ */
83435 #endif /* _LINUX_MM_H */
83436diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
83437index 6e0b286..90d9c0d 100644
83438--- a/include/linux/mm_types.h
83439+++ b/include/linux/mm_types.h
83440@@ -308,7 +308,9 @@ struct vm_area_struct {
83441 #ifdef CONFIG_NUMA
83442 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
83443 #endif
83444-};
83445+
83446+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
83447+} __randomize_layout;
83448
83449 struct core_thread {
83450 struct task_struct *task;
83451@@ -454,7 +456,25 @@ struct mm_struct {
83452 bool tlb_flush_pending;
83453 #endif
83454 struct uprobes_state uprobes_state;
83455-};
83456+
83457+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
83458+ unsigned long pax_flags;
83459+#endif
83460+
83461+#ifdef CONFIG_PAX_DLRESOLVE
83462+ unsigned long call_dl_resolve;
83463+#endif
83464+
83465+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
83466+ unsigned long call_syscall;
83467+#endif
83468+
83469+#ifdef CONFIG_PAX_ASLR
83470+ unsigned long delta_mmap; /* randomized offset */
83471+ unsigned long delta_stack; /* randomized offset */
83472+#endif
83473+
83474+} __randomize_layout;
83475
83476 static inline void mm_init_cpumask(struct mm_struct *mm)
83477 {
83478diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
83479index c5d5278..f0b68c8 100644
83480--- a/include/linux/mmiotrace.h
83481+++ b/include/linux/mmiotrace.h
83482@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
83483 /* Called from ioremap.c */
83484 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
83485 void __iomem *addr);
83486-extern void mmiotrace_iounmap(volatile void __iomem *addr);
83487+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
83488
83489 /* For anyone to insert markers. Remember trailing newline. */
83490 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
83491@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
83492 {
83493 }
83494
83495-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
83496+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
83497 {
83498 }
83499
83500diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
83501index ffe66e3..b310722 100644
83502--- a/include/linux/mmzone.h
83503+++ b/include/linux/mmzone.h
83504@@ -527,7 +527,7 @@ struct zone {
83505
83506 ZONE_PADDING(_pad3_)
83507 /* Zone statistics */
83508- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83509+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83510 } ____cacheline_internodealigned_in_smp;
83511
83512 enum zone_flags {
83513diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
83514index 44eeef0..a92d3f9 100644
83515--- a/include/linux/mod_devicetable.h
83516+++ b/include/linux/mod_devicetable.h
83517@@ -139,7 +139,7 @@ struct usb_device_id {
83518 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
83519 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
83520
83521-#define HID_ANY_ID (~0)
83522+#define HID_ANY_ID (~0U)
83523 #define HID_BUS_ANY 0xffff
83524 #define HID_GROUP_ANY 0x0000
83525
83526@@ -475,7 +475,7 @@ struct dmi_system_id {
83527 const char *ident;
83528 struct dmi_strmatch matches[4];
83529 void *driver_data;
83530-};
83531+} __do_const;
83532 /*
83533 * struct dmi_device_id appears during expansion of
83534 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
83535diff --git a/include/linux/module.h b/include/linux/module.h
83536index 71f282a..b2387e2 100644
83537--- a/include/linux/module.h
83538+++ b/include/linux/module.h
83539@@ -17,9 +17,11 @@
83540 #include <linux/moduleparam.h>
83541 #include <linux/jump_label.h>
83542 #include <linux/export.h>
83543+#include <linux/fs.h>
83544
83545 #include <linux/percpu.h>
83546 #include <asm/module.h>
83547+#include <asm/pgtable.h>
83548
83549 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
83550 #define MODULE_SIG_STRING "~Module signature appended~\n"
83551@@ -42,7 +44,7 @@ struct module_kobject {
83552 struct kobject *drivers_dir;
83553 struct module_param_attrs *mp;
83554 struct completion *kobj_completion;
83555-};
83556+} __randomize_layout;
83557
83558 struct module_attribute {
83559 struct attribute attr;
83560@@ -54,12 +56,13 @@ struct module_attribute {
83561 int (*test)(struct module *);
83562 void (*free)(struct module *);
83563 };
83564+typedef struct module_attribute __no_const module_attribute_no_const;
83565
83566 struct module_version_attribute {
83567 struct module_attribute mattr;
83568 const char *module_name;
83569 const char *version;
83570-} __attribute__ ((__aligned__(sizeof(void *))));
83571+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
83572
83573 extern ssize_t __modver_version_show(struct module_attribute *,
83574 struct module_kobject *, char *);
83575@@ -235,7 +238,7 @@ struct module {
83576
83577 /* Sysfs stuff. */
83578 struct module_kobject mkobj;
83579- struct module_attribute *modinfo_attrs;
83580+ module_attribute_no_const *modinfo_attrs;
83581 const char *version;
83582 const char *srcversion;
83583 struct kobject *holders_dir;
83584@@ -284,19 +287,16 @@ struct module {
83585 int (*init)(void);
83586
83587 /* If this is non-NULL, vfree after init() returns */
83588- void *module_init;
83589+ void *module_init_rx, *module_init_rw;
83590
83591 /* Here is the actual code + data, vfree'd on unload. */
83592- void *module_core;
83593+ void *module_core_rx, *module_core_rw;
83594
83595 /* Here are the sizes of the init and core sections */
83596- unsigned int init_size, core_size;
83597+ unsigned int init_size_rw, core_size_rw;
83598
83599 /* The size of the executable code in each section. */
83600- unsigned int init_text_size, core_text_size;
83601-
83602- /* Size of RO sections of the module (text+rodata) */
83603- unsigned int init_ro_size, core_ro_size;
83604+ unsigned int init_size_rx, core_size_rx;
83605
83606 /* Arch-specific module values */
83607 struct mod_arch_specific arch;
83608@@ -352,6 +352,10 @@ struct module {
83609 #ifdef CONFIG_EVENT_TRACING
83610 struct ftrace_event_call **trace_events;
83611 unsigned int num_trace_events;
83612+ struct file_operations trace_id;
83613+ struct file_operations trace_enable;
83614+ struct file_operations trace_format;
83615+ struct file_operations trace_filter;
83616 #endif
83617 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
83618 unsigned int num_ftrace_callsites;
83619@@ -375,7 +379,7 @@ struct module {
83620 ctor_fn_t *ctors;
83621 unsigned int num_ctors;
83622 #endif
83623-};
83624+} __randomize_layout;
83625 #ifndef MODULE_ARCH_INIT
83626 #define MODULE_ARCH_INIT {}
83627 #endif
83628@@ -396,18 +400,48 @@ bool is_module_address(unsigned long addr);
83629 bool is_module_percpu_address(unsigned long addr);
83630 bool is_module_text_address(unsigned long addr);
83631
83632+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
83633+{
83634+
83635+#ifdef CONFIG_PAX_KERNEXEC
83636+ if (ktla_ktva(addr) >= (unsigned long)start &&
83637+ ktla_ktva(addr) < (unsigned long)start + size)
83638+ return 1;
83639+#endif
83640+
83641+ return ((void *)addr >= start && (void *)addr < start + size);
83642+}
83643+
83644+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
83645+{
83646+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
83647+}
83648+
83649+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
83650+{
83651+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
83652+}
83653+
83654+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
83655+{
83656+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
83657+}
83658+
83659+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
83660+{
83661+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
83662+}
83663+
83664 static inline bool within_module_core(unsigned long addr,
83665 const struct module *mod)
83666 {
83667- return (unsigned long)mod->module_core <= addr &&
83668- addr < (unsigned long)mod->module_core + mod->core_size;
83669+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
83670 }
83671
83672 static inline bool within_module_init(unsigned long addr,
83673 const struct module *mod)
83674 {
83675- return (unsigned long)mod->module_init <= addr &&
83676- addr < (unsigned long)mod->module_init + mod->init_size;
83677+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
83678 }
83679
83680 static inline bool within_module(unsigned long addr, const struct module *mod)
83681diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
83682index 7eeb9bb..68f37e0 100644
83683--- a/include/linux/moduleloader.h
83684+++ b/include/linux/moduleloader.h
83685@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
83686 sections. Returns NULL on failure. */
83687 void *module_alloc(unsigned long size);
83688
83689+#ifdef CONFIG_PAX_KERNEXEC
83690+void *module_alloc_exec(unsigned long size);
83691+#else
83692+#define module_alloc_exec(x) module_alloc(x)
83693+#endif
83694+
83695 /* Free memory returned from module_alloc. */
83696 void module_free(struct module *mod, void *module_region);
83697
83698+#ifdef CONFIG_PAX_KERNEXEC
83699+void module_free_exec(struct module *mod, void *module_region);
83700+#else
83701+#define module_free_exec(x, y) module_free((x), (y))
83702+#endif
83703+
83704 /*
83705 * Apply the given relocation to the (simplified) ELF. Return -error
83706 * or 0.
83707@@ -45,8 +57,10 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
83708 unsigned int relsec,
83709 struct module *me)
83710 {
83711+#ifdef CONFIG_MODULES
83712 printk(KERN_ERR "module %s: REL relocation unsupported\n",
83713 module_name(me));
83714+#endif
83715 return -ENOEXEC;
83716 }
83717 #endif
83718@@ -68,8 +82,10 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
83719 unsigned int relsec,
83720 struct module *me)
83721 {
83722+#ifdef CONFIG_MODULES
83723 printk(KERN_ERR "module %s: REL relocation unsupported\n",
83724 module_name(me));
83725+#endif
83726 return -ENOEXEC;
83727 }
83728 #endif
83729diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
83730index 1c9effa..1160bdd 100644
83731--- a/include/linux/moduleparam.h
83732+++ b/include/linux/moduleparam.h
83733@@ -323,7 +323,7 @@ static inline void __kernel_param_unlock(void)
83734 * @len is usually just sizeof(string).
83735 */
83736 #define module_param_string(name, string, len, perm) \
83737- static const struct kparam_string __param_string_##name \
83738+ static const struct kparam_string __param_string_##name __used \
83739 = { len, string }; \
83740 __module_param_call(MODULE_PARAM_PREFIX, name, \
83741 &param_ops_string, \
83742@@ -467,7 +467,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
83743 */
83744 #define module_param_array_named(name, array, type, nump, perm) \
83745 param_check_##type(name, &(array)[0]); \
83746- static const struct kparam_array __param_arr_##name \
83747+ static const struct kparam_array __param_arr_##name __used \
83748 = { .max = ARRAY_SIZE(array), .num = nump, \
83749 .ops = &param_ops_##type, \
83750 .elemsize = sizeof(array[0]), .elem = array }; \
83751diff --git a/include/linux/mount.h b/include/linux/mount.h
83752index c2c561d..a5f2a8c 100644
83753--- a/include/linux/mount.h
83754+++ b/include/linux/mount.h
83755@@ -66,7 +66,7 @@ struct vfsmount {
83756 struct dentry *mnt_root; /* root of the mounted tree */
83757 struct super_block *mnt_sb; /* pointer to superblock */
83758 int mnt_flags;
83759-};
83760+} __randomize_layout;
83761
83762 struct file; /* forward dec */
83763 struct path;
83764diff --git a/include/linux/namei.h b/include/linux/namei.h
83765index 492de72..1bddcd4 100644
83766--- a/include/linux/namei.h
83767+++ b/include/linux/namei.h
83768@@ -19,7 +19,7 @@ struct nameidata {
83769 unsigned seq, m_seq;
83770 int last_type;
83771 unsigned depth;
83772- char *saved_names[MAX_NESTED_LINKS + 1];
83773+ const char *saved_names[MAX_NESTED_LINKS + 1];
83774 };
83775
83776 /*
83777@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
83778
83779 extern void nd_jump_link(struct nameidata *nd, struct path *path);
83780
83781-static inline void nd_set_link(struct nameidata *nd, char *path)
83782+static inline void nd_set_link(struct nameidata *nd, const char *path)
83783 {
83784 nd->saved_names[nd->depth] = path;
83785 }
83786
83787-static inline char *nd_get_link(struct nameidata *nd)
83788+static inline const char *nd_get_link(const struct nameidata *nd)
83789 {
83790 return nd->saved_names[nd->depth];
83791 }
83792diff --git a/include/linux/net.h b/include/linux/net.h
83793index 17d8339..81656c0 100644
83794--- a/include/linux/net.h
83795+++ b/include/linux/net.h
83796@@ -192,7 +192,7 @@ struct net_proto_family {
83797 int (*create)(struct net *net, struct socket *sock,
83798 int protocol, int kern);
83799 struct module *owner;
83800-};
83801+} __do_const;
83802
83803 struct iovec;
83804 struct kvec;
83805diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
83806index 74fd5d3..86a1e4f 100644
83807--- a/include/linux/netdevice.h
83808+++ b/include/linux/netdevice.h
83809@@ -1156,6 +1156,7 @@ struct net_device_ops {
83810 bool (*ndo_gso_check) (struct sk_buff *skb,
83811 struct net_device *dev);
83812 };
83813+typedef struct net_device_ops __no_const net_device_ops_no_const;
83814
83815 /**
83816 * enum net_device_priv_flags - &struct net_device priv_flags
83817@@ -1498,10 +1499,10 @@ struct net_device {
83818
83819 struct net_device_stats stats;
83820
83821- atomic_long_t rx_dropped;
83822- atomic_long_t tx_dropped;
83823+ atomic_long_unchecked_t rx_dropped;
83824+ atomic_long_unchecked_t tx_dropped;
83825
83826- atomic_t carrier_changes;
83827+ atomic_unchecked_t carrier_changes;
83828
83829 #ifdef CONFIG_WIRELESS_EXT
83830 const struct iw_handler_def * wireless_handlers;
83831diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
83832index 2517ece..0bbfcfb 100644
83833--- a/include/linux/netfilter.h
83834+++ b/include/linux/netfilter.h
83835@@ -85,7 +85,7 @@ struct nf_sockopt_ops {
83836 #endif
83837 /* Use the module struct to lock set/get code in place */
83838 struct module *owner;
83839-};
83840+} __do_const;
83841
83842 /* Function to register/unregister hook points. */
83843 int nf_register_hook(struct nf_hook_ops *reg);
83844diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
83845index e955d47..04a5338 100644
83846--- a/include/linux/netfilter/nfnetlink.h
83847+++ b/include/linux/netfilter/nfnetlink.h
83848@@ -19,7 +19,7 @@ struct nfnl_callback {
83849 const struct nlattr * const cda[]);
83850 const struct nla_policy *policy; /* netlink attribute policy */
83851 const u_int16_t attr_count; /* number of nlattr's */
83852-};
83853+} __do_const;
83854
83855 struct nfnetlink_subsystem {
83856 const char *name;
83857diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
83858new file mode 100644
83859index 0000000..33f4af8
83860--- /dev/null
83861+++ b/include/linux/netfilter/xt_gradm.h
83862@@ -0,0 +1,9 @@
83863+#ifndef _LINUX_NETFILTER_XT_GRADM_H
83864+#define _LINUX_NETFILTER_XT_GRADM_H 1
83865+
83866+struct xt_gradm_mtinfo {
83867+ __u16 flags;
83868+ __u16 invflags;
83869+};
83870+
83871+#endif
83872diff --git a/include/linux/nls.h b/include/linux/nls.h
83873index 520681b..2b7fabb 100644
83874--- a/include/linux/nls.h
83875+++ b/include/linux/nls.h
83876@@ -31,7 +31,7 @@ struct nls_table {
83877 const unsigned char *charset2upper;
83878 struct module *owner;
83879 struct nls_table *next;
83880-};
83881+} __do_const;
83882
83883 /* this value hold the maximum octet of charset */
83884 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
83885@@ -46,7 +46,7 @@ enum utf16_endian {
83886 /* nls_base.c */
83887 extern int __register_nls(struct nls_table *, struct module *);
83888 extern int unregister_nls(struct nls_table *);
83889-extern struct nls_table *load_nls(char *);
83890+extern struct nls_table *load_nls(const char *);
83891 extern void unload_nls(struct nls_table *);
83892 extern struct nls_table *load_nls_default(void);
83893 #define register_nls(nls) __register_nls((nls), THIS_MODULE)
83894diff --git a/include/linux/notifier.h b/include/linux/notifier.h
83895index d14a4c3..a078786 100644
83896--- a/include/linux/notifier.h
83897+++ b/include/linux/notifier.h
83898@@ -54,7 +54,8 @@ struct notifier_block {
83899 notifier_fn_t notifier_call;
83900 struct notifier_block __rcu *next;
83901 int priority;
83902-};
83903+} __do_const;
83904+typedef struct notifier_block __no_const notifier_block_no_const;
83905
83906 struct atomic_notifier_head {
83907 spinlock_t lock;
83908diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
83909index b2a0f15..4d7da32 100644
83910--- a/include/linux/oprofile.h
83911+++ b/include/linux/oprofile.h
83912@@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
83913 int oprofilefs_create_ro_ulong(struct dentry * root,
83914 char const * name, ulong * val);
83915
83916-/** Create a file for read-only access to an atomic_t. */
83917+/** Create a file for read-only access to an atomic_unchecked_t. */
83918 int oprofilefs_create_ro_atomic(struct dentry * root,
83919- char const * name, atomic_t * val);
83920+ char const * name, atomic_unchecked_t * val);
83921
83922 /** create a directory */
83923 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
83924diff --git a/include/linux/padata.h b/include/linux/padata.h
83925index 4386946..f50c615 100644
83926--- a/include/linux/padata.h
83927+++ b/include/linux/padata.h
83928@@ -129,7 +129,7 @@ struct parallel_data {
83929 struct padata_serial_queue __percpu *squeue;
83930 atomic_t reorder_objects;
83931 atomic_t refcnt;
83932- atomic_t seq_nr;
83933+ atomic_unchecked_t seq_nr;
83934 struct padata_cpumask cpumask;
83935 spinlock_t lock ____cacheline_aligned;
83936 unsigned int processed;
83937diff --git a/include/linux/path.h b/include/linux/path.h
83938index d137218..be0c176 100644
83939--- a/include/linux/path.h
83940+++ b/include/linux/path.h
83941@@ -1,13 +1,15 @@
83942 #ifndef _LINUX_PATH_H
83943 #define _LINUX_PATH_H
83944
83945+#include <linux/compiler.h>
83946+
83947 struct dentry;
83948 struct vfsmount;
83949
83950 struct path {
83951 struct vfsmount *mnt;
83952 struct dentry *dentry;
83953-};
83954+} __randomize_layout;
83955
83956 extern void path_get(const struct path *);
83957 extern void path_put(const struct path *);
83958diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
83959index 2706ee9..e691f7c 100644
83960--- a/include/linux/pci_hotplug.h
83961+++ b/include/linux/pci_hotplug.h
83962@@ -71,7 +71,8 @@ struct hotplug_slot_ops {
83963 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
83964 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
83965 int (*reset_slot) (struct hotplug_slot *slot, int probe);
83966-};
83967+} __do_const;
83968+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
83969
83970 /**
83971 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
83972diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
83973index 893a0d0..d5f996e 100644
83974--- a/include/linux/perf_event.h
83975+++ b/include/linux/perf_event.h
83976@@ -341,8 +341,8 @@ struct perf_event {
83977
83978 enum perf_event_active_state state;
83979 unsigned int attach_state;
83980- local64_t count;
83981- atomic64_t child_count;
83982+ local64_t count; /* PaX: fix it one day */
83983+ atomic64_unchecked_t child_count;
83984
83985 /*
83986 * These are the total time in nanoseconds that the event
83987@@ -393,8 +393,8 @@ struct perf_event {
83988 * These accumulate total time (in nanoseconds) that children
83989 * events have been enabled and running, respectively.
83990 */
83991- atomic64_t child_total_time_enabled;
83992- atomic64_t child_total_time_running;
83993+ atomic64_unchecked_t child_total_time_enabled;
83994+ atomic64_unchecked_t child_total_time_running;
83995
83996 /*
83997 * Protect attach/detach and child_list:
83998@@ -734,7 +734,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
83999 entry->ip[entry->nr++] = ip;
84000 }
84001
84002-extern int sysctl_perf_event_paranoid;
84003+extern int sysctl_perf_event_legitimately_concerned;
84004 extern int sysctl_perf_event_mlock;
84005 extern int sysctl_perf_event_sample_rate;
84006 extern int sysctl_perf_cpu_time_max_percent;
84007@@ -749,19 +749,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
84008 loff_t *ppos);
84009
84010
84011+static inline bool perf_paranoid_any(void)
84012+{
84013+ return sysctl_perf_event_legitimately_concerned > 2;
84014+}
84015+
84016 static inline bool perf_paranoid_tracepoint_raw(void)
84017 {
84018- return sysctl_perf_event_paranoid > -1;
84019+ return sysctl_perf_event_legitimately_concerned > -1;
84020 }
84021
84022 static inline bool perf_paranoid_cpu(void)
84023 {
84024- return sysctl_perf_event_paranoid > 0;
84025+ return sysctl_perf_event_legitimately_concerned > 0;
84026 }
84027
84028 static inline bool perf_paranoid_kernel(void)
84029 {
84030- return sysctl_perf_event_paranoid > 1;
84031+ return sysctl_perf_event_legitimately_concerned > 1;
84032 }
84033
84034 extern void perf_event_init(void);
84035@@ -892,7 +897,7 @@ struct perf_pmu_events_attr {
84036 struct device_attribute attr;
84037 u64 id;
84038 const char *event_str;
84039-};
84040+} __do_const;
84041
84042 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
84043 static struct perf_pmu_events_attr _var = { \
84044diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
84045index 1997ffc..4f1f44d 100644
84046--- a/include/linux/pid_namespace.h
84047+++ b/include/linux/pid_namespace.h
84048@@ -44,7 +44,7 @@ struct pid_namespace {
84049 int hide_pid;
84050 int reboot; /* group exit code if this pidns was rebooted */
84051 unsigned int proc_inum;
84052-};
84053+} __randomize_layout;
84054
84055 extern struct pid_namespace init_pid_ns;
84056
84057diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
84058index eb8b8ac..62649e1 100644
84059--- a/include/linux/pipe_fs_i.h
84060+++ b/include/linux/pipe_fs_i.h
84061@@ -47,10 +47,10 @@ struct pipe_inode_info {
84062 struct mutex mutex;
84063 wait_queue_head_t wait;
84064 unsigned int nrbufs, curbuf, buffers;
84065- unsigned int readers;
84066- unsigned int writers;
84067- unsigned int files;
84068- unsigned int waiting_writers;
84069+ atomic_t readers;
84070+ atomic_t writers;
84071+ atomic_t files;
84072+ atomic_t waiting_writers;
84073 unsigned int r_counter;
84074 unsigned int w_counter;
84075 struct page *tmp_page;
84076diff --git a/include/linux/pm.h b/include/linux/pm.h
84077index 383fd68..7a11504 100644
84078--- a/include/linux/pm.h
84079+++ b/include/linux/pm.h
84080@@ -621,6 +621,7 @@ struct dev_pm_domain {
84081 struct dev_pm_ops ops;
84082 void (*detach)(struct device *dev, bool power_off);
84083 };
84084+typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
84085
84086 /*
84087 * The PM_EVENT_ messages are also used by drivers implementing the legacy
84088diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
84089index 2e0e06d..824cc9b 100644
84090--- a/include/linux/pm_domain.h
84091+++ b/include/linux/pm_domain.h
84092@@ -36,11 +36,11 @@ struct gpd_dev_ops {
84093 int (*save_state)(struct device *dev);
84094 int (*restore_state)(struct device *dev);
84095 bool (*active_wakeup)(struct device *dev);
84096-};
84097+} __no_const;
84098
84099 struct gpd_cpuidle_data {
84100 unsigned int saved_exit_latency;
84101- struct cpuidle_state *idle_state;
84102+ cpuidle_state_no_const *idle_state;
84103 };
84104
84105 struct generic_pm_domain {
84106diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
84107index 367f49b..d2f5a14 100644
84108--- a/include/linux/pm_runtime.h
84109+++ b/include/linux/pm_runtime.h
84110@@ -125,7 +125,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
84111
84112 static inline void pm_runtime_mark_last_busy(struct device *dev)
84113 {
84114- ACCESS_ONCE(dev->power.last_busy) = jiffies;
84115+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
84116 }
84117
84118 #else /* !CONFIG_PM_RUNTIME */
84119diff --git a/include/linux/pnp.h b/include/linux/pnp.h
84120index 195aafc..49a7bc2 100644
84121--- a/include/linux/pnp.h
84122+++ b/include/linux/pnp.h
84123@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
84124 struct pnp_fixup {
84125 char id[7];
84126 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
84127-};
84128+} __do_const;
84129
84130 /* config parameters */
84131 #define PNP_CONFIG_NORMAL 0x0001
84132diff --git a/include/linux/poison.h b/include/linux/poison.h
84133index 2110a81..13a11bb 100644
84134--- a/include/linux/poison.h
84135+++ b/include/linux/poison.h
84136@@ -19,8 +19,8 @@
84137 * under normal circumstances, used to verify that nobody uses
84138 * non-initialized list entries.
84139 */
84140-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
84141-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
84142+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
84143+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
84144
84145 /********** include/linux/timer.h **********/
84146 /*
84147diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
84148index d8b187c3..9a9257a 100644
84149--- a/include/linux/power/smartreflex.h
84150+++ b/include/linux/power/smartreflex.h
84151@@ -238,7 +238,7 @@ struct omap_sr_class_data {
84152 int (*notify)(struct omap_sr *sr, u32 status);
84153 u8 notify_flags;
84154 u8 class_type;
84155-};
84156+} __do_const;
84157
84158 /**
84159 * struct omap_sr_nvalue_table - Smartreflex n-target value info
84160diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
84161index 4ea1d37..80f4b33 100644
84162--- a/include/linux/ppp-comp.h
84163+++ b/include/linux/ppp-comp.h
84164@@ -84,7 +84,7 @@ struct compressor {
84165 struct module *owner;
84166 /* Extra skb space needed by the compressor algorithm */
84167 unsigned int comp_extra;
84168-};
84169+} __do_const;
84170
84171 /*
84172 * The return value from decompress routine is the length of the
84173diff --git a/include/linux/preempt.h b/include/linux/preempt.h
84174index de83b4e..c4b997d 100644
84175--- a/include/linux/preempt.h
84176+++ b/include/linux/preempt.h
84177@@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
84178 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
84179 #endif
84180
84181+#define raw_preempt_count_add(val) __preempt_count_add(val)
84182+#define raw_preempt_count_sub(val) __preempt_count_sub(val)
84183+
84184 #define __preempt_count_inc() __preempt_count_add(1)
84185 #define __preempt_count_dec() __preempt_count_sub(1)
84186
84187 #define preempt_count_inc() preempt_count_add(1)
84188+#define raw_preempt_count_inc() raw_preempt_count_add(1)
84189 #define preempt_count_dec() preempt_count_sub(1)
84190+#define raw_preempt_count_dec() raw_preempt_count_sub(1)
84191
84192 #ifdef CONFIG_PREEMPT_COUNT
84193
84194@@ -41,6 +46,12 @@ do { \
84195 barrier(); \
84196 } while (0)
84197
84198+#define raw_preempt_disable() \
84199+do { \
84200+ raw_preempt_count_inc(); \
84201+ barrier(); \
84202+} while (0)
84203+
84204 #define sched_preempt_enable_no_resched() \
84205 do { \
84206 barrier(); \
84207@@ -49,6 +60,12 @@ do { \
84208
84209 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
84210
84211+#define raw_preempt_enable_no_resched() \
84212+do { \
84213+ barrier(); \
84214+ raw_preempt_count_dec(); \
84215+} while (0)
84216+
84217 #ifdef CONFIG_PREEMPT
84218 #define preempt_enable() \
84219 do { \
84220@@ -113,8 +130,10 @@ do { \
84221 * region.
84222 */
84223 #define preempt_disable() barrier()
84224+#define raw_preempt_disable() barrier()
84225 #define sched_preempt_enable_no_resched() barrier()
84226 #define preempt_enable_no_resched() barrier()
84227+#define raw_preempt_enable_no_resched() barrier()
84228 #define preempt_enable() barrier()
84229 #define preempt_check_resched() do { } while (0)
84230
84231@@ -128,11 +147,13 @@ do { \
84232 /*
84233 * Modules have no business playing preemption tricks.
84234 */
84235+#ifndef CONFIG_PAX_KERNEXEC
84236 #undef sched_preempt_enable_no_resched
84237 #undef preempt_enable_no_resched
84238 #undef preempt_enable_no_resched_notrace
84239 #undef preempt_check_resched
84240 #endif
84241+#endif
84242
84243 #define preempt_set_need_resched() \
84244 do { \
84245diff --git a/include/linux/printk.h b/include/linux/printk.h
84246index d78125f..7f36596 100644
84247--- a/include/linux/printk.h
84248+++ b/include/linux/printk.h
84249@@ -124,6 +124,8 @@ static inline __printf(1, 2) __cold
84250 void early_printk(const char *s, ...) { }
84251 #endif
84252
84253+extern int kptr_restrict;
84254+
84255 #ifdef CONFIG_PRINTK
84256 asmlinkage __printf(5, 0)
84257 int vprintk_emit(int facility, int level,
84258@@ -158,7 +160,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
84259
84260 extern int printk_delay_msec;
84261 extern int dmesg_restrict;
84262-extern int kptr_restrict;
84263
84264 extern void wake_up_klogd(void);
84265
84266diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
84267index b97bf2e..f14c92d4 100644
84268--- a/include/linux/proc_fs.h
84269+++ b/include/linux/proc_fs.h
84270@@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
84271 extern struct proc_dir_entry *proc_symlink(const char *,
84272 struct proc_dir_entry *, const char *);
84273 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
84274+extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
84275 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
84276 struct proc_dir_entry *, void *);
84277+extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
84278+ struct proc_dir_entry *, void *);
84279 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
84280 struct proc_dir_entry *);
84281
84282@@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
84283 return proc_create_data(name, mode, parent, proc_fops, NULL);
84284 }
84285
84286+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
84287+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
84288+{
84289+#ifdef CONFIG_GRKERNSEC_PROC_USER
84290+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
84291+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
84292+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
84293+#else
84294+ return proc_create_data(name, mode, parent, proc_fops, NULL);
84295+#endif
84296+}
84297+
84298+
84299 extern void proc_set_size(struct proc_dir_entry *, loff_t);
84300 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
84301 extern void *PDE_DATA(const struct inode *);
84302@@ -56,8 +72,12 @@ static inline struct proc_dir_entry *proc_symlink(const char *name,
84303 struct proc_dir_entry *parent,const char *dest) { return NULL;}
84304 static inline struct proc_dir_entry *proc_mkdir(const char *name,
84305 struct proc_dir_entry *parent) {return NULL;}
84306+static inline struct proc_dir_entry *proc_mkdir_restrict(const char *name,
84307+ struct proc_dir_entry *parent) { return NULL; }
84308 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
84309 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
84310+static inline struct proc_dir_entry *proc_mkdir_data_restrict(const char *name,
84311+ umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
84312 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
84313 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
84314 #define proc_create(name, mode, parent, proc_fops) ({NULL;})
84315@@ -79,7 +99,7 @@ struct net;
84316 static inline struct proc_dir_entry *proc_net_mkdir(
84317 struct net *net, const char *name, struct proc_dir_entry *parent)
84318 {
84319- return proc_mkdir_data(name, 0, parent, net);
84320+ return proc_mkdir_data_restrict(name, 0, parent, net);
84321 }
84322
84323 #endif /* _LINUX_PROC_FS_H */
84324diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
84325index 34a1e10..70f6bde 100644
84326--- a/include/linux/proc_ns.h
84327+++ b/include/linux/proc_ns.h
84328@@ -14,7 +14,7 @@ struct proc_ns_operations {
84329 void (*put)(void *ns);
84330 int (*install)(struct nsproxy *nsproxy, void *ns);
84331 unsigned int (*inum)(void *ns);
84332-};
84333+} __do_const __randomize_layout;
84334
84335 struct proc_ns {
84336 void *ns;
84337diff --git a/include/linux/quota.h b/include/linux/quota.h
84338index 80d345a..9e89a9a 100644
84339--- a/include/linux/quota.h
84340+++ b/include/linux/quota.h
84341@@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
84342
84343 extern bool qid_eq(struct kqid left, struct kqid right);
84344 extern bool qid_lt(struct kqid left, struct kqid right);
84345-extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
84346+extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
84347 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
84348 extern bool qid_valid(struct kqid qid);
84349
84350diff --git a/include/linux/random.h b/include/linux/random.h
84351index b05856e..0a9f14e 100644
84352--- a/include/linux/random.h
84353+++ b/include/linux/random.h
84354@@ -9,9 +9,19 @@
84355 #include <uapi/linux/random.h>
84356
84357 extern void add_device_randomness(const void *, unsigned int);
84358+
84359+static inline void add_latent_entropy(void)
84360+{
84361+
84362+#ifdef LATENT_ENTROPY_PLUGIN
84363+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
84364+#endif
84365+
84366+}
84367+
84368 extern void add_input_randomness(unsigned int type, unsigned int code,
84369- unsigned int value);
84370-extern void add_interrupt_randomness(int irq, int irq_flags);
84371+ unsigned int value) __latent_entropy;
84372+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
84373
84374 extern void get_random_bytes(void *buf, int nbytes);
84375 extern void get_random_bytes_arch(void *buf, int nbytes);
84376@@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
84377 extern const struct file_operations random_fops, urandom_fops;
84378 #endif
84379
84380-unsigned int get_random_int(void);
84381+unsigned int __intentional_overflow(-1) get_random_int(void);
84382 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
84383
84384-u32 prandom_u32(void);
84385+u32 prandom_u32(void) __intentional_overflow(-1);
84386 void prandom_bytes(void *buf, size_t nbytes);
84387 void prandom_seed(u32 seed);
84388 void prandom_reseed_late(void);
84389@@ -37,6 +47,11 @@ struct rnd_state {
84390 u32 prandom_u32_state(struct rnd_state *state);
84391 void prandom_bytes_state(struct rnd_state *state, void *buf, size_t nbytes);
84392
84393+static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
84394+{
84395+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
84396+}
84397+
84398 /**
84399 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
84400 * @ep_ro: right open interval endpoint
84401@@ -49,7 +64,7 @@ void prandom_bytes_state(struct rnd_state *state, void *buf, size_t nbytes);
84402 *
84403 * Returns: pseudo-random number in interval [0, ep_ro)
84404 */
84405-static inline u32 prandom_u32_max(u32 ep_ro)
84406+static inline u32 __intentional_overflow(-1) prandom_u32_max(u32 ep_ro)
84407 {
84408 return (u32)(((u64) prandom_u32() * ep_ro) >> 32);
84409 }
84410diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
84411index 378c5ee..aa84a47 100644
84412--- a/include/linux/rbtree_augmented.h
84413+++ b/include/linux/rbtree_augmented.h
84414@@ -90,7 +90,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
84415 old->rbaugmented = rbcompute(old); \
84416 } \
84417 rbstatic const struct rb_augment_callbacks rbname = { \
84418- rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
84419+ .propagate = rbname ## _propagate, \
84420+ .copy = rbname ## _copy, \
84421+ .rotate = rbname ## _rotate \
84422 };
84423
84424
84425diff --git a/include/linux/rculist.h b/include/linux/rculist.h
84426index 372ad5e..d4373f8 100644
84427--- a/include/linux/rculist.h
84428+++ b/include/linux/rculist.h
84429@@ -29,8 +29,8 @@
84430 */
84431 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
84432 {
84433- ACCESS_ONCE(list->next) = list;
84434- ACCESS_ONCE(list->prev) = list;
84435+ ACCESS_ONCE_RW(list->next) = list;
84436+ ACCESS_ONCE_RW(list->prev) = list;
84437 }
84438
84439 /*
84440@@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
84441 struct list_head *prev, struct list_head *next);
84442 #endif
84443
84444+void __pax_list_add_rcu(struct list_head *new,
84445+ struct list_head *prev, struct list_head *next);
84446+
84447 /**
84448 * list_add_rcu - add a new entry to rcu-protected list
84449 * @new: new entry to be added
84450@@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
84451 __list_add_rcu(new, head, head->next);
84452 }
84453
84454+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
84455+{
84456+ __pax_list_add_rcu(new, head, head->next);
84457+}
84458+
84459 /**
84460 * list_add_tail_rcu - add a new entry to rcu-protected list
84461 * @new: new entry to be added
84462@@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
84463 __list_add_rcu(new, head->prev, head);
84464 }
84465
84466+static inline void pax_list_add_tail_rcu(struct list_head *new,
84467+ struct list_head *head)
84468+{
84469+ __pax_list_add_rcu(new, head->prev, head);
84470+}
84471+
84472 /**
84473 * list_del_rcu - deletes entry from list without re-initialization
84474 * @entry: the element to delete from the list.
84475@@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
84476 entry->prev = LIST_POISON2;
84477 }
84478
84479+extern void pax_list_del_rcu(struct list_head *entry);
84480+
84481 /**
84482 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
84483 * @n: the element to delete from the hash list.
84484diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
84485index 53ff1a7..c40f0ab 100644
84486--- a/include/linux/rcupdate.h
84487+++ b/include/linux/rcupdate.h
84488@@ -332,7 +332,7 @@ extern struct srcu_struct tasks_rcu_exit_srcu;
84489 #define rcu_note_voluntary_context_switch(t) \
84490 do { \
84491 if (ACCESS_ONCE((t)->rcu_tasks_holdout)) \
84492- ACCESS_ONCE((t)->rcu_tasks_holdout) = false; \
84493+ ACCESS_ONCE_RW((t)->rcu_tasks_holdout) = false; \
84494 } while (0)
84495 #else /* #ifdef CONFIG_TASKS_RCU */
84496 #define TASKS_RCU(x) do { } while (0)
84497diff --git a/include/linux/reboot.h b/include/linux/reboot.h
84498index 67fc8fc..a90f7d8 100644
84499--- a/include/linux/reboot.h
84500+++ b/include/linux/reboot.h
84501@@ -47,9 +47,9 @@ extern void do_kernel_restart(char *cmd);
84502 */
84503
84504 extern void migrate_to_reboot_cpu(void);
84505-extern void machine_restart(char *cmd);
84506-extern void machine_halt(void);
84507-extern void machine_power_off(void);
84508+extern void machine_restart(char *cmd) __noreturn;
84509+extern void machine_halt(void) __noreturn;
84510+extern void machine_power_off(void) __noreturn;
84511
84512 extern void machine_shutdown(void);
84513 struct pt_regs;
84514@@ -60,9 +60,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
84515 */
84516
84517 extern void kernel_restart_prepare(char *cmd);
84518-extern void kernel_restart(char *cmd);
84519-extern void kernel_halt(void);
84520-extern void kernel_power_off(void);
84521+extern void kernel_restart(char *cmd) __noreturn;
84522+extern void kernel_halt(void) __noreturn;
84523+extern void kernel_power_off(void) __noreturn;
84524
84525 extern int C_A_D; /* for sysctl */
84526 void ctrl_alt_del(void);
84527@@ -76,7 +76,7 @@ extern int orderly_poweroff(bool force);
84528 * Emergency restart, callable from an interrupt handler.
84529 */
84530
84531-extern void emergency_restart(void);
84532+extern void emergency_restart(void) __noreturn;
84533 #include <asm/emergency-restart.h>
84534
84535 #endif /* _LINUX_REBOOT_H */
84536diff --git a/include/linux/regset.h b/include/linux/regset.h
84537index 8e0c9fe..ac4d221 100644
84538--- a/include/linux/regset.h
84539+++ b/include/linux/regset.h
84540@@ -161,7 +161,8 @@ struct user_regset {
84541 unsigned int align;
84542 unsigned int bias;
84543 unsigned int core_note_type;
84544-};
84545+} __do_const;
84546+typedef struct user_regset __no_const user_regset_no_const;
84547
84548 /**
84549 * struct user_regset_view - available regsets
84550diff --git a/include/linux/relay.h b/include/linux/relay.h
84551index d7c8359..818daf5 100644
84552--- a/include/linux/relay.h
84553+++ b/include/linux/relay.h
84554@@ -157,7 +157,7 @@ struct rchan_callbacks
84555 * The callback should return 0 if successful, negative if not.
84556 */
84557 int (*remove_buf_file)(struct dentry *dentry);
84558-};
84559+} __no_const;
84560
84561 /*
84562 * CONFIG_RELAY kernel API, kernel/relay.c
84563diff --git a/include/linux/rio.h b/include/linux/rio.h
84564index 6bda06f..bf39a9b 100644
84565--- a/include/linux/rio.h
84566+++ b/include/linux/rio.h
84567@@ -358,7 +358,7 @@ struct rio_ops {
84568 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
84569 u64 rstart, u32 size, u32 flags);
84570 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
84571-};
84572+} __no_const;
84573
84574 #define RIO_RESOURCE_MEM 0x00000100
84575 #define RIO_RESOURCE_DOORBELL 0x00000200
84576diff --git a/include/linux/rmap.h b/include/linux/rmap.h
84577index c0c2bce..4813524 100644
84578--- a/include/linux/rmap.h
84579+++ b/include/linux/rmap.h
84580@@ -144,8 +144,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
84581 void anon_vma_init(void); /* create anon_vma_cachep */
84582 int anon_vma_prepare(struct vm_area_struct *);
84583 void unlink_anon_vmas(struct vm_area_struct *);
84584-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
84585-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
84586+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
84587+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
84588
84589 static inline void anon_vma_merge(struct vm_area_struct *vma,
84590 struct vm_area_struct *next)
84591diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
84592index ed8f9e7..999bc96 100644
84593--- a/include/linux/scatterlist.h
84594+++ b/include/linux/scatterlist.h
84595@@ -1,6 +1,7 @@
84596 #ifndef _LINUX_SCATTERLIST_H
84597 #define _LINUX_SCATTERLIST_H
84598
84599+#include <linux/sched.h>
84600 #include <linux/string.h>
84601 #include <linux/bug.h>
84602 #include <linux/mm.h>
84603@@ -114,6 +115,12 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
84604 #ifdef CONFIG_DEBUG_SG
84605 BUG_ON(!virt_addr_valid(buf));
84606 #endif
84607+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
84608+ if (object_starts_on_stack(buf)) {
84609+ void *adjbuf = buf - current->stack + current->lowmem_stack;
84610+ sg_set_page(sg, virt_to_page(adjbuf), buflen, offset_in_page(adjbuf));
84611+ } else
84612+#endif
84613 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
84614 }
84615
84616diff --git a/include/linux/sched.h b/include/linux/sched.h
84617index 5e344bb..0743255 100644
84618--- a/include/linux/sched.h
84619+++ b/include/linux/sched.h
84620@@ -133,6 +133,7 @@ struct fs_struct;
84621 struct perf_event_context;
84622 struct blk_plug;
84623 struct filename;
84624+struct linux_binprm;
84625
84626 #define VMACACHE_BITS 2
84627 #define VMACACHE_SIZE (1U << VMACACHE_BITS)
84628@@ -376,7 +377,7 @@ extern char __sched_text_start[], __sched_text_end[];
84629 extern int in_sched_functions(unsigned long addr);
84630
84631 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
84632-extern signed long schedule_timeout(signed long timeout);
84633+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
84634 extern signed long schedule_timeout_interruptible(signed long timeout);
84635 extern signed long schedule_timeout_killable(signed long timeout);
84636 extern signed long schedule_timeout_uninterruptible(signed long timeout);
84637@@ -387,6 +388,19 @@ struct nsproxy;
84638 struct user_namespace;
84639
84640 #ifdef CONFIG_MMU
84641+
84642+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
84643+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
84644+#else
84645+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
84646+{
84647+ return 0;
84648+}
84649+#endif
84650+
84651+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
84652+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
84653+
84654 extern void arch_pick_mmap_layout(struct mm_struct *mm);
84655 extern unsigned long
84656 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
84657@@ -685,6 +699,17 @@ struct signal_struct {
84658 #ifdef CONFIG_TASKSTATS
84659 struct taskstats *stats;
84660 #endif
84661+
84662+#ifdef CONFIG_GRKERNSEC
84663+ u32 curr_ip;
84664+ u32 saved_ip;
84665+ u32 gr_saddr;
84666+ u32 gr_daddr;
84667+ u16 gr_sport;
84668+ u16 gr_dport;
84669+ u8 used_accept:1;
84670+#endif
84671+
84672 #ifdef CONFIG_AUDIT
84673 unsigned audit_tty;
84674 unsigned audit_tty_log_passwd;
84675@@ -711,7 +736,7 @@ struct signal_struct {
84676 struct mutex cred_guard_mutex; /* guard against foreign influences on
84677 * credential calculations
84678 * (notably. ptrace) */
84679-};
84680+} __randomize_layout;
84681
84682 /*
84683 * Bits in flags field of signal_struct.
84684@@ -764,6 +789,14 @@ struct user_struct {
84685 struct key *session_keyring; /* UID's default session keyring */
84686 #endif
84687
84688+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
84689+ unsigned char kernel_banned;
84690+#endif
84691+#ifdef CONFIG_GRKERNSEC_BRUTE
84692+ unsigned char suid_banned;
84693+ unsigned long suid_ban_expires;
84694+#endif
84695+
84696 /* Hash table maintenance information */
84697 struct hlist_node uidhash_node;
84698 kuid_t uid;
84699@@ -771,7 +804,7 @@ struct user_struct {
84700 #ifdef CONFIG_PERF_EVENTS
84701 atomic_long_t locked_vm;
84702 #endif
84703-};
84704+} __randomize_layout;
84705
84706 extern int uids_sysfs_init(void);
84707
84708@@ -1235,6 +1268,9 @@ enum perf_event_task_context {
84709 struct task_struct {
84710 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
84711 void *stack;
84712+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
84713+ void *lowmem_stack;
84714+#endif
84715 atomic_t usage;
84716 unsigned int flags; /* per process flags, defined below */
84717 unsigned int ptrace;
84718@@ -1362,8 +1398,8 @@ struct task_struct {
84719 struct list_head thread_node;
84720
84721 struct completion *vfork_done; /* for vfork() */
84722- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
84723- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
84724+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
84725+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
84726
84727 cputime_t utime, stime, utimescaled, stimescaled;
84728 cputime_t gtime;
84729@@ -1388,11 +1424,6 @@ struct task_struct {
84730 struct task_cputime cputime_expires;
84731 struct list_head cpu_timers[3];
84732
84733-/* process credentials */
84734- const struct cred __rcu *real_cred; /* objective and real subjective task
84735- * credentials (COW) */
84736- const struct cred __rcu *cred; /* effective (overridable) subjective task
84737- * credentials (COW) */
84738 char comm[TASK_COMM_LEN]; /* executable name excluding path
84739 - access with [gs]et_task_comm (which lock
84740 it with task_lock())
84741@@ -1410,6 +1441,10 @@ struct task_struct {
84742 #endif
84743 /* CPU-specific state of this task */
84744 struct thread_struct thread;
84745+/* thread_info moved to task_struct */
84746+#ifdef CONFIG_X86
84747+ struct thread_info tinfo;
84748+#endif
84749 /* filesystem information */
84750 struct fs_struct *fs;
84751 /* open file information */
84752@@ -1484,6 +1519,10 @@ struct task_struct {
84753 gfp_t lockdep_reclaim_gfp;
84754 #endif
84755
84756+/* process credentials */
84757+ const struct cred __rcu *real_cred; /* objective and real subjective task
84758+ * credentials (COW) */
84759+
84760 /* journalling filesystem info */
84761 void *journal_info;
84762
84763@@ -1522,6 +1561,10 @@ struct task_struct {
84764 /* cg_list protected by css_set_lock and tsk->alloc_lock */
84765 struct list_head cg_list;
84766 #endif
84767+
84768+ const struct cred __rcu *cred; /* effective (overridable) subjective task
84769+ * credentials (COW) */
84770+
84771 #ifdef CONFIG_FUTEX
84772 struct robust_list_head __user *robust_list;
84773 #ifdef CONFIG_COMPAT
84774@@ -1635,7 +1678,7 @@ struct task_struct {
84775 * Number of functions that haven't been traced
84776 * because of depth overrun.
84777 */
84778- atomic_t trace_overrun;
84779+ atomic_unchecked_t trace_overrun;
84780 /* Pause for the tracing */
84781 atomic_t tracing_graph_pause;
84782 #endif
84783@@ -1661,7 +1704,78 @@ struct task_struct {
84784 unsigned int sequential_io;
84785 unsigned int sequential_io_avg;
84786 #endif
84787-};
84788+
84789+#ifdef CONFIG_GRKERNSEC
84790+ /* grsecurity */
84791+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
84792+ u64 exec_id;
84793+#endif
84794+#ifdef CONFIG_GRKERNSEC_SETXID
84795+ const struct cred *delayed_cred;
84796+#endif
84797+ struct dentry *gr_chroot_dentry;
84798+ struct acl_subject_label *acl;
84799+ struct acl_subject_label *tmpacl;
84800+ struct acl_role_label *role;
84801+ struct file *exec_file;
84802+ unsigned long brute_expires;
84803+ u16 acl_role_id;
84804+ u8 inherited;
84805+ /* is this the task that authenticated to the special role */
84806+ u8 acl_sp_role;
84807+ u8 is_writable;
84808+ u8 brute;
84809+ u8 gr_is_chrooted;
84810+#endif
84811+
84812+} __randomize_layout;
84813+
84814+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
84815+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
84816+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
84817+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
84818+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
84819+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
84820+
84821+#ifdef CONFIG_PAX_SOFTMODE
84822+extern int pax_softmode;
84823+#endif
84824+
84825+extern int pax_check_flags(unsigned long *);
84826+#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
84827+
84828+/* if tsk != current then task_lock must be held on it */
84829+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
84830+static inline unsigned long pax_get_flags(struct task_struct *tsk)
84831+{
84832+ if (likely(tsk->mm))
84833+ return tsk->mm->pax_flags;
84834+ else
84835+ return 0UL;
84836+}
84837+
84838+/* if tsk != current then task_lock must be held on it */
84839+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
84840+{
84841+ if (likely(tsk->mm)) {
84842+ tsk->mm->pax_flags = flags;
84843+ return 0;
84844+ }
84845+ return -EINVAL;
84846+}
84847+#endif
84848+
84849+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
84850+extern void pax_set_initial_flags(struct linux_binprm *bprm);
84851+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
84852+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
84853+#endif
84854+
84855+struct path;
84856+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
84857+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
84858+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
84859+extern void pax_report_refcount_overflow(struct pt_regs *regs);
84860
84861 /* Future-safe accessor for struct task_struct's cpus_allowed. */
84862 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
84863@@ -1743,7 +1857,7 @@ struct pid_namespace;
84864 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
84865 struct pid_namespace *ns);
84866
84867-static inline pid_t task_pid_nr(struct task_struct *tsk)
84868+static inline pid_t task_pid_nr(const struct task_struct *tsk)
84869 {
84870 return tsk->pid;
84871 }
84872@@ -2106,6 +2220,25 @@ extern u64 sched_clock_cpu(int cpu);
84873
84874 extern void sched_clock_init(void);
84875
84876+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
84877+static inline void populate_stack(void)
84878+{
84879+ struct task_struct *curtask = current;
84880+ int c;
84881+ int *ptr = curtask->stack;
84882+ int *end = curtask->stack + THREAD_SIZE;
84883+
84884+ while (ptr < end) {
84885+ c = *(volatile int *)ptr;
84886+ ptr += PAGE_SIZE/sizeof(int);
84887+ }
84888+}
84889+#else
84890+static inline void populate_stack(void)
84891+{
84892+}
84893+#endif
84894+
84895 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
84896 static inline void sched_clock_tick(void)
84897 {
84898@@ -2239,7 +2372,9 @@ void yield(void);
84899 extern struct exec_domain default_exec_domain;
84900
84901 union thread_union {
84902+#ifndef CONFIG_X86
84903 struct thread_info thread_info;
84904+#endif
84905 unsigned long stack[THREAD_SIZE/sizeof(long)];
84906 };
84907
84908@@ -2272,6 +2407,7 @@ extern struct pid_namespace init_pid_ns;
84909 */
84910
84911 extern struct task_struct *find_task_by_vpid(pid_t nr);
84912+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
84913 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
84914 struct pid_namespace *ns);
84915
84916@@ -2436,7 +2572,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
84917 extern void exit_itimers(struct signal_struct *);
84918 extern void flush_itimer_signals(void);
84919
84920-extern void do_group_exit(int);
84921+extern __noreturn void do_group_exit(int);
84922
84923 extern int do_execve(struct filename *,
84924 const char __user * const __user *,
84925@@ -2653,9 +2789,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
84926 #define task_stack_end_corrupted(task) \
84927 (*(end_of_stack(task)) != STACK_END_MAGIC)
84928
84929-static inline int object_is_on_stack(void *obj)
84930+static inline int object_starts_on_stack(const void *obj)
84931 {
84932- void *stack = task_stack_page(current);
84933+ const void *stack = task_stack_page(current);
84934
84935 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
84936 }
84937diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
84938index 596a0e0..bea77ec 100644
84939--- a/include/linux/sched/sysctl.h
84940+++ b/include/linux/sched/sysctl.h
84941@@ -34,6 +34,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
84942 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
84943
84944 extern int sysctl_max_map_count;
84945+extern unsigned long sysctl_heap_stack_gap;
84946
84947 extern unsigned int sysctl_sched_latency;
84948 extern unsigned int sysctl_sched_min_granularity;
84949diff --git a/include/linux/security.h b/include/linux/security.h
84950index ba96471..74fb3f6 100644
84951--- a/include/linux/security.h
84952+++ b/include/linux/security.h
84953@@ -27,6 +27,7 @@
84954 #include <linux/slab.h>
84955 #include <linux/err.h>
84956 #include <linux/string.h>
84957+#include <linux/grsecurity.h>
84958
84959 struct linux_binprm;
84960 struct cred;
84961@@ -116,8 +117,6 @@ struct seq_file;
84962
84963 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
84964
84965-void reset_security_ops(void);
84966-
84967 #ifdef CONFIG_MMU
84968 extern unsigned long mmap_min_addr;
84969 extern unsigned long dac_mmap_min_addr;
84970@@ -1729,7 +1728,7 @@ struct security_operations {
84971 struct audit_context *actx);
84972 void (*audit_rule_free) (void *lsmrule);
84973 #endif /* CONFIG_AUDIT */
84974-};
84975+} __randomize_layout;
84976
84977 /* prototypes */
84978 extern int security_init(void);
84979diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
84980index dc368b8..e895209 100644
84981--- a/include/linux/semaphore.h
84982+++ b/include/linux/semaphore.h
84983@@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
84984 }
84985
84986 extern void down(struct semaphore *sem);
84987-extern int __must_check down_interruptible(struct semaphore *sem);
84988+extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
84989 extern int __must_check down_killable(struct semaphore *sem);
84990 extern int __must_check down_trylock(struct semaphore *sem);
84991 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
84992diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
84993index 52e0097..383f21d 100644
84994--- a/include/linux/seq_file.h
84995+++ b/include/linux/seq_file.h
84996@@ -27,6 +27,9 @@ struct seq_file {
84997 struct mutex lock;
84998 const struct seq_operations *op;
84999 int poll_event;
85000+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
85001+ u64 exec_id;
85002+#endif
85003 #ifdef CONFIG_USER_NS
85004 struct user_namespace *user_ns;
85005 #endif
85006@@ -39,6 +42,7 @@ struct seq_operations {
85007 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
85008 int (*show) (struct seq_file *m, void *v);
85009 };
85010+typedef struct seq_operations __no_const seq_operations_no_const;
85011
85012 #define SEQ_SKIP 1
85013
85014@@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
85015
85016 char *mangle_path(char *s, const char *p, const char *esc);
85017 int seq_open(struct file *, const struct seq_operations *);
85018+int seq_open_restrict(struct file *, const struct seq_operations *);
85019 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
85020 loff_t seq_lseek(struct file *, loff_t, int);
85021 int seq_release(struct inode *, struct file *);
85022@@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
85023 }
85024
85025 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
85026+int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
85027 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
85028 int single_release(struct inode *, struct file *);
85029 void *__seq_open_private(struct file *, const struct seq_operations *, int);
85030diff --git a/include/linux/shm.h b/include/linux/shm.h
85031index 6fb8016..ab4465e 100644
85032--- a/include/linux/shm.h
85033+++ b/include/linux/shm.h
85034@@ -22,6 +22,10 @@ struct shmid_kernel /* private to the kernel */
85035 /* The task created the shm object. NULL if the task is dead. */
85036 struct task_struct *shm_creator;
85037 struct list_head shm_clist; /* list by creator */
85038+#ifdef CONFIG_GRKERNSEC
85039+ u64 shm_createtime;
85040+ pid_t shm_lapid;
85041+#endif
85042 };
85043
85044 /* shm_mode upper byte flags */
85045diff --git a/include/linux/signal.h b/include/linux/signal.h
85046index ab1e039..ad4229e 100644
85047--- a/include/linux/signal.h
85048+++ b/include/linux/signal.h
85049@@ -289,7 +289,7 @@ static inline void allow_signal(int sig)
85050 * know it'll be handled, so that they don't get converted to
85051 * SIGKILL or just silently dropped.
85052 */
85053- kernel_sigaction(sig, (__force __sighandler_t)2);
85054+ kernel_sigaction(sig, (__force_user __sighandler_t)2);
85055 }
85056
85057 static inline void disallow_signal(int sig)
85058diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
85059index 6c8b6f6..5a0f4bd 100644
85060--- a/include/linux/skbuff.h
85061+++ b/include/linux/skbuff.h
85062@@ -773,7 +773,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
85063 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
85064 int node);
85065 struct sk_buff *build_skb(void *data, unsigned int frag_size);
85066-static inline struct sk_buff *alloc_skb(unsigned int size,
85067+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
85068 gfp_t priority)
85069 {
85070 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
85071@@ -1962,7 +1962,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
85072 return skb->inner_transport_header - skb->inner_network_header;
85073 }
85074
85075-static inline int skb_network_offset(const struct sk_buff *skb)
85076+static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
85077 {
85078 return skb_network_header(skb) - skb->data;
85079 }
85080@@ -2022,7 +2022,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
85081 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
85082 */
85083 #ifndef NET_SKB_PAD
85084-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
85085+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
85086 #endif
85087
85088 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
85089@@ -2629,7 +2629,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
85090 int *err);
85091 unsigned int datagram_poll(struct file *file, struct socket *sock,
85092 struct poll_table_struct *wait);
85093-int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
85094+int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
85095 struct iovec *to, int size);
85096 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
85097 struct iovec *iov);
85098@@ -3091,6 +3091,9 @@ static inline void nf_reset(struct sk_buff *skb)
85099 nf_bridge_put(skb->nf_bridge);
85100 skb->nf_bridge = NULL;
85101 #endif
85102+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
85103+ skb->nf_trace = 0;
85104+#endif
85105 }
85106
85107 static inline void nf_reset_trace(struct sk_buff *skb)
85108diff --git a/include/linux/slab.h b/include/linux/slab.h
85109index c265bec..4867d28 100644
85110--- a/include/linux/slab.h
85111+++ b/include/linux/slab.h
85112@@ -14,15 +14,29 @@
85113 #include <linux/gfp.h>
85114 #include <linux/types.h>
85115 #include <linux/workqueue.h>
85116-
85117+#include <linux/err.h>
85118
85119 /*
85120 * Flags to pass to kmem_cache_create().
85121 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
85122 */
85123 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
85124+
85125+#ifdef CONFIG_PAX_USERCOPY_SLABS
85126+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
85127+#else
85128+#define SLAB_USERCOPY 0x00000000UL
85129+#endif
85130+
85131 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
85132 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
85133+
85134+#ifdef CONFIG_PAX_MEMORY_SANITIZE
85135+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
85136+#else
85137+#define SLAB_NO_SANITIZE 0x00000000UL
85138+#endif
85139+
85140 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
85141 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
85142 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
85143@@ -98,10 +112,13 @@
85144 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
85145 * Both make kfree a no-op.
85146 */
85147-#define ZERO_SIZE_PTR ((void *)16)
85148+#define ZERO_SIZE_PTR \
85149+({ \
85150+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
85151+ (void *)(-MAX_ERRNO-1L); \
85152+})
85153
85154-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
85155- (unsigned long)ZERO_SIZE_PTR)
85156+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
85157
85158 #include <linux/kmemleak.h>
85159
85160@@ -144,6 +161,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
85161 void kfree(const void *);
85162 void kzfree(const void *);
85163 size_t ksize(const void *);
85164+const char *check_heap_object(const void *ptr, unsigned long n);
85165+bool is_usercopy_object(const void *ptr);
85166
85167 /*
85168 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
85169@@ -236,6 +255,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
85170 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
85171 #endif
85172
85173+#ifdef CONFIG_PAX_USERCOPY_SLABS
85174+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
85175+#endif
85176+
85177 /*
85178 * Figure out which kmalloc slab an allocation of a certain size
85179 * belongs to.
85180@@ -244,7 +267,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
85181 * 2 = 120 .. 192 bytes
85182 * n = 2^(n-1) .. 2^n -1
85183 */
85184-static __always_inline int kmalloc_index(size_t size)
85185+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
85186 {
85187 if (!size)
85188 return 0;
85189@@ -287,11 +310,11 @@ static __always_inline int kmalloc_index(size_t size)
85190 }
85191 #endif /* !CONFIG_SLOB */
85192
85193-void *__kmalloc(size_t size, gfp_t flags);
85194+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
85195 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
85196
85197 #ifdef CONFIG_NUMA
85198-void *__kmalloc_node(size_t size, gfp_t flags, int node);
85199+void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
85200 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
85201 #else
85202 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
85203diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
85204index b869d16..1453c73 100644
85205--- a/include/linux/slab_def.h
85206+++ b/include/linux/slab_def.h
85207@@ -40,7 +40,7 @@ struct kmem_cache {
85208 /* 4) cache creation/removal */
85209 const char *name;
85210 struct list_head list;
85211- int refcount;
85212+ atomic_t refcount;
85213 int object_size;
85214 int align;
85215
85216@@ -56,10 +56,14 @@ struct kmem_cache {
85217 unsigned long node_allocs;
85218 unsigned long node_frees;
85219 unsigned long node_overflow;
85220- atomic_t allochit;
85221- atomic_t allocmiss;
85222- atomic_t freehit;
85223- atomic_t freemiss;
85224+ atomic_unchecked_t allochit;
85225+ atomic_unchecked_t allocmiss;
85226+ atomic_unchecked_t freehit;
85227+ atomic_unchecked_t freemiss;
85228+#ifdef CONFIG_PAX_MEMORY_SANITIZE
85229+ atomic_unchecked_t sanitized;
85230+ atomic_unchecked_t not_sanitized;
85231+#endif
85232
85233 /*
85234 * If debugging is enabled, then the allocator can add additional
85235diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
85236index d82abd4..408c3a0 100644
85237--- a/include/linux/slub_def.h
85238+++ b/include/linux/slub_def.h
85239@@ -74,7 +74,7 @@ struct kmem_cache {
85240 struct kmem_cache_order_objects max;
85241 struct kmem_cache_order_objects min;
85242 gfp_t allocflags; /* gfp flags to use on each alloc */
85243- int refcount; /* Refcount for slab cache destroy */
85244+ atomic_t refcount; /* Refcount for slab cache destroy */
85245 void (*ctor)(void *);
85246 int inuse; /* Offset to metadata */
85247 int align; /* Alignment */
85248diff --git a/include/linux/smp.h b/include/linux/smp.h
85249index 93dff5f..933c561 100644
85250--- a/include/linux/smp.h
85251+++ b/include/linux/smp.h
85252@@ -176,7 +176,9 @@ static inline void wake_up_all_idle_cpus(void) { }
85253 #endif
85254
85255 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
85256+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
85257 #define put_cpu() preempt_enable()
85258+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
85259
85260 /*
85261 * Callback to arch code if there's nosmp or maxcpus=0 on the
85262diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
85263index 46cca4c..3323536 100644
85264--- a/include/linux/sock_diag.h
85265+++ b/include/linux/sock_diag.h
85266@@ -11,7 +11,7 @@ struct sock;
85267 struct sock_diag_handler {
85268 __u8 family;
85269 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
85270-};
85271+} __do_const;
85272
85273 int sock_diag_register(const struct sock_diag_handler *h);
85274 void sock_diag_unregister(const struct sock_diag_handler *h);
85275diff --git a/include/linux/sonet.h b/include/linux/sonet.h
85276index 680f9a3..f13aeb0 100644
85277--- a/include/linux/sonet.h
85278+++ b/include/linux/sonet.h
85279@@ -7,7 +7,7 @@
85280 #include <uapi/linux/sonet.h>
85281
85282 struct k_sonet_stats {
85283-#define __HANDLE_ITEM(i) atomic_t i
85284+#define __HANDLE_ITEM(i) atomic_unchecked_t i
85285 __SONET_ITEMS
85286 #undef __HANDLE_ITEM
85287 };
85288diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
85289index 07d8e53..dc934c9 100644
85290--- a/include/linux/sunrpc/addr.h
85291+++ b/include/linux/sunrpc/addr.h
85292@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
85293 {
85294 switch (sap->sa_family) {
85295 case AF_INET:
85296- return ntohs(((struct sockaddr_in *)sap)->sin_port);
85297+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
85298 case AF_INET6:
85299- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
85300+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
85301 }
85302 return 0;
85303 }
85304@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
85305 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
85306 const struct sockaddr *src)
85307 {
85308- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
85309+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
85310 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
85311
85312 dsin->sin_family = ssin->sin_family;
85313@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
85314 if (sa->sa_family != AF_INET6)
85315 return 0;
85316
85317- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
85318+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
85319 }
85320
85321 #endif /* _LINUX_SUNRPC_ADDR_H */
85322diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
85323index 70736b9..37f33db 100644
85324--- a/include/linux/sunrpc/clnt.h
85325+++ b/include/linux/sunrpc/clnt.h
85326@@ -97,7 +97,7 @@ struct rpc_procinfo {
85327 unsigned int p_timer; /* Which RTT timer to use */
85328 u32 p_statidx; /* Which procedure to account */
85329 const char * p_name; /* name of procedure */
85330-};
85331+} __do_const;
85332
85333 #ifdef __KERNEL__
85334
85335diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
85336index 2167846..0648fc3 100644
85337--- a/include/linux/sunrpc/svc.h
85338+++ b/include/linux/sunrpc/svc.h
85339@@ -416,7 +416,7 @@ struct svc_procedure {
85340 unsigned int pc_count; /* call count */
85341 unsigned int pc_cachetype; /* cache info (NFS) */
85342 unsigned int pc_xdrressize; /* maximum size of XDR reply */
85343-};
85344+} __do_const;
85345
85346 /*
85347 * Function prototypes.
85348diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
85349index 975da75..318c083 100644
85350--- a/include/linux/sunrpc/svc_rdma.h
85351+++ b/include/linux/sunrpc/svc_rdma.h
85352@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
85353 extern unsigned int svcrdma_max_requests;
85354 extern unsigned int svcrdma_max_req_size;
85355
85356-extern atomic_t rdma_stat_recv;
85357-extern atomic_t rdma_stat_read;
85358-extern atomic_t rdma_stat_write;
85359-extern atomic_t rdma_stat_sq_starve;
85360-extern atomic_t rdma_stat_rq_starve;
85361-extern atomic_t rdma_stat_rq_poll;
85362-extern atomic_t rdma_stat_rq_prod;
85363-extern atomic_t rdma_stat_sq_poll;
85364-extern atomic_t rdma_stat_sq_prod;
85365+extern atomic_unchecked_t rdma_stat_recv;
85366+extern atomic_unchecked_t rdma_stat_read;
85367+extern atomic_unchecked_t rdma_stat_write;
85368+extern atomic_unchecked_t rdma_stat_sq_starve;
85369+extern atomic_unchecked_t rdma_stat_rq_starve;
85370+extern atomic_unchecked_t rdma_stat_rq_poll;
85371+extern atomic_unchecked_t rdma_stat_rq_prod;
85372+extern atomic_unchecked_t rdma_stat_sq_poll;
85373+extern atomic_unchecked_t rdma_stat_sq_prod;
85374
85375 #define RPCRDMA_VERSION 1
85376
85377diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
85378index 8d71d65..f79586e 100644
85379--- a/include/linux/sunrpc/svcauth.h
85380+++ b/include/linux/sunrpc/svcauth.h
85381@@ -120,7 +120,7 @@ struct auth_ops {
85382 int (*release)(struct svc_rqst *rq);
85383 void (*domain_release)(struct auth_domain *);
85384 int (*set_client)(struct svc_rqst *rq);
85385-};
85386+} __do_const;
85387
85388 #define SVC_GARBAGE 1
85389 #define SVC_SYSERR 2
85390diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
85391index e7a018e..49f8b17 100644
85392--- a/include/linux/swiotlb.h
85393+++ b/include/linux/swiotlb.h
85394@@ -60,7 +60,8 @@ extern void
85395
85396 extern void
85397 swiotlb_free_coherent(struct device *hwdev, size_t size,
85398- void *vaddr, dma_addr_t dma_handle);
85399+ void *vaddr, dma_addr_t dma_handle,
85400+ struct dma_attrs *attrs);
85401
85402 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
85403 unsigned long offset, size_t size,
85404diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
85405index bda9b81..629e06e 100644
85406--- a/include/linux/syscalls.h
85407+++ b/include/linux/syscalls.h
85408@@ -99,10 +99,16 @@ union bpf_attr;
85409 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
85410
85411 #define __SC_DECL(t, a) t a
85412+#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))
85413 #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
85414 #define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
85415 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
85416-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
85417+#define __SC_LONG(t, a) __typeof( \
85418+ __builtin_choose_expr( \
85419+ sizeof(t) > sizeof(int), \
85420+ (t) 0, \
85421+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
85422+ )) a
85423 #define __SC_CAST(t, a) (t) a
85424 #define __SC_ARGS(t, a) a
85425 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
85426@@ -384,11 +390,11 @@ asmlinkage long sys_sync(void);
85427 asmlinkage long sys_fsync(unsigned int fd);
85428 asmlinkage long sys_fdatasync(unsigned int fd);
85429 asmlinkage long sys_bdflush(int func, long data);
85430-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
85431- char __user *type, unsigned long flags,
85432+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
85433+ const char __user *type, unsigned long flags,
85434 void __user *data);
85435-asmlinkage long sys_umount(char __user *name, int flags);
85436-asmlinkage long sys_oldumount(char __user *name);
85437+asmlinkage long sys_umount(const char __user *name, int flags);
85438+asmlinkage long sys_oldumount(const char __user *name);
85439 asmlinkage long sys_truncate(const char __user *path, long length);
85440 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
85441 asmlinkage long sys_stat(const char __user *filename,
85442@@ -600,7 +606,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
85443 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
85444 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
85445 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
85446- struct sockaddr __user *, int);
85447+ struct sockaddr __user *, int) __intentional_overflow(0);
85448 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
85449 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
85450 unsigned int vlen, unsigned flags);
85451diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
85452index 27b3b0b..e093dd9 100644
85453--- a/include/linux/syscore_ops.h
85454+++ b/include/linux/syscore_ops.h
85455@@ -16,7 +16,7 @@ struct syscore_ops {
85456 int (*suspend)(void);
85457 void (*resume)(void);
85458 void (*shutdown)(void);
85459-};
85460+} __do_const;
85461
85462 extern void register_syscore_ops(struct syscore_ops *ops);
85463 extern void unregister_syscore_ops(struct syscore_ops *ops);
85464diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
85465index b7361f8..341a15a 100644
85466--- a/include/linux/sysctl.h
85467+++ b/include/linux/sysctl.h
85468@@ -39,6 +39,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
85469
85470 extern int proc_dostring(struct ctl_table *, int,
85471 void __user *, size_t *, loff_t *);
85472+extern int proc_dostring_modpriv(struct ctl_table *, int,
85473+ void __user *, size_t *, loff_t *);
85474 extern int proc_dointvec(struct ctl_table *, int,
85475 void __user *, size_t *, loff_t *);
85476 extern int proc_dointvec_minmax(struct ctl_table *, int,
85477@@ -113,7 +115,8 @@ struct ctl_table
85478 struct ctl_table_poll *poll;
85479 void *extra1;
85480 void *extra2;
85481-};
85482+} __do_const __randomize_layout;
85483+typedef struct ctl_table __no_const ctl_table_no_const;
85484
85485 struct ctl_node {
85486 struct rb_node node;
85487diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
85488index f97d0db..c1187dc 100644
85489--- a/include/linux/sysfs.h
85490+++ b/include/linux/sysfs.h
85491@@ -34,7 +34,8 @@ struct attribute {
85492 struct lock_class_key *key;
85493 struct lock_class_key skey;
85494 #endif
85495-};
85496+} __do_const;
85497+typedef struct attribute __no_const attribute_no_const;
85498
85499 /**
85500 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
85501@@ -63,7 +64,8 @@ struct attribute_group {
85502 struct attribute *, int);
85503 struct attribute **attrs;
85504 struct bin_attribute **bin_attrs;
85505-};
85506+} __do_const;
85507+typedef struct attribute_group __no_const attribute_group_no_const;
85508
85509 /**
85510 * Use these macros to make defining attributes easier. See include/linux/device.h
85511@@ -128,7 +130,8 @@ struct bin_attribute {
85512 char *, loff_t, size_t);
85513 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
85514 struct vm_area_struct *vma);
85515-};
85516+} __do_const;
85517+typedef struct bin_attribute __no_const bin_attribute_no_const;
85518
85519 /**
85520 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
85521diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
85522index 387fa7d..3fcde6b 100644
85523--- a/include/linux/sysrq.h
85524+++ b/include/linux/sysrq.h
85525@@ -16,6 +16,7 @@
85526
85527 #include <linux/errno.h>
85528 #include <linux/types.h>
85529+#include <linux/compiler.h>
85530
85531 /* Possible values of bitmask for enabling sysrq functions */
85532 /* 0x0001 is reserved for enable everything */
85533@@ -33,7 +34,7 @@ struct sysrq_key_op {
85534 char *help_msg;
85535 char *action_msg;
85536 int enable_mask;
85537-};
85538+} __do_const;
85539
85540 #ifdef CONFIG_MAGIC_SYSRQ
85541
85542diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
85543index ff307b5..f1a4468 100644
85544--- a/include/linux/thread_info.h
85545+++ b/include/linux/thread_info.h
85546@@ -145,6 +145,13 @@ static inline bool test_and_clear_restore_sigmask(void)
85547 #error "no set_restore_sigmask() provided and default one won't work"
85548 #endif
85549
85550+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size);
85551+
85552+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
85553+{
85554+ __check_object_size(ptr, n, to_user, __builtin_constant_p(n));
85555+}
85556+
85557 #endif /* __KERNEL__ */
85558
85559 #endif /* _LINUX_THREAD_INFO_H */
85560diff --git a/include/linux/tty.h b/include/linux/tty.h
85561index 5171ef8..1048d83e 100644
85562--- a/include/linux/tty.h
85563+++ b/include/linux/tty.h
85564@@ -202,7 +202,7 @@ struct tty_port {
85565 const struct tty_port_operations *ops; /* Port operations */
85566 spinlock_t lock; /* Lock protecting tty field */
85567 int blocked_open; /* Waiting to open */
85568- int count; /* Usage count */
85569+ atomic_t count; /* Usage count */
85570 wait_queue_head_t open_wait; /* Open waiters */
85571 wait_queue_head_t close_wait; /* Close waiters */
85572 wait_queue_head_t delta_msr_wait; /* Modem status change */
85573@@ -290,7 +290,7 @@ struct tty_struct {
85574 /* If the tty has a pending do_SAK, queue it here - akpm */
85575 struct work_struct SAK_work;
85576 struct tty_port *port;
85577-};
85578+} __randomize_layout;
85579
85580 /* Each of a tty's open files has private_data pointing to tty_file_private */
85581 struct tty_file_private {
85582@@ -555,7 +555,7 @@ extern int tty_port_open(struct tty_port *port,
85583 struct tty_struct *tty, struct file *filp);
85584 static inline int tty_port_users(struct tty_port *port)
85585 {
85586- return port->count + port->blocked_open;
85587+ return atomic_read(&port->count) + port->blocked_open;
85588 }
85589
85590 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
85591diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
85592index 92e337c..f46757b 100644
85593--- a/include/linux/tty_driver.h
85594+++ b/include/linux/tty_driver.h
85595@@ -291,7 +291,7 @@ struct tty_operations {
85596 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
85597 #endif
85598 const struct file_operations *proc_fops;
85599-};
85600+} __do_const __randomize_layout;
85601
85602 struct tty_driver {
85603 int magic; /* magic number for this structure */
85604@@ -325,7 +325,7 @@ struct tty_driver {
85605
85606 const struct tty_operations *ops;
85607 struct list_head tty_drivers;
85608-};
85609+} __randomize_layout;
85610
85611 extern struct list_head tty_drivers;
85612
85613diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
85614index 00c9d68..bc0188b 100644
85615--- a/include/linux/tty_ldisc.h
85616+++ b/include/linux/tty_ldisc.h
85617@@ -215,7 +215,7 @@ struct tty_ldisc_ops {
85618
85619 struct module *owner;
85620
85621- int refcount;
85622+ atomic_t refcount;
85623 };
85624
85625 struct tty_ldisc {
85626diff --git a/include/linux/types.h b/include/linux/types.h
85627index a0bb704..f511c77 100644
85628--- a/include/linux/types.h
85629+++ b/include/linux/types.h
85630@@ -177,10 +177,26 @@ typedef struct {
85631 int counter;
85632 } atomic_t;
85633
85634+#ifdef CONFIG_PAX_REFCOUNT
85635+typedef struct {
85636+ int counter;
85637+} atomic_unchecked_t;
85638+#else
85639+typedef atomic_t atomic_unchecked_t;
85640+#endif
85641+
85642 #ifdef CONFIG_64BIT
85643 typedef struct {
85644 long counter;
85645 } atomic64_t;
85646+
85647+#ifdef CONFIG_PAX_REFCOUNT
85648+typedef struct {
85649+ long counter;
85650+} atomic64_unchecked_t;
85651+#else
85652+typedef atomic64_t atomic64_unchecked_t;
85653+#endif
85654 #endif
85655
85656 struct list_head {
85657diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
85658index ecd3319..8a36ded 100644
85659--- a/include/linux/uaccess.h
85660+++ b/include/linux/uaccess.h
85661@@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
85662 long ret; \
85663 mm_segment_t old_fs = get_fs(); \
85664 \
85665- set_fs(KERNEL_DS); \
85666 pagefault_disable(); \
85667- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
85668- pagefault_enable(); \
85669+ set_fs(KERNEL_DS); \
85670+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
85671 set_fs(old_fs); \
85672+ pagefault_enable(); \
85673 ret; \
85674 })
85675
85676diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
85677index 2d1f9b6..d7a9fce 100644
85678--- a/include/linux/uidgid.h
85679+++ b/include/linux/uidgid.h
85680@@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
85681
85682 #endif /* CONFIG_USER_NS */
85683
85684+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
85685+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
85686+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
85687+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
85688+
85689 #endif /* _LINUX_UIDGID_H */
85690diff --git a/include/linux/uio_driver.h b/include/linux/uio_driver.h
85691index baa8171..9ca98ba 100644
85692--- a/include/linux/uio_driver.h
85693+++ b/include/linux/uio_driver.h
85694@@ -67,7 +67,7 @@ struct uio_device {
85695 struct module *owner;
85696 struct device *dev;
85697 int minor;
85698- atomic_t event;
85699+ atomic_unchecked_t event;
85700 struct fasync_struct *async_queue;
85701 wait_queue_head_t wait;
85702 struct uio_info *info;
85703diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
85704index 99c1b4d..562e6f3 100644
85705--- a/include/linux/unaligned/access_ok.h
85706+++ b/include/linux/unaligned/access_ok.h
85707@@ -4,34 +4,34 @@
85708 #include <linux/kernel.h>
85709 #include <asm/byteorder.h>
85710
85711-static inline u16 get_unaligned_le16(const void *p)
85712+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
85713 {
85714- return le16_to_cpup((__le16 *)p);
85715+ return le16_to_cpup((const __le16 *)p);
85716 }
85717
85718-static inline u32 get_unaligned_le32(const void *p)
85719+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
85720 {
85721- return le32_to_cpup((__le32 *)p);
85722+ return le32_to_cpup((const __le32 *)p);
85723 }
85724
85725-static inline u64 get_unaligned_le64(const void *p)
85726+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
85727 {
85728- return le64_to_cpup((__le64 *)p);
85729+ return le64_to_cpup((const __le64 *)p);
85730 }
85731
85732-static inline u16 get_unaligned_be16(const void *p)
85733+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
85734 {
85735- return be16_to_cpup((__be16 *)p);
85736+ return be16_to_cpup((const __be16 *)p);
85737 }
85738
85739-static inline u32 get_unaligned_be32(const void *p)
85740+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
85741 {
85742- return be32_to_cpup((__be32 *)p);
85743+ return be32_to_cpup((const __be32 *)p);
85744 }
85745
85746-static inline u64 get_unaligned_be64(const void *p)
85747+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
85748 {
85749- return be64_to_cpup((__be64 *)p);
85750+ return be64_to_cpup((const __be64 *)p);
85751 }
85752
85753 static inline void put_unaligned_le16(u16 val, void *p)
85754diff --git a/include/linux/usb.h b/include/linux/usb.h
85755index 447a7e2..9cea7e9 100644
85756--- a/include/linux/usb.h
85757+++ b/include/linux/usb.h
85758@@ -571,7 +571,7 @@ struct usb_device {
85759 int maxchild;
85760
85761 u32 quirks;
85762- atomic_t urbnum;
85763+ atomic_unchecked_t urbnum;
85764
85765 unsigned long active_duration;
85766
85767@@ -1655,7 +1655,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
85768
85769 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
85770 __u8 request, __u8 requesttype, __u16 value, __u16 index,
85771- void *data, __u16 size, int timeout);
85772+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
85773 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
85774 void *data, int len, int *actual_length, int timeout);
85775 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
85776diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
85777index d5952bb..9a626d4 100644
85778--- a/include/linux/usb/renesas_usbhs.h
85779+++ b/include/linux/usb/renesas_usbhs.h
85780@@ -39,7 +39,7 @@ enum {
85781 */
85782 struct renesas_usbhs_driver_callback {
85783 int (*notify_hotplug)(struct platform_device *pdev);
85784-};
85785+} __no_const;
85786
85787 /*
85788 * callback functions for platform
85789diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
85790index e953726..8edb26a 100644
85791--- a/include/linux/user_namespace.h
85792+++ b/include/linux/user_namespace.h
85793@@ -33,7 +33,7 @@ struct user_namespace {
85794 struct key *persistent_keyring_register;
85795 struct rw_semaphore persistent_keyring_register_sem;
85796 #endif
85797-};
85798+} __randomize_layout;
85799
85800 extern struct user_namespace init_user_ns;
85801
85802diff --git a/include/linux/utsname.h b/include/linux/utsname.h
85803index 239e277..22a5cf5 100644
85804--- a/include/linux/utsname.h
85805+++ b/include/linux/utsname.h
85806@@ -24,7 +24,7 @@ struct uts_namespace {
85807 struct new_utsname name;
85808 struct user_namespace *user_ns;
85809 unsigned int proc_inum;
85810-};
85811+} __randomize_layout;
85812 extern struct uts_namespace init_uts_ns;
85813
85814 #ifdef CONFIG_UTS_NS
85815diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
85816index 6f8fbcf..4efc177 100644
85817--- a/include/linux/vermagic.h
85818+++ b/include/linux/vermagic.h
85819@@ -25,9 +25,42 @@
85820 #define MODULE_ARCH_VERMAGIC ""
85821 #endif
85822
85823+#ifdef CONFIG_PAX_REFCOUNT
85824+#define MODULE_PAX_REFCOUNT "REFCOUNT "
85825+#else
85826+#define MODULE_PAX_REFCOUNT ""
85827+#endif
85828+
85829+#ifdef CONSTIFY_PLUGIN
85830+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
85831+#else
85832+#define MODULE_CONSTIFY_PLUGIN ""
85833+#endif
85834+
85835+#ifdef STACKLEAK_PLUGIN
85836+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
85837+#else
85838+#define MODULE_STACKLEAK_PLUGIN ""
85839+#endif
85840+
85841+#ifdef RANDSTRUCT_PLUGIN
85842+#include <generated/randomize_layout_hash.h>
85843+#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
85844+#else
85845+#define MODULE_RANDSTRUCT_PLUGIN
85846+#endif
85847+
85848+#ifdef CONFIG_GRKERNSEC
85849+#define MODULE_GRSEC "GRSEC "
85850+#else
85851+#define MODULE_GRSEC ""
85852+#endif
85853+
85854 #define VERMAGIC_STRING \
85855 UTS_RELEASE " " \
85856 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
85857 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
85858- MODULE_ARCH_VERMAGIC
85859+ MODULE_ARCH_VERMAGIC \
85860+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
85861+ MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
85862
85863diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
85864index b483abd..af305ad 100644
85865--- a/include/linux/vga_switcheroo.h
85866+++ b/include/linux/vga_switcheroo.h
85867@@ -63,9 +63,9 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
85868
85869 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
85870
85871-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
85872+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
85873 void vga_switcheroo_fini_domain_pm_ops(struct device *dev);
85874-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
85875+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
85876 #else
85877
85878 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
85879@@ -82,9 +82,9 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
85880
85881 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
85882
85883-static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
85884+static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
85885 static inline void vga_switcheroo_fini_domain_pm_ops(struct device *dev) {}
85886-static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
85887+static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
85888
85889 #endif
85890 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
85891diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
85892index b87696f..1d11de7 100644
85893--- a/include/linux/vmalloc.h
85894+++ b/include/linux/vmalloc.h
85895@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
85896 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
85897 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
85898 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
85899+
85900+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85901+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
85902+#endif
85903+
85904 /* bits [20..32] reserved for arch specific ioremap internals */
85905
85906 /*
85907@@ -82,6 +87,10 @@ extern void *vmap(struct page **pages, unsigned int count,
85908 unsigned long flags, pgprot_t prot);
85909 extern void vunmap(const void *addr);
85910
85911+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
85912+extern void unmap_process_stacks(struct task_struct *task);
85913+#endif
85914+
85915 extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
85916 unsigned long uaddr, void *kaddr,
85917 unsigned long size);
85918@@ -142,7 +151,7 @@ extern void free_vm_area(struct vm_struct *area);
85919
85920 /* for /dev/kmem */
85921 extern long vread(char *buf, char *addr, unsigned long count);
85922-extern long vwrite(char *buf, char *addr, unsigned long count);
85923+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
85924
85925 /*
85926 * Internals. Dont't use..
85927diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
85928index 82e7db7..f8ce3d0 100644
85929--- a/include/linux/vmstat.h
85930+++ b/include/linux/vmstat.h
85931@@ -108,18 +108,18 @@ static inline void vm_events_fold_cpu(int cpu)
85932 /*
85933 * Zone based page accounting with per cpu differentials.
85934 */
85935-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
85936+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
85937
85938 static inline void zone_page_state_add(long x, struct zone *zone,
85939 enum zone_stat_item item)
85940 {
85941- atomic_long_add(x, &zone->vm_stat[item]);
85942- atomic_long_add(x, &vm_stat[item]);
85943+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
85944+ atomic_long_add_unchecked(x, &vm_stat[item]);
85945 }
85946
85947-static inline unsigned long global_page_state(enum zone_stat_item item)
85948+static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
85949 {
85950- long x = atomic_long_read(&vm_stat[item]);
85951+ long x = atomic_long_read_unchecked(&vm_stat[item]);
85952 #ifdef CONFIG_SMP
85953 if (x < 0)
85954 x = 0;
85955@@ -127,10 +127,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
85956 return x;
85957 }
85958
85959-static inline unsigned long zone_page_state(struct zone *zone,
85960+static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
85961 enum zone_stat_item item)
85962 {
85963- long x = atomic_long_read(&zone->vm_stat[item]);
85964+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
85965 #ifdef CONFIG_SMP
85966 if (x < 0)
85967 x = 0;
85968@@ -147,7 +147,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
85969 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
85970 enum zone_stat_item item)
85971 {
85972- long x = atomic_long_read(&zone->vm_stat[item]);
85973+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
85974
85975 #ifdef CONFIG_SMP
85976 int cpu;
85977@@ -234,14 +234,14 @@ static inline void __mod_zone_page_state(struct zone *zone,
85978
85979 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
85980 {
85981- atomic_long_inc(&zone->vm_stat[item]);
85982- atomic_long_inc(&vm_stat[item]);
85983+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
85984+ atomic_long_inc_unchecked(&vm_stat[item]);
85985 }
85986
85987 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
85988 {
85989- atomic_long_dec(&zone->vm_stat[item]);
85990- atomic_long_dec(&vm_stat[item]);
85991+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
85992+ atomic_long_dec_unchecked(&vm_stat[item]);
85993 }
85994
85995 static inline void __inc_zone_page_state(struct page *page,
85996diff --git a/include/linux/xattr.h b/include/linux/xattr.h
85997index 91b0a68..0e9adf6 100644
85998--- a/include/linux/xattr.h
85999+++ b/include/linux/xattr.h
86000@@ -28,7 +28,7 @@ struct xattr_handler {
86001 size_t size, int handler_flags);
86002 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
86003 size_t size, int flags, int handler_flags);
86004-};
86005+} __do_const;
86006
86007 struct xattr {
86008 const char *name;
86009@@ -37,6 +37,9 @@ struct xattr {
86010 };
86011
86012 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
86013+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
86014+ssize_t pax_getxattr(struct dentry *, void *, size_t);
86015+#endif
86016 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
86017 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
86018 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
86019diff --git a/include/linux/zlib.h b/include/linux/zlib.h
86020index 92dbbd3..13ab0b3 100644
86021--- a/include/linux/zlib.h
86022+++ b/include/linux/zlib.h
86023@@ -31,6 +31,7 @@
86024 #define _ZLIB_H
86025
86026 #include <linux/zconf.h>
86027+#include <linux/compiler.h>
86028
86029 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
86030 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
86031@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
86032
86033 /* basic functions */
86034
86035-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
86036+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
86037 /*
86038 Returns the number of bytes that needs to be allocated for a per-
86039 stream workspace with the specified parameters. A pointer to this
86040diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
86041index eb76cfd..9fd0e7c 100644
86042--- a/include/media/v4l2-dev.h
86043+++ b/include/media/v4l2-dev.h
86044@@ -75,7 +75,7 @@ struct v4l2_file_operations {
86045 int (*mmap) (struct file *, struct vm_area_struct *);
86046 int (*open) (struct file *);
86047 int (*release) (struct file *);
86048-};
86049+} __do_const;
86050
86051 /*
86052 * Newer version of video_device, handled by videodev2.c
86053diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
86054index ffb69da..040393e 100644
86055--- a/include/media/v4l2-device.h
86056+++ b/include/media/v4l2-device.h
86057@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
86058 this function returns 0. If the name ends with a digit (e.g. cx18),
86059 then the name will be set to cx18-0 since cx180 looks really odd. */
86060 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
86061- atomic_t *instance);
86062+ atomic_unchecked_t *instance);
86063
86064 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
86065 Since the parent disappears this ensures that v4l2_dev doesn't have an
86066diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
86067index 2a25dec..bf6dd8a 100644
86068--- a/include/net/9p/transport.h
86069+++ b/include/net/9p/transport.h
86070@@ -62,7 +62,7 @@ struct p9_trans_module {
86071 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
86072 int (*zc_request)(struct p9_client *, struct p9_req_t *,
86073 char *, char *, int , int, int, int);
86074-};
86075+} __do_const;
86076
86077 void v9fs_register_trans(struct p9_trans_module *m);
86078 void v9fs_unregister_trans(struct p9_trans_module *m);
86079diff --git a/include/net/af_unix.h b/include/net/af_unix.h
86080index a175ba4..196eb8242 100644
86081--- a/include/net/af_unix.h
86082+++ b/include/net/af_unix.h
86083@@ -36,7 +36,7 @@ struct unix_skb_parms {
86084 u32 secid; /* Security ID */
86085 #endif
86086 u32 consumed;
86087-};
86088+} __randomize_layout;
86089
86090 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
86091 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
86092diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
86093index ead99f0..6263c4b 100644
86094--- a/include/net/bluetooth/l2cap.h
86095+++ b/include/net/bluetooth/l2cap.h
86096@@ -608,7 +608,7 @@ struct l2cap_ops {
86097 unsigned char *kdata,
86098 struct iovec *iov,
86099 int len);
86100-};
86101+} __do_const;
86102
86103 struct l2cap_conn {
86104 struct hci_conn *hcon;
86105diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
86106index f2ae33d..c457cf0 100644
86107--- a/include/net/caif/cfctrl.h
86108+++ b/include/net/caif/cfctrl.h
86109@@ -52,7 +52,7 @@ struct cfctrl_rsp {
86110 void (*radioset_rsp)(void);
86111 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
86112 struct cflayer *client_layer);
86113-};
86114+} __no_const;
86115
86116 /* Link Setup Parameters for CAIF-Links. */
86117 struct cfctrl_link_param {
86118@@ -101,8 +101,8 @@ struct cfctrl_request_info {
86119 struct cfctrl {
86120 struct cfsrvl serv;
86121 struct cfctrl_rsp res;
86122- atomic_t req_seq_no;
86123- atomic_t rsp_seq_no;
86124+ atomic_unchecked_t req_seq_no;
86125+ atomic_unchecked_t rsp_seq_no;
86126 struct list_head list;
86127 /* Protects from simultaneous access to first_req list */
86128 spinlock_t info_list_lock;
86129diff --git a/include/net/flow.h b/include/net/flow.h
86130index 8109a15..504466d 100644
86131--- a/include/net/flow.h
86132+++ b/include/net/flow.h
86133@@ -231,6 +231,6 @@ void flow_cache_fini(struct net *net);
86134
86135 void flow_cache_flush(struct net *net);
86136 void flow_cache_flush_deferred(struct net *net);
86137-extern atomic_t flow_cache_genid;
86138+extern atomic_unchecked_t flow_cache_genid;
86139
86140 #endif
86141diff --git a/include/net/genetlink.h b/include/net/genetlink.h
86142index af10c2c..a431cc5 100644
86143--- a/include/net/genetlink.h
86144+++ b/include/net/genetlink.h
86145@@ -120,7 +120,7 @@ struct genl_ops {
86146 u8 cmd;
86147 u8 internal_flags;
86148 u8 flags;
86149-};
86150+} __do_const;
86151
86152 int __genl_register_family(struct genl_family *family);
86153
86154diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
86155index 734d9b5..48a9a4b 100644
86156--- a/include/net/gro_cells.h
86157+++ b/include/net/gro_cells.h
86158@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
86159 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
86160
86161 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
86162- atomic_long_inc(&dev->rx_dropped);
86163+ atomic_long_inc_unchecked(&dev->rx_dropped);
86164 kfree_skb(skb);
86165 return;
86166 }
86167diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
86168index 848e85c..051c7de 100644
86169--- a/include/net/inet_connection_sock.h
86170+++ b/include/net/inet_connection_sock.h
86171@@ -63,7 +63,7 @@ struct inet_connection_sock_af_ops {
86172 int (*bind_conflict)(const struct sock *sk,
86173 const struct inet_bind_bucket *tb, bool relax);
86174 void (*mtu_reduced)(struct sock *sk);
86175-};
86176+} __do_const;
86177
86178 /** inet_connection_sock - INET connection oriented sock
86179 *
86180diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
86181index 80479ab..0c3f647 100644
86182--- a/include/net/inetpeer.h
86183+++ b/include/net/inetpeer.h
86184@@ -47,7 +47,7 @@ struct inet_peer {
86185 */
86186 union {
86187 struct {
86188- atomic_t rid; /* Frag reception counter */
86189+ atomic_unchecked_t rid; /* Frag reception counter */
86190 };
86191 struct rcu_head rcu;
86192 struct inet_peer *gc_next;
86193diff --git a/include/net/ip.h b/include/net/ip.h
86194index 0bb6207..a8878af 100644
86195--- a/include/net/ip.h
86196+++ b/include/net/ip.h
86197@@ -316,7 +316,7 @@ static inline unsigned int ip_skb_dst_mtu(const struct sk_buff *skb)
86198 }
86199 }
86200
86201-u32 ip_idents_reserve(u32 hash, int segs);
86202+u32 ip_idents_reserve(u32 hash, int segs) __intentional_overflow(-1);
86203 void __ip_select_ident(struct iphdr *iph, int segs);
86204
86205 static inline void ip_select_ident_segs(struct sk_buff *skb, struct sock *sk, int segs)
86206diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
86207index dc9d2a2..d985691 100644
86208--- a/include/net/ip_fib.h
86209+++ b/include/net/ip_fib.h
86210@@ -170,7 +170,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
86211
86212 #define FIB_RES_SADDR(net, res) \
86213 ((FIB_RES_NH(res).nh_saddr_genid == \
86214- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
86215+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
86216 FIB_RES_NH(res).nh_saddr : \
86217 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
86218 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
86219diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
86220index 615b20b..fd4cbd8 100644
86221--- a/include/net/ip_vs.h
86222+++ b/include/net/ip_vs.h
86223@@ -534,7 +534,7 @@ struct ip_vs_conn {
86224 struct ip_vs_conn *control; /* Master control connection */
86225 atomic_t n_control; /* Number of controlled ones */
86226 struct ip_vs_dest *dest; /* real server */
86227- atomic_t in_pkts; /* incoming packet counter */
86228+ atomic_unchecked_t in_pkts; /* incoming packet counter */
86229
86230 /* Packet transmitter for different forwarding methods. If it
86231 * mangles the packet, it must return NF_DROP or better NF_STOLEN,
86232@@ -682,7 +682,7 @@ struct ip_vs_dest {
86233 __be16 port; /* port number of the server */
86234 union nf_inet_addr addr; /* IP address of the server */
86235 volatile unsigned int flags; /* dest status flags */
86236- atomic_t conn_flags; /* flags to copy to conn */
86237+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
86238 atomic_t weight; /* server weight */
86239
86240 atomic_t refcnt; /* reference counter */
86241@@ -928,11 +928,11 @@ struct netns_ipvs {
86242 /* ip_vs_lblc */
86243 int sysctl_lblc_expiration;
86244 struct ctl_table_header *lblc_ctl_header;
86245- struct ctl_table *lblc_ctl_table;
86246+ ctl_table_no_const *lblc_ctl_table;
86247 /* ip_vs_lblcr */
86248 int sysctl_lblcr_expiration;
86249 struct ctl_table_header *lblcr_ctl_header;
86250- struct ctl_table *lblcr_ctl_table;
86251+ ctl_table_no_const *lblcr_ctl_table;
86252 /* ip_vs_est */
86253 struct list_head est_list; /* estimator list */
86254 spinlock_t est_lock;
86255diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
86256index 8d4f588..2e37ad2 100644
86257--- a/include/net/irda/ircomm_tty.h
86258+++ b/include/net/irda/ircomm_tty.h
86259@@ -33,6 +33,7 @@
86260 #include <linux/termios.h>
86261 #include <linux/timer.h>
86262 #include <linux/tty.h> /* struct tty_struct */
86263+#include <asm/local.h>
86264
86265 #include <net/irda/irias_object.h>
86266 #include <net/irda/ircomm_core.h>
86267diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
86268index 714cc9a..ea05f3e 100644
86269--- a/include/net/iucv/af_iucv.h
86270+++ b/include/net/iucv/af_iucv.h
86271@@ -149,7 +149,7 @@ struct iucv_skb_cb {
86272 struct iucv_sock_list {
86273 struct hlist_head head;
86274 rwlock_t lock;
86275- atomic_t autobind_name;
86276+ atomic_unchecked_t autobind_name;
86277 };
86278
86279 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
86280diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
86281index f3be818..bf46196 100644
86282--- a/include/net/llc_c_ac.h
86283+++ b/include/net/llc_c_ac.h
86284@@ -87,7 +87,7 @@
86285 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
86286 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
86287
86288-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
86289+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
86290
86291 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
86292 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
86293diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
86294index 3948cf1..83b28c4 100644
86295--- a/include/net/llc_c_ev.h
86296+++ b/include/net/llc_c_ev.h
86297@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
86298 return (struct llc_conn_state_ev *)skb->cb;
86299 }
86300
86301-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
86302-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
86303+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
86304+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
86305
86306 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
86307 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
86308diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
86309index 0e79cfb..f46db31 100644
86310--- a/include/net/llc_c_st.h
86311+++ b/include/net/llc_c_st.h
86312@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
86313 u8 next_state;
86314 llc_conn_ev_qfyr_t *ev_qualifiers;
86315 llc_conn_action_t *ev_actions;
86316-};
86317+} __do_const;
86318
86319 struct llc_conn_state {
86320 u8 current_state;
86321diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
86322index a61b98c..aade1eb 100644
86323--- a/include/net/llc_s_ac.h
86324+++ b/include/net/llc_s_ac.h
86325@@ -23,7 +23,7 @@
86326 #define SAP_ACT_TEST_IND 9
86327
86328 /* All action functions must look like this */
86329-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
86330+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
86331
86332 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
86333 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
86334diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
86335index 567c681..cd73ac02 100644
86336--- a/include/net/llc_s_st.h
86337+++ b/include/net/llc_s_st.h
86338@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
86339 llc_sap_ev_t ev;
86340 u8 next_state;
86341 llc_sap_action_t *ev_actions;
86342-};
86343+} __do_const;
86344
86345 struct llc_sap_state {
86346 u8 curr_state;
86347diff --git a/include/net/mac80211.h b/include/net/mac80211.h
86348index 0ad1f47..aaea45b 100644
86349--- a/include/net/mac80211.h
86350+++ b/include/net/mac80211.h
86351@@ -4648,7 +4648,7 @@ struct rate_control_ops {
86352 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
86353
86354 u32 (*get_expected_throughput)(void *priv_sta);
86355-};
86356+} __do_const;
86357
86358 static inline int rate_supported(struct ieee80211_sta *sta,
86359 enum ieee80211_band band,
86360diff --git a/include/net/neighbour.h b/include/net/neighbour.h
86361index f60558d..e5ed9bd 100644
86362--- a/include/net/neighbour.h
86363+++ b/include/net/neighbour.h
86364@@ -163,7 +163,7 @@ struct neigh_ops {
86365 void (*error_report)(struct neighbour *, struct sk_buff *);
86366 int (*output)(struct neighbour *, struct sk_buff *);
86367 int (*connected_output)(struct neighbour *, struct sk_buff *);
86368-};
86369+} __do_const;
86370
86371 struct pneigh_entry {
86372 struct pneigh_entry *next;
86373@@ -217,7 +217,7 @@ struct neigh_table {
86374 struct neigh_statistics __percpu *stats;
86375 struct neigh_hash_table __rcu *nht;
86376 struct pneigh_entry **phash_buckets;
86377-};
86378+} __randomize_layout;
86379
86380 static inline int neigh_parms_family(struct neigh_parms *p)
86381 {
86382diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
86383index e0d6466..e2f3003 100644
86384--- a/include/net/net_namespace.h
86385+++ b/include/net/net_namespace.h
86386@@ -129,8 +129,8 @@ struct net {
86387 struct netns_ipvs *ipvs;
86388 #endif
86389 struct sock *diag_nlsk;
86390- atomic_t fnhe_genid;
86391-};
86392+ atomic_unchecked_t fnhe_genid;
86393+} __randomize_layout;
86394
86395 #include <linux/seq_file_net.h>
86396
86397@@ -286,7 +286,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
86398 #define __net_init __init
86399 #define __net_exit __exit_refok
86400 #define __net_initdata __initdata
86401+#ifdef CONSTIFY_PLUGIN
86402 #define __net_initconst __initconst
86403+#else
86404+#define __net_initconst __initdata
86405+#endif
86406 #endif
86407
86408 struct pernet_operations {
86409@@ -296,7 +300,7 @@ struct pernet_operations {
86410 void (*exit_batch)(struct list_head *net_exit_list);
86411 int *id;
86412 size_t size;
86413-};
86414+} __do_const;
86415
86416 /*
86417 * Use these carefully. If you implement a network device and it
86418@@ -344,12 +348,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
86419
86420 static inline int rt_genid_ipv4(struct net *net)
86421 {
86422- return atomic_read(&net->ipv4.rt_genid);
86423+ return atomic_read_unchecked(&net->ipv4.rt_genid);
86424 }
86425
86426 static inline void rt_genid_bump_ipv4(struct net *net)
86427 {
86428- atomic_inc(&net->ipv4.rt_genid);
86429+ atomic_inc_unchecked(&net->ipv4.rt_genid);
86430 }
86431
86432 extern void (*__fib6_flush_trees)(struct net *net);
86433@@ -376,12 +380,12 @@ static inline void rt_genid_bump_all(struct net *net)
86434
86435 static inline int fnhe_genid(struct net *net)
86436 {
86437- return atomic_read(&net->fnhe_genid);
86438+ return atomic_read_unchecked(&net->fnhe_genid);
86439 }
86440
86441 static inline void fnhe_genid_bump(struct net *net)
86442 {
86443- atomic_inc(&net->fnhe_genid);
86444+ atomic_inc_unchecked(&net->fnhe_genid);
86445 }
86446
86447 #endif /* __NET_NET_NAMESPACE_H */
86448diff --git a/include/net/netlink.h b/include/net/netlink.h
86449index 7b903e1..ad9ca4b 100644
86450--- a/include/net/netlink.h
86451+++ b/include/net/netlink.h
86452@@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
86453 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
86454 {
86455 if (mark)
86456- skb_trim(skb, (unsigned char *) mark - skb->data);
86457+ skb_trim(skb, (const unsigned char *) mark - skb->data);
86458 }
86459
86460 /**
86461diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
86462index 29d6a94..235d3d84 100644
86463--- a/include/net/netns/conntrack.h
86464+++ b/include/net/netns/conntrack.h
86465@@ -14,10 +14,10 @@ struct nf_conntrack_ecache;
86466 struct nf_proto_net {
86467 #ifdef CONFIG_SYSCTL
86468 struct ctl_table_header *ctl_table_header;
86469- struct ctl_table *ctl_table;
86470+ ctl_table_no_const *ctl_table;
86471 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
86472 struct ctl_table_header *ctl_compat_header;
86473- struct ctl_table *ctl_compat_table;
86474+ ctl_table_no_const *ctl_compat_table;
86475 #endif
86476 #endif
86477 unsigned int users;
86478@@ -60,7 +60,7 @@ struct nf_ip_net {
86479 struct nf_icmp_net icmpv6;
86480 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
86481 struct ctl_table_header *ctl_table_header;
86482- struct ctl_table *ctl_table;
86483+ ctl_table_no_const *ctl_table;
86484 #endif
86485 };
86486
86487diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
86488index 24945ce..f19e42f 100644
86489--- a/include/net/netns/ipv4.h
86490+++ b/include/net/netns/ipv4.h
86491@@ -83,7 +83,7 @@ struct netns_ipv4 {
86492
86493 struct ping_group_range ping_group_range;
86494
86495- atomic_t dev_addr_genid;
86496+ atomic_unchecked_t dev_addr_genid;
86497
86498 #ifdef CONFIG_SYSCTL
86499 unsigned long *sysctl_local_reserved_ports;
86500@@ -97,6 +97,6 @@ struct netns_ipv4 {
86501 struct fib_rules_ops *mr_rules_ops;
86502 #endif
86503 #endif
86504- atomic_t rt_genid;
86505+ atomic_unchecked_t rt_genid;
86506 };
86507 #endif
86508diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
86509index 69ae41f..4f94868 100644
86510--- a/include/net/netns/ipv6.h
86511+++ b/include/net/netns/ipv6.h
86512@@ -75,8 +75,8 @@ struct netns_ipv6 {
86513 struct fib_rules_ops *mr6_rules_ops;
86514 #endif
86515 #endif
86516- atomic_t dev_addr_genid;
86517- atomic_t fib6_sernum;
86518+ atomic_unchecked_t dev_addr_genid;
86519+ atomic_unchecked_t fib6_sernum;
86520 };
86521
86522 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
86523diff --git a/include/net/netns/xfrm.h b/include/net/netns/xfrm.h
86524index 9da7982..099321b9 100644
86525--- a/include/net/netns/xfrm.h
86526+++ b/include/net/netns/xfrm.h
86527@@ -78,7 +78,7 @@ struct netns_xfrm {
86528
86529 /* flow cache part */
86530 struct flow_cache flow_cache_global;
86531- atomic_t flow_cache_genid;
86532+ atomic_unchecked_t flow_cache_genid;
86533 struct list_head flow_cache_gc_list;
86534 spinlock_t flow_cache_gc_lock;
86535 struct work_struct flow_cache_gc_work;
86536diff --git a/include/net/ping.h b/include/net/ping.h
86537index 026479b..d9b2829 100644
86538--- a/include/net/ping.h
86539+++ b/include/net/ping.h
86540@@ -54,7 +54,7 @@ struct ping_iter_state {
86541
86542 extern struct proto ping_prot;
86543 #if IS_ENABLED(CONFIG_IPV6)
86544-extern struct pingv6_ops pingv6_ops;
86545+extern struct pingv6_ops *pingv6_ops;
86546 #endif
86547
86548 struct pingfakehdr {
86549diff --git a/include/net/protocol.h b/include/net/protocol.h
86550index d6fcc1f..ca277058 100644
86551--- a/include/net/protocol.h
86552+++ b/include/net/protocol.h
86553@@ -49,7 +49,7 @@ struct net_protocol {
86554 * socket lookup?
86555 */
86556 icmp_strict_tag_validation:1;
86557-};
86558+} __do_const;
86559
86560 #if IS_ENABLED(CONFIG_IPV6)
86561 struct inet6_protocol {
86562@@ -62,7 +62,7 @@ struct inet6_protocol {
86563 u8 type, u8 code, int offset,
86564 __be32 info);
86565 unsigned int flags; /* INET6_PROTO_xxx */
86566-};
86567+} __do_const;
86568
86569 #define INET6_PROTO_NOPOLICY 0x1
86570 #define INET6_PROTO_FINAL 0x2
86571diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
86572index e21b9f9..0191ef0 100644
86573--- a/include/net/rtnetlink.h
86574+++ b/include/net/rtnetlink.h
86575@@ -93,7 +93,7 @@ struct rtnl_link_ops {
86576 int (*fill_slave_info)(struct sk_buff *skb,
86577 const struct net_device *dev,
86578 const struct net_device *slave_dev);
86579-};
86580+} __do_const;
86581
86582 int __rtnl_link_register(struct rtnl_link_ops *ops);
86583 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
86584diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
86585index 4a5b9a3..ca27d73 100644
86586--- a/include/net/sctp/checksum.h
86587+++ b/include/net/sctp/checksum.h
86588@@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
86589 unsigned int offset)
86590 {
86591 struct sctphdr *sh = sctp_hdr(skb);
86592- __le32 ret, old = sh->checksum;
86593- const struct skb_checksum_ops ops = {
86594+ __le32 ret, old = sh->checksum;
86595+ static const struct skb_checksum_ops ops = {
86596 .update = sctp_csum_update,
86597 .combine = sctp_csum_combine,
86598 };
86599diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
86600index 72a31db..aaa63d9 100644
86601--- a/include/net/sctp/sm.h
86602+++ b/include/net/sctp/sm.h
86603@@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
86604 typedef struct {
86605 sctp_state_fn_t *fn;
86606 const char *name;
86607-} sctp_sm_table_entry_t;
86608+} __do_const sctp_sm_table_entry_t;
86609
86610 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
86611 * currently in use.
86612@@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
86613 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
86614
86615 /* Extern declarations for major data structures. */
86616-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
86617+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
86618
86619
86620 /* Get the size of a DATA chunk payload. */
86621diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
86622index 4ff3f67..89ae38e 100644
86623--- a/include/net/sctp/structs.h
86624+++ b/include/net/sctp/structs.h
86625@@ -509,7 +509,7 @@ struct sctp_pf {
86626 void (*to_sk_saddr)(union sctp_addr *, struct sock *sk);
86627 void (*to_sk_daddr)(union sctp_addr *, struct sock *sk);
86628 struct sctp_af *af;
86629-};
86630+} __do_const;
86631
86632
86633 /* Structure to track chunk fragments that have been acked, but peer
86634diff --git a/include/net/sock.h b/include/net/sock.h
86635index 7db3db1..a915cca 100644
86636--- a/include/net/sock.h
86637+++ b/include/net/sock.h
86638@@ -355,7 +355,7 @@ struct sock {
86639 unsigned int sk_napi_id;
86640 unsigned int sk_ll_usec;
86641 #endif
86642- atomic_t sk_drops;
86643+ atomic_unchecked_t sk_drops;
86644 int sk_rcvbuf;
86645
86646 struct sk_filter __rcu *sk_filter;
86647@@ -1048,7 +1048,7 @@ struct proto {
86648 void (*destroy_cgroup)(struct mem_cgroup *memcg);
86649 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
86650 #endif
86651-};
86652+} __randomize_layout;
86653
86654 /*
86655 * Bits in struct cg_proto.flags
86656@@ -1235,7 +1235,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
86657 return ret >> PAGE_SHIFT;
86658 }
86659
86660-static inline long
86661+static inline long __intentional_overflow(-1)
86662 sk_memory_allocated(const struct sock *sk)
86663 {
86664 struct proto *prot = sk->sk_prot;
86665@@ -1380,7 +1380,7 @@ struct sock_iocb {
86666 struct scm_cookie *scm;
86667 struct msghdr *msg, async_msg;
86668 struct kiocb *kiocb;
86669-};
86670+} __randomize_layout;
86671
86672 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
86673 {
86674@@ -1820,7 +1820,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
86675 }
86676
86677 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
86678- char __user *from, char *to,
86679+ char __user *from, unsigned char *to,
86680 int copy, int offset)
86681 {
86682 if (skb->ip_summed == CHECKSUM_NONE) {
86683@@ -2092,7 +2092,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
86684 }
86685 }
86686
86687-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
86688+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
86689
86690 /**
86691 * sk_page_frag - return an appropriate page_frag
86692diff --git a/include/net/tcp.h b/include/net/tcp.h
86693index 4062b4f..9ff45e7 100644
86694--- a/include/net/tcp.h
86695+++ b/include/net/tcp.h
86696@@ -519,7 +519,7 @@ void tcp_retransmit_timer(struct sock *sk);
86697 void tcp_xmit_retransmit_queue(struct sock *);
86698 void tcp_simple_retransmit(struct sock *);
86699 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
86700-int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
86701+int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
86702
86703 void tcp_send_probe0(struct sock *);
86704 void tcp_send_partial(struct sock *);
86705@@ -692,8 +692,8 @@ static inline u32 tcp_skb_timestamp(const struct sk_buff *skb)
86706 * If this grows please adjust skbuff.h:skbuff->cb[xxx] size appropriately.
86707 */
86708 struct tcp_skb_cb {
86709- __u32 seq; /* Starting sequence number */
86710- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
86711+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
86712+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
86713 union {
86714 /* Note : tcp_tw_isn is used in input path only
86715 * (isn chosen by tcp_timewait_state_process())
86716@@ -718,7 +718,7 @@ struct tcp_skb_cb {
86717
86718 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
86719 /* 1 byte hole */
86720- __u32 ack_seq; /* Sequence number ACK'd */
86721+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
86722 union {
86723 struct inet_skb_parm h4;
86724 #if IS_ENABLED(CONFIG_IPV6)
86725diff --git a/include/net/xfrm.h b/include/net/xfrm.h
86726index dc4865e..152ee4c 100644
86727--- a/include/net/xfrm.h
86728+++ b/include/net/xfrm.h
86729@@ -285,7 +285,6 @@ struct xfrm_dst;
86730 struct xfrm_policy_afinfo {
86731 unsigned short family;
86732 struct dst_ops *dst_ops;
86733- void (*garbage_collect)(struct net *net);
86734 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
86735 const xfrm_address_t *saddr,
86736 const xfrm_address_t *daddr);
86737@@ -303,7 +302,7 @@ struct xfrm_policy_afinfo {
86738 struct net_device *dev,
86739 const struct flowi *fl);
86740 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
86741-};
86742+} __do_const;
86743
86744 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
86745 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
86746@@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
86747 int (*transport_finish)(struct sk_buff *skb,
86748 int async);
86749 void (*local_error)(struct sk_buff *skb, u32 mtu);
86750-};
86751+} __do_const;
86752
86753 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
86754 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
86755@@ -437,7 +436,7 @@ struct xfrm_mode {
86756 struct module *owner;
86757 unsigned int encap;
86758 int flags;
86759-};
86760+} __do_const;
86761
86762 /* Flags for xfrm_mode. */
86763 enum {
86764@@ -534,7 +533,7 @@ struct xfrm_policy {
86765 struct timer_list timer;
86766
86767 struct flow_cache_object flo;
86768- atomic_t genid;
86769+ atomic_unchecked_t genid;
86770 u32 priority;
86771 u32 index;
86772 struct xfrm_mark mark;
86773@@ -1167,6 +1166,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
86774 }
86775
86776 void xfrm_garbage_collect(struct net *net);
86777+void xfrm_garbage_collect_deferred(struct net *net);
86778
86779 #else
86780
86781@@ -1205,6 +1205,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
86782 static inline void xfrm_garbage_collect(struct net *net)
86783 {
86784 }
86785+static inline void xfrm_garbage_collect_deferred(struct net *net)
86786+{
86787+}
86788 #endif
86789
86790 static __inline__
86791diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
86792index 1017e0b..227aa4d 100644
86793--- a/include/rdma/iw_cm.h
86794+++ b/include/rdma/iw_cm.h
86795@@ -122,7 +122,7 @@ struct iw_cm_verbs {
86796 int backlog);
86797
86798 int (*destroy_listen)(struct iw_cm_id *cm_id);
86799-};
86800+} __no_const;
86801
86802 /**
86803 * iw_create_cm_id - Create an IW CM identifier.
86804diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
86805index 52beadf..598734c 100644
86806--- a/include/scsi/libfc.h
86807+++ b/include/scsi/libfc.h
86808@@ -771,6 +771,7 @@ struct libfc_function_template {
86809 */
86810 void (*disc_stop_final) (struct fc_lport *);
86811 };
86812+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
86813
86814 /**
86815 * struct fc_disc - Discovery context
86816@@ -875,7 +876,7 @@ struct fc_lport {
86817 struct fc_vport *vport;
86818
86819 /* Operational Information */
86820- struct libfc_function_template tt;
86821+ libfc_function_template_no_const tt;
86822 u8 link_up;
86823 u8 qfull;
86824 enum fc_lport_state state;
86825diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
86826index 27ecee7..5f42632 100644
86827--- a/include/scsi/scsi_device.h
86828+++ b/include/scsi/scsi_device.h
86829@@ -186,9 +186,9 @@ struct scsi_device {
86830 unsigned int max_device_blocked; /* what device_blocked counts down from */
86831 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
86832
86833- atomic_t iorequest_cnt;
86834- atomic_t iodone_cnt;
86835- atomic_t ioerr_cnt;
86836+ atomic_unchecked_t iorequest_cnt;
86837+ atomic_unchecked_t iodone_cnt;
86838+ atomic_unchecked_t ioerr_cnt;
86839
86840 struct device sdev_gendev,
86841 sdev_dev;
86842diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
86843index 007a0bc..7188db8 100644
86844--- a/include/scsi/scsi_transport_fc.h
86845+++ b/include/scsi/scsi_transport_fc.h
86846@@ -756,7 +756,8 @@ struct fc_function_template {
86847 unsigned long show_host_system_hostname:1;
86848
86849 unsigned long disable_target_scan:1;
86850-};
86851+} __do_const;
86852+typedef struct fc_function_template __no_const fc_function_template_no_const;
86853
86854
86855 /**
86856diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
86857index ae6c3b8..fd748ac 100644
86858--- a/include/sound/compress_driver.h
86859+++ b/include/sound/compress_driver.h
86860@@ -128,7 +128,7 @@ struct snd_compr_ops {
86861 struct snd_compr_caps *caps);
86862 int (*get_codec_caps) (struct snd_compr_stream *stream,
86863 struct snd_compr_codec_caps *codec);
86864-};
86865+} __no_const;
86866
86867 /**
86868 * struct snd_compr: Compressed device
86869diff --git a/include/sound/soc.h b/include/sound/soc.h
86870index 7ba7130..d46594d 100644
86871--- a/include/sound/soc.h
86872+++ b/include/sound/soc.h
86873@@ -853,7 +853,7 @@ struct snd_soc_codec_driver {
86874 enum snd_soc_dapm_type, int);
86875
86876 bool ignore_pmdown_time; /* Doesn't benefit from pmdown delay */
86877-};
86878+} __do_const;
86879
86880 /* SoC platform interface */
86881 struct snd_soc_platform_driver {
86882@@ -882,7 +882,7 @@ struct snd_soc_platform_driver {
86883 const struct snd_compr_ops *compr_ops;
86884
86885 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
86886-};
86887+} __do_const;
86888
86889 struct snd_soc_dai_link_component {
86890 const char *name;
86891diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
86892index 23c518a..d6ef510 100644
86893--- a/include/target/target_core_base.h
86894+++ b/include/target/target_core_base.h
86895@@ -764,7 +764,7 @@ struct se_device {
86896 atomic_long_t write_bytes;
86897 /* Active commands on this virtual SE device */
86898 atomic_t simple_cmds;
86899- atomic_t dev_ordered_id;
86900+ atomic_unchecked_t dev_ordered_id;
86901 atomic_t dev_ordered_sync;
86902 atomic_t dev_qf_count;
86903 int export_count;
86904diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
86905new file mode 100644
86906index 0000000..fb634b7
86907--- /dev/null
86908+++ b/include/trace/events/fs.h
86909@@ -0,0 +1,53 @@
86910+#undef TRACE_SYSTEM
86911+#define TRACE_SYSTEM fs
86912+
86913+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
86914+#define _TRACE_FS_H
86915+
86916+#include <linux/fs.h>
86917+#include <linux/tracepoint.h>
86918+
86919+TRACE_EVENT(do_sys_open,
86920+
86921+ TP_PROTO(const char *filename, int flags, int mode),
86922+
86923+ TP_ARGS(filename, flags, mode),
86924+
86925+ TP_STRUCT__entry(
86926+ __string( filename, filename )
86927+ __field( int, flags )
86928+ __field( int, mode )
86929+ ),
86930+
86931+ TP_fast_assign(
86932+ __assign_str(filename, filename);
86933+ __entry->flags = flags;
86934+ __entry->mode = mode;
86935+ ),
86936+
86937+ TP_printk("\"%s\" %x %o",
86938+ __get_str(filename), __entry->flags, __entry->mode)
86939+);
86940+
86941+TRACE_EVENT(open_exec,
86942+
86943+ TP_PROTO(const char *filename),
86944+
86945+ TP_ARGS(filename),
86946+
86947+ TP_STRUCT__entry(
86948+ __string( filename, filename )
86949+ ),
86950+
86951+ TP_fast_assign(
86952+ __assign_str(filename, filename);
86953+ ),
86954+
86955+ TP_printk("\"%s\"",
86956+ __get_str(filename))
86957+);
86958+
86959+#endif /* _TRACE_FS_H */
86960+
86961+/* This part must be outside protection */
86962+#include <trace/define_trace.h>
86963diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
86964index 3608beb..df39d8a 100644
86965--- a/include/trace/events/irq.h
86966+++ b/include/trace/events/irq.h
86967@@ -36,7 +36,7 @@ struct softirq_action;
86968 */
86969 TRACE_EVENT(irq_handler_entry,
86970
86971- TP_PROTO(int irq, struct irqaction *action),
86972+ TP_PROTO(int irq, const struct irqaction *action),
86973
86974 TP_ARGS(irq, action),
86975
86976@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
86977 */
86978 TRACE_EVENT(irq_handler_exit,
86979
86980- TP_PROTO(int irq, struct irqaction *action, int ret),
86981+ TP_PROTO(int irq, const struct irqaction *action, int ret),
86982
86983 TP_ARGS(irq, action, ret),
86984
86985diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
86986index 7caf44c..23c6f27 100644
86987--- a/include/uapi/linux/a.out.h
86988+++ b/include/uapi/linux/a.out.h
86989@@ -39,6 +39,14 @@ enum machine_type {
86990 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
86991 };
86992
86993+/* Constants for the N_FLAGS field */
86994+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
86995+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
86996+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
86997+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
86998+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
86999+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
87000+
87001 #if !defined (N_MAGIC)
87002 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
87003 #endif
87004diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
87005index 22b6ad3..aeba37e 100644
87006--- a/include/uapi/linux/bcache.h
87007+++ b/include/uapi/linux/bcache.h
87008@@ -5,6 +5,7 @@
87009 * Bcache on disk data structures
87010 */
87011
87012+#include <linux/compiler.h>
87013 #include <asm/types.h>
87014
87015 #define BITMASK(name, type, field, offset, size) \
87016@@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
87017 /* Btree keys - all units are in sectors */
87018
87019 struct bkey {
87020- __u64 high;
87021- __u64 low;
87022+ __u64 high __intentional_overflow(-1);
87023+ __u64 low __intentional_overflow(-1);
87024 __u64 ptr[];
87025 };
87026
87027diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
87028index d876736..ccce5c0 100644
87029--- a/include/uapi/linux/byteorder/little_endian.h
87030+++ b/include/uapi/linux/byteorder/little_endian.h
87031@@ -42,51 +42,51 @@
87032
87033 static inline __le64 __cpu_to_le64p(const __u64 *p)
87034 {
87035- return (__force __le64)*p;
87036+ return (__force const __le64)*p;
87037 }
87038-static inline __u64 __le64_to_cpup(const __le64 *p)
87039+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
87040 {
87041- return (__force __u64)*p;
87042+ return (__force const __u64)*p;
87043 }
87044 static inline __le32 __cpu_to_le32p(const __u32 *p)
87045 {
87046- return (__force __le32)*p;
87047+ return (__force const __le32)*p;
87048 }
87049 static inline __u32 __le32_to_cpup(const __le32 *p)
87050 {
87051- return (__force __u32)*p;
87052+ return (__force const __u32)*p;
87053 }
87054 static inline __le16 __cpu_to_le16p(const __u16 *p)
87055 {
87056- return (__force __le16)*p;
87057+ return (__force const __le16)*p;
87058 }
87059 static inline __u16 __le16_to_cpup(const __le16 *p)
87060 {
87061- return (__force __u16)*p;
87062+ return (__force const __u16)*p;
87063 }
87064 static inline __be64 __cpu_to_be64p(const __u64 *p)
87065 {
87066- return (__force __be64)__swab64p(p);
87067+ return (__force const __be64)__swab64p(p);
87068 }
87069 static inline __u64 __be64_to_cpup(const __be64 *p)
87070 {
87071- return __swab64p((__u64 *)p);
87072+ return __swab64p((const __u64 *)p);
87073 }
87074 static inline __be32 __cpu_to_be32p(const __u32 *p)
87075 {
87076- return (__force __be32)__swab32p(p);
87077+ return (__force const __be32)__swab32p(p);
87078 }
87079-static inline __u32 __be32_to_cpup(const __be32 *p)
87080+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
87081 {
87082- return __swab32p((__u32 *)p);
87083+ return __swab32p((const __u32 *)p);
87084 }
87085 static inline __be16 __cpu_to_be16p(const __u16 *p)
87086 {
87087- return (__force __be16)__swab16p(p);
87088+ return (__force const __be16)__swab16p(p);
87089 }
87090 static inline __u16 __be16_to_cpup(const __be16 *p)
87091 {
87092- return __swab16p((__u16 *)p);
87093+ return __swab16p((const __u16 *)p);
87094 }
87095 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
87096 #define __le64_to_cpus(x) do { (void)(x); } while (0)
87097diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
87098index ea9bf25..5140c61 100644
87099--- a/include/uapi/linux/elf.h
87100+++ b/include/uapi/linux/elf.h
87101@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
87102 #define PT_GNU_EH_FRAME 0x6474e550
87103
87104 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
87105+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
87106+
87107+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
87108+
87109+/* Constants for the e_flags field */
87110+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
87111+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
87112+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
87113+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
87114+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
87115+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
87116
87117 /*
87118 * Extended Numbering
87119@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
87120 #define DT_DEBUG 21
87121 #define DT_TEXTREL 22
87122 #define DT_JMPREL 23
87123+#define DT_FLAGS 30
87124+ #define DF_TEXTREL 0x00000004
87125 #define DT_ENCODING 32
87126 #define OLD_DT_LOOS 0x60000000
87127 #define DT_LOOS 0x6000000d
87128@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
87129 #define PF_W 0x2
87130 #define PF_X 0x1
87131
87132+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
87133+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
87134+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
87135+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
87136+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
87137+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
87138+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
87139+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
87140+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
87141+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
87142+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
87143+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
87144+
87145 typedef struct elf32_phdr{
87146 Elf32_Word p_type;
87147 Elf32_Off p_offset;
87148@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
87149 #define EI_OSABI 7
87150 #define EI_PAD 8
87151
87152+#define EI_PAX 14
87153+
87154 #define ELFMAG0 0x7f /* EI_MAG */
87155 #define ELFMAG1 'E'
87156 #define ELFMAG2 'L'
87157diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
87158index aa169c4..6a2771d 100644
87159--- a/include/uapi/linux/personality.h
87160+++ b/include/uapi/linux/personality.h
87161@@ -30,6 +30,7 @@ enum {
87162 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
87163 ADDR_NO_RANDOMIZE | \
87164 ADDR_COMPAT_LAYOUT | \
87165+ ADDR_LIMIT_3GB | \
87166 MMAP_PAGE_ZERO)
87167
87168 /*
87169diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
87170index 7530e74..e714828 100644
87171--- a/include/uapi/linux/screen_info.h
87172+++ b/include/uapi/linux/screen_info.h
87173@@ -43,7 +43,8 @@ struct screen_info {
87174 __u16 pages; /* 0x32 */
87175 __u16 vesa_attributes; /* 0x34 */
87176 __u32 capabilities; /* 0x36 */
87177- __u8 _reserved[6]; /* 0x3a */
87178+ __u16 vesapm_size; /* 0x3a */
87179+ __u8 _reserved[4]; /* 0x3c */
87180 } __attribute__((packed));
87181
87182 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
87183diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
87184index 0e011eb..82681b1 100644
87185--- a/include/uapi/linux/swab.h
87186+++ b/include/uapi/linux/swab.h
87187@@ -43,7 +43,7 @@
87188 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
87189 */
87190
87191-static inline __attribute_const__ __u16 __fswab16(__u16 val)
87192+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
87193 {
87194 #ifdef __HAVE_BUILTIN_BSWAP16__
87195 return __builtin_bswap16(val);
87196@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
87197 #endif
87198 }
87199
87200-static inline __attribute_const__ __u32 __fswab32(__u32 val)
87201+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
87202 {
87203 #ifdef __HAVE_BUILTIN_BSWAP32__
87204 return __builtin_bswap32(val);
87205@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
87206 #endif
87207 }
87208
87209-static inline __attribute_const__ __u64 __fswab64(__u64 val)
87210+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
87211 {
87212 #ifdef __HAVE_BUILTIN_BSWAP64__
87213 return __builtin_bswap64(val);
87214diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
87215index 43aaba1..1c30b48 100644
87216--- a/include/uapi/linux/sysctl.h
87217+++ b/include/uapi/linux/sysctl.h
87218@@ -155,8 +155,6 @@ enum
87219 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
87220 };
87221
87222-
87223-
87224 /* CTL_VM names: */
87225 enum
87226 {
87227diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
87228index 1590c49..5eab462 100644
87229--- a/include/uapi/linux/xattr.h
87230+++ b/include/uapi/linux/xattr.h
87231@@ -73,5 +73,9 @@
87232 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
87233 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
87234
87235+/* User namespace */
87236+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
87237+#define XATTR_PAX_FLAGS_SUFFIX "flags"
87238+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
87239
87240 #endif /* _UAPI_LINUX_XATTR_H */
87241diff --git a/include/video/udlfb.h b/include/video/udlfb.h
87242index f9466fa..f4e2b81 100644
87243--- a/include/video/udlfb.h
87244+++ b/include/video/udlfb.h
87245@@ -53,10 +53,10 @@ struct dlfb_data {
87246 u32 pseudo_palette[256];
87247 int blank_mode; /*one of FB_BLANK_ */
87248 /* blit-only rendering path metrics, exposed through sysfs */
87249- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
87250- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
87251- atomic_t bytes_sent; /* to usb, after compression including overhead */
87252- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
87253+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
87254+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
87255+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
87256+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
87257 };
87258
87259 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
87260diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
87261index 30f5362..8ed8ac9 100644
87262--- a/include/video/uvesafb.h
87263+++ b/include/video/uvesafb.h
87264@@ -122,6 +122,7 @@ struct uvesafb_par {
87265 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
87266 u8 pmi_setpal; /* PMI for palette changes */
87267 u16 *pmi_base; /* protected mode interface location */
87268+ u8 *pmi_code; /* protected mode code location */
87269 void *pmi_start;
87270 void *pmi_pal;
87271 u8 *vbe_state_orig; /*
87272diff --git a/init/Kconfig b/init/Kconfig
87273index 2081a4d..98d1149 100644
87274--- a/init/Kconfig
87275+++ b/init/Kconfig
87276@@ -1150,6 +1150,7 @@ endif # CGROUPS
87277
87278 config CHECKPOINT_RESTORE
87279 bool "Checkpoint/restore support" if EXPERT
87280+ depends on !GRKERNSEC
87281 default n
87282 help
87283 Enables additional kernel features in a sake of checkpoint/restore.
87284@@ -1659,7 +1660,7 @@ config SLUB_DEBUG
87285
87286 config COMPAT_BRK
87287 bool "Disable heap randomization"
87288- default y
87289+ default n
87290 help
87291 Randomizing heap placement makes heap exploits harder, but it
87292 also breaks ancient binaries (including anything libc5 based).
87293@@ -1990,7 +1991,7 @@ config INIT_ALL_POSSIBLE
87294 config STOP_MACHINE
87295 bool
87296 default y
87297- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
87298+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
87299 help
87300 Need stop_machine() primitive.
87301
87302diff --git a/init/Makefile b/init/Makefile
87303index 7bc47ee..6da2dc7 100644
87304--- a/init/Makefile
87305+++ b/init/Makefile
87306@@ -2,6 +2,9 @@
87307 # Makefile for the linux kernel.
87308 #
87309
87310+ccflags-y := $(GCC_PLUGINS_CFLAGS)
87311+asflags-y := $(GCC_PLUGINS_AFLAGS)
87312+
87313 obj-y := main.o version.o mounts.o
87314 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
87315 obj-y += noinitramfs.o
87316diff --git a/init/do_mounts.c b/init/do_mounts.c
87317index 9b3565c..3f90cf9 100644
87318--- a/init/do_mounts.c
87319+++ b/init/do_mounts.c
87320@@ -360,11 +360,11 @@ static void __init get_fs_names(char *page)
87321 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
87322 {
87323 struct super_block *s;
87324- int err = sys_mount(name, "/root", fs, flags, data);
87325+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
87326 if (err)
87327 return err;
87328
87329- sys_chdir("/root");
87330+ sys_chdir((const char __force_user *)"/root");
87331 s = current->fs->pwd.dentry->d_sb;
87332 ROOT_DEV = s->s_dev;
87333 printk(KERN_INFO
87334@@ -485,18 +485,18 @@ void __init change_floppy(char *fmt, ...)
87335 va_start(args, fmt);
87336 vsprintf(buf, fmt, args);
87337 va_end(args);
87338- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
87339+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
87340 if (fd >= 0) {
87341 sys_ioctl(fd, FDEJECT, 0);
87342 sys_close(fd);
87343 }
87344 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
87345- fd = sys_open("/dev/console", O_RDWR, 0);
87346+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
87347 if (fd >= 0) {
87348 sys_ioctl(fd, TCGETS, (long)&termios);
87349 termios.c_lflag &= ~ICANON;
87350 sys_ioctl(fd, TCSETSF, (long)&termios);
87351- sys_read(fd, &c, 1);
87352+ sys_read(fd, (char __user *)&c, 1);
87353 termios.c_lflag |= ICANON;
87354 sys_ioctl(fd, TCSETSF, (long)&termios);
87355 sys_close(fd);
87356@@ -590,8 +590,8 @@ void __init prepare_namespace(void)
87357 mount_root();
87358 out:
87359 devtmpfs_mount("dev");
87360- sys_mount(".", "/", NULL, MS_MOVE, NULL);
87361- sys_chroot(".");
87362+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
87363+ sys_chroot((const char __force_user *)".");
87364 }
87365
87366 static bool is_tmpfs;
87367diff --git a/init/do_mounts.h b/init/do_mounts.h
87368index f5b978a..69dbfe8 100644
87369--- a/init/do_mounts.h
87370+++ b/init/do_mounts.h
87371@@ -15,15 +15,15 @@ extern int root_mountflags;
87372
87373 static inline int create_dev(char *name, dev_t dev)
87374 {
87375- sys_unlink(name);
87376- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
87377+ sys_unlink((char __force_user *)name);
87378+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
87379 }
87380
87381 #if BITS_PER_LONG == 32
87382 static inline u32 bstat(char *name)
87383 {
87384 struct stat64 stat;
87385- if (sys_stat64(name, &stat) != 0)
87386+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
87387 return 0;
87388 if (!S_ISBLK(stat.st_mode))
87389 return 0;
87390@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
87391 static inline u32 bstat(char *name)
87392 {
87393 struct stat stat;
87394- if (sys_newstat(name, &stat) != 0)
87395+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
87396 return 0;
87397 if (!S_ISBLK(stat.st_mode))
87398 return 0;
87399diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
87400index 3e0878e..8a9d7a0 100644
87401--- a/init/do_mounts_initrd.c
87402+++ b/init/do_mounts_initrd.c
87403@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
87404 {
87405 sys_unshare(CLONE_FS | CLONE_FILES);
87406 /* stdin/stdout/stderr for /linuxrc */
87407- sys_open("/dev/console", O_RDWR, 0);
87408+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
87409 sys_dup(0);
87410 sys_dup(0);
87411 /* move initrd over / and chdir/chroot in initrd root */
87412- sys_chdir("/root");
87413- sys_mount(".", "/", NULL, MS_MOVE, NULL);
87414- sys_chroot(".");
87415+ sys_chdir((const char __force_user *)"/root");
87416+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
87417+ sys_chroot((const char __force_user *)".");
87418 sys_setsid();
87419 return 0;
87420 }
87421@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
87422 create_dev("/dev/root.old", Root_RAM0);
87423 /* mount initrd on rootfs' /root */
87424 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
87425- sys_mkdir("/old", 0700);
87426- sys_chdir("/old");
87427+ sys_mkdir((const char __force_user *)"/old", 0700);
87428+ sys_chdir((const char __force_user *)"/old");
87429
87430 /* try loading default modules from initrd */
87431 load_default_modules();
87432@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
87433 current->flags &= ~PF_FREEZER_SKIP;
87434
87435 /* move initrd to rootfs' /old */
87436- sys_mount("..", ".", NULL, MS_MOVE, NULL);
87437+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
87438 /* switch root and cwd back to / of rootfs */
87439- sys_chroot("..");
87440+ sys_chroot((const char __force_user *)"..");
87441
87442 if (new_decode_dev(real_root_dev) == Root_RAM0) {
87443- sys_chdir("/old");
87444+ sys_chdir((const char __force_user *)"/old");
87445 return;
87446 }
87447
87448- sys_chdir("/");
87449+ sys_chdir((const char __force_user *)"/");
87450 ROOT_DEV = new_decode_dev(real_root_dev);
87451 mount_root();
87452
87453 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
87454- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
87455+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
87456 if (!error)
87457 printk("okay\n");
87458 else {
87459- int fd = sys_open("/dev/root.old", O_RDWR, 0);
87460+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
87461 if (error == -ENOENT)
87462 printk("/initrd does not exist. Ignored.\n");
87463 else
87464 printk("failed\n");
87465 printk(KERN_NOTICE "Unmounting old root\n");
87466- sys_umount("/old", MNT_DETACH);
87467+ sys_umount((char __force_user *)"/old", MNT_DETACH);
87468 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
87469 if (fd < 0) {
87470 error = fd;
87471@@ -127,11 +127,11 @@ int __init initrd_load(void)
87472 * mounted in the normal path.
87473 */
87474 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
87475- sys_unlink("/initrd.image");
87476+ sys_unlink((const char __force_user *)"/initrd.image");
87477 handle_initrd();
87478 return 1;
87479 }
87480 }
87481- sys_unlink("/initrd.image");
87482+ sys_unlink((const char __force_user *)"/initrd.image");
87483 return 0;
87484 }
87485diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
87486index 8cb6db5..d729f50 100644
87487--- a/init/do_mounts_md.c
87488+++ b/init/do_mounts_md.c
87489@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
87490 partitioned ? "_d" : "", minor,
87491 md_setup_args[ent].device_names);
87492
87493- fd = sys_open(name, 0, 0);
87494+ fd = sys_open((char __force_user *)name, 0, 0);
87495 if (fd < 0) {
87496 printk(KERN_ERR "md: open failed - cannot start "
87497 "array %s\n", name);
87498@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
87499 * array without it
87500 */
87501 sys_close(fd);
87502- fd = sys_open(name, 0, 0);
87503+ fd = sys_open((char __force_user *)name, 0, 0);
87504 sys_ioctl(fd, BLKRRPART, 0);
87505 }
87506 sys_close(fd);
87507@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
87508
87509 wait_for_device_probe();
87510
87511- fd = sys_open("/dev/md0", 0, 0);
87512+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
87513 if (fd >= 0) {
87514 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
87515 sys_close(fd);
87516diff --git a/init/init_task.c b/init/init_task.c
87517index ba0a7f36..2bcf1d5 100644
87518--- a/init/init_task.c
87519+++ b/init/init_task.c
87520@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
87521 * Initial thread structure. Alignment of this is handled by a special
87522 * linker map entry.
87523 */
87524+#ifdef CONFIG_X86
87525+union thread_union init_thread_union __init_task_data;
87526+#else
87527 union thread_union init_thread_union __init_task_data =
87528 { INIT_THREAD_INFO(init_task) };
87529+#endif
87530diff --git a/init/initramfs.c b/init/initramfs.c
87531index ad1bd77..dca2c1b 100644
87532--- a/init/initramfs.c
87533+++ b/init/initramfs.c
87534@@ -25,7 +25,7 @@ static ssize_t __init xwrite(int fd, const char *p, size_t count)
87535
87536 /* sys_write only can write MAX_RW_COUNT aka 2G-4K bytes at most */
87537 while (count) {
87538- ssize_t rv = sys_write(fd, p, count);
87539+ ssize_t rv = sys_write(fd, (char __force_user *)p, count);
87540
87541 if (rv < 0) {
87542 if (rv == -EINTR || rv == -EAGAIN)
87543@@ -107,7 +107,7 @@ static void __init free_hash(void)
87544 }
87545 }
87546
87547-static long __init do_utime(char *filename, time_t mtime)
87548+static long __init do_utime(char __force_user *filename, time_t mtime)
87549 {
87550 struct timespec t[2];
87551
87552@@ -142,7 +142,7 @@ static void __init dir_utime(void)
87553 struct dir_entry *de, *tmp;
87554 list_for_each_entry_safe(de, tmp, &dir_list, list) {
87555 list_del(&de->list);
87556- do_utime(de->name, de->mtime);
87557+ do_utime((char __force_user *)de->name, de->mtime);
87558 kfree(de->name);
87559 kfree(de);
87560 }
87561@@ -304,7 +304,7 @@ static int __init maybe_link(void)
87562 if (nlink >= 2) {
87563 char *old = find_link(major, minor, ino, mode, collected);
87564 if (old)
87565- return (sys_link(old, collected) < 0) ? -1 : 1;
87566+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
87567 }
87568 return 0;
87569 }
87570@@ -313,11 +313,11 @@ static void __init clean_path(char *path, umode_t fmode)
87571 {
87572 struct stat st;
87573
87574- if (!sys_newlstat(path, &st) && (st.st_mode ^ fmode) & S_IFMT) {
87575+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode ^ fmode) & S_IFMT) {
87576 if (S_ISDIR(st.st_mode))
87577- sys_rmdir(path);
87578+ sys_rmdir((char __force_user *)path);
87579 else
87580- sys_unlink(path);
87581+ sys_unlink((char __force_user *)path);
87582 }
87583 }
87584
87585@@ -338,7 +338,7 @@ static int __init do_name(void)
87586 int openflags = O_WRONLY|O_CREAT;
87587 if (ml != 1)
87588 openflags |= O_TRUNC;
87589- wfd = sys_open(collected, openflags, mode);
87590+ wfd = sys_open((char __force_user *)collected, openflags, mode);
87591
87592 if (wfd >= 0) {
87593 sys_fchown(wfd, uid, gid);
87594@@ -350,17 +350,17 @@ static int __init do_name(void)
87595 }
87596 }
87597 } else if (S_ISDIR(mode)) {
87598- sys_mkdir(collected, mode);
87599- sys_chown(collected, uid, gid);
87600- sys_chmod(collected, mode);
87601+ sys_mkdir((char __force_user *)collected, mode);
87602+ sys_chown((char __force_user *)collected, uid, gid);
87603+ sys_chmod((char __force_user *)collected, mode);
87604 dir_add(collected, mtime);
87605 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
87606 S_ISFIFO(mode) || S_ISSOCK(mode)) {
87607 if (maybe_link() == 0) {
87608- sys_mknod(collected, mode, rdev);
87609- sys_chown(collected, uid, gid);
87610- sys_chmod(collected, mode);
87611- do_utime(collected, mtime);
87612+ sys_mknod((char __force_user *)collected, mode, rdev);
87613+ sys_chown((char __force_user *)collected, uid, gid);
87614+ sys_chmod((char __force_user *)collected, mode);
87615+ do_utime((char __force_user *)collected, mtime);
87616 }
87617 }
87618 return 0;
87619@@ -372,7 +372,7 @@ static int __init do_copy(void)
87620 if (xwrite(wfd, victim, body_len) != body_len)
87621 error("write error");
87622 sys_close(wfd);
87623- do_utime(vcollected, mtime);
87624+ do_utime((char __force_user *)vcollected, mtime);
87625 kfree(vcollected);
87626 eat(body_len);
87627 state = SkipIt;
87628@@ -390,9 +390,9 @@ static int __init do_symlink(void)
87629 {
87630 collected[N_ALIGN(name_len) + body_len] = '\0';
87631 clean_path(collected, 0);
87632- sys_symlink(collected + N_ALIGN(name_len), collected);
87633- sys_lchown(collected, uid, gid);
87634- do_utime(collected, mtime);
87635+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
87636+ sys_lchown((char __force_user *)collected, uid, gid);
87637+ do_utime((char __force_user *)collected, mtime);
87638 state = SkipIt;
87639 next_state = Reset;
87640 return 0;
87641diff --git a/init/main.c b/init/main.c
87642index 321d0ce..91b53e5 100644
87643--- a/init/main.c
87644+++ b/init/main.c
87645@@ -98,6 +98,8 @@ extern void radix_tree_init(void);
87646 static inline void mark_rodata_ro(void) { }
87647 #endif
87648
87649+extern void grsecurity_init(void);
87650+
87651 /*
87652 * Debug helper: via this flag we know that we are in 'early bootup code'
87653 * where only the boot processor is running with IRQ disabled. This means
87654@@ -159,6 +161,75 @@ static int __init set_reset_devices(char *str)
87655
87656 __setup("reset_devices", set_reset_devices);
87657
87658+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
87659+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
87660+static int __init setup_grsec_proc_gid(char *str)
87661+{
87662+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
87663+ return 1;
87664+}
87665+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
87666+#endif
87667+
87668+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
87669+unsigned long pax_user_shadow_base __read_only;
87670+EXPORT_SYMBOL(pax_user_shadow_base);
87671+extern char pax_enter_kernel_user[];
87672+extern char pax_exit_kernel_user[];
87673+#endif
87674+
87675+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
87676+static int __init setup_pax_nouderef(char *str)
87677+{
87678+#ifdef CONFIG_X86_32
87679+ unsigned int cpu;
87680+ struct desc_struct *gdt;
87681+
87682+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
87683+ gdt = get_cpu_gdt_table(cpu);
87684+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
87685+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
87686+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
87687+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
87688+ }
87689+ loadsegment(ds, __KERNEL_DS);
87690+ loadsegment(es, __KERNEL_DS);
87691+ loadsegment(ss, __KERNEL_DS);
87692+#else
87693+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
87694+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
87695+ clone_pgd_mask = ~(pgdval_t)0UL;
87696+ pax_user_shadow_base = 0UL;
87697+ setup_clear_cpu_cap(X86_FEATURE_PCID);
87698+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
87699+#endif
87700+
87701+ return 0;
87702+}
87703+early_param("pax_nouderef", setup_pax_nouderef);
87704+
87705+#ifdef CONFIG_X86_64
87706+static int __init setup_pax_weakuderef(char *str)
87707+{
87708+ if (clone_pgd_mask != ~(pgdval_t)0UL)
87709+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
87710+ return 1;
87711+}
87712+__setup("pax_weakuderef", setup_pax_weakuderef);
87713+#endif
87714+#endif
87715+
87716+#ifdef CONFIG_PAX_SOFTMODE
87717+int pax_softmode;
87718+
87719+static int __init setup_pax_softmode(char *str)
87720+{
87721+ get_option(&str, &pax_softmode);
87722+ return 1;
87723+}
87724+__setup("pax_softmode=", setup_pax_softmode);
87725+#endif
87726+
87727 static const char *argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
87728 const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
87729 static const char *panic_later, *panic_param;
87730@@ -728,7 +799,7 @@ static bool __init_or_module initcall_blacklisted(initcall_t fn)
87731 struct blacklist_entry *entry;
87732 char *fn_name;
87733
87734- fn_name = kasprintf(GFP_KERNEL, "%pf", fn);
87735+ fn_name = kasprintf(GFP_KERNEL, "%pX", fn);
87736 if (!fn_name)
87737 return false;
87738
87739@@ -780,7 +851,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
87740 {
87741 int count = preempt_count();
87742 int ret;
87743- char msgbuf[64];
87744+ const char *msg1 = "", *msg2 = "";
87745
87746 if (initcall_blacklisted(fn))
87747 return -EPERM;
87748@@ -790,18 +861,17 @@ int __init_or_module do_one_initcall(initcall_t fn)
87749 else
87750 ret = fn();
87751
87752- msgbuf[0] = 0;
87753-
87754 if (preempt_count() != count) {
87755- sprintf(msgbuf, "preemption imbalance ");
87756+ msg1 = " preemption imbalance";
87757 preempt_count_set(count);
87758 }
87759 if (irqs_disabled()) {
87760- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
87761+ msg2 = " disabled interrupts";
87762 local_irq_enable();
87763 }
87764- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
87765+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
87766
87767+ add_latent_entropy();
87768 return ret;
87769 }
87770
87771@@ -907,8 +977,8 @@ static int run_init_process(const char *init_filename)
87772 {
87773 argv_init[0] = init_filename;
87774 return do_execve(getname_kernel(init_filename),
87775- (const char __user *const __user *)argv_init,
87776- (const char __user *const __user *)envp_init);
87777+ (const char __user *const __force_user *)argv_init,
87778+ (const char __user *const __force_user *)envp_init);
87779 }
87780
87781 static int try_to_run_init_process(const char *init_filename)
87782@@ -925,6 +995,10 @@ static int try_to_run_init_process(const char *init_filename)
87783 return ret;
87784 }
87785
87786+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
87787+extern int gr_init_ran;
87788+#endif
87789+
87790 static noinline void __init kernel_init_freeable(void);
87791
87792 static int __ref kernel_init(void *unused)
87793@@ -949,6 +1023,11 @@ static int __ref kernel_init(void *unused)
87794 ramdisk_execute_command, ret);
87795 }
87796
87797+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
87798+ /* if no initrd was used, be extra sure we enforce chroot restrictions */
87799+ gr_init_ran = 1;
87800+#endif
87801+
87802 /*
87803 * We try each of these until one succeeds.
87804 *
87805@@ -1004,7 +1083,7 @@ static noinline void __init kernel_init_freeable(void)
87806 do_basic_setup();
87807
87808 /* Open the /dev/console on the rootfs, this should never fail */
87809- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
87810+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
87811 pr_err("Warning: unable to open an initial console.\n");
87812
87813 (void) sys_dup(0);
87814@@ -1017,11 +1096,13 @@ static noinline void __init kernel_init_freeable(void)
87815 if (!ramdisk_execute_command)
87816 ramdisk_execute_command = "/init";
87817
87818- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
87819+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
87820 ramdisk_execute_command = NULL;
87821 prepare_namespace();
87822 }
87823
87824+ grsecurity_init();
87825+
87826 /*
87827 * Ok, we have completed the initial bootup, and
87828 * we're essentially up and running. Get rid of the
87829diff --git a/ipc/compat.c b/ipc/compat.c
87830index 9b3c85f..1c4d897 100644
87831--- a/ipc/compat.c
87832+++ b/ipc/compat.c
87833@@ -396,7 +396,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
87834 COMPAT_SHMLBA);
87835 if (err < 0)
87836 return err;
87837- return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
87838+ return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
87839 }
87840 case SHMDT:
87841 return sys_shmdt(compat_ptr(ptr));
87842diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
87843index e8075b2..76f2c6a 100644
87844--- a/ipc/ipc_sysctl.c
87845+++ b/ipc/ipc_sysctl.c
87846@@ -30,7 +30,7 @@ static void *get_ipc(struct ctl_table *table)
87847 static int proc_ipc_dointvec(struct ctl_table *table, int write,
87848 void __user *buffer, size_t *lenp, loff_t *ppos)
87849 {
87850- struct ctl_table ipc_table;
87851+ ctl_table_no_const ipc_table;
87852
87853 memcpy(&ipc_table, table, sizeof(ipc_table));
87854 ipc_table.data = get_ipc(table);
87855@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(struct ctl_table *table, int write,
87856 static int proc_ipc_dointvec_minmax(struct ctl_table *table, int write,
87857 void __user *buffer, size_t *lenp, loff_t *ppos)
87858 {
87859- struct ctl_table ipc_table;
87860+ ctl_table_no_const ipc_table;
87861
87862 memcpy(&ipc_table, table, sizeof(ipc_table));
87863 ipc_table.data = get_ipc(table);
87864@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(struct ctl_table *table, int write,
87865 static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
87866 void __user *buffer, size_t *lenp, loff_t *ppos)
87867 {
87868- struct ctl_table ipc_table;
87869+ ctl_table_no_const ipc_table;
87870 size_t lenp_bef = *lenp;
87871 int rc;
87872
87873@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
87874 static int proc_ipc_doulongvec_minmax(struct ctl_table *table, int write,
87875 void __user *buffer, size_t *lenp, loff_t *ppos)
87876 {
87877- struct ctl_table ipc_table;
87878+ ctl_table_no_const ipc_table;
87879 memcpy(&ipc_table, table, sizeof(ipc_table));
87880 ipc_table.data = get_ipc(table);
87881
87882@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
87883 static int proc_ipcauto_dointvec_minmax(struct ctl_table *table, int write,
87884 void __user *buffer, size_t *lenp, loff_t *ppos)
87885 {
87886- struct ctl_table ipc_table;
87887+ ctl_table_no_const ipc_table;
87888 int oldval;
87889 int rc;
87890
87891diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
87892index 68d4e95..1477ded 100644
87893--- a/ipc/mq_sysctl.c
87894+++ b/ipc/mq_sysctl.c
87895@@ -25,7 +25,7 @@ static void *get_mq(struct ctl_table *table)
87896 static int proc_mq_dointvec(struct ctl_table *table, int write,
87897 void __user *buffer, size_t *lenp, loff_t *ppos)
87898 {
87899- struct ctl_table mq_table;
87900+ ctl_table_no_const mq_table;
87901 memcpy(&mq_table, table, sizeof(mq_table));
87902 mq_table.data = get_mq(table);
87903
87904@@ -35,7 +35,7 @@ static int proc_mq_dointvec(struct ctl_table *table, int write,
87905 static int proc_mq_dointvec_minmax(struct ctl_table *table, int write,
87906 void __user *buffer, size_t *lenp, loff_t *ppos)
87907 {
87908- struct ctl_table mq_table;
87909+ ctl_table_no_const mq_table;
87910 memcpy(&mq_table, table, sizeof(mq_table));
87911 mq_table.data = get_mq(table);
87912
87913diff --git a/ipc/mqueue.c b/ipc/mqueue.c
87914index 4fcf39a..d3cc2ec 100644
87915--- a/ipc/mqueue.c
87916+++ b/ipc/mqueue.c
87917@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
87918 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
87919 info->attr.mq_msgsize);
87920
87921+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
87922 spin_lock(&mq_lock);
87923 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
87924 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
87925diff --git a/ipc/shm.c b/ipc/shm.c
87926index 0145479..3d27947 100644
87927--- a/ipc/shm.c
87928+++ b/ipc/shm.c
87929@@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
87930 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
87931 #endif
87932
87933+#ifdef CONFIG_GRKERNSEC
87934+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
87935+ const u64 shm_createtime, const kuid_t cuid,
87936+ const int shmid);
87937+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
87938+ const u64 shm_createtime);
87939+#endif
87940+
87941 void shm_init_ns(struct ipc_namespace *ns)
87942 {
87943 ns->shm_ctlmax = SHMMAX;
87944@@ -559,6 +567,9 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
87945 shp->shm_lprid = 0;
87946 shp->shm_atim = shp->shm_dtim = 0;
87947 shp->shm_ctim = get_seconds();
87948+#ifdef CONFIG_GRKERNSEC
87949+ shp->shm_createtime = ktime_get_ns();
87950+#endif
87951 shp->shm_segsz = size;
87952 shp->shm_nattch = 0;
87953 shp->shm_file = file;
87954@@ -1095,6 +1106,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
87955 f_mode = FMODE_READ | FMODE_WRITE;
87956 }
87957 if (shmflg & SHM_EXEC) {
87958+
87959+#ifdef CONFIG_PAX_MPROTECT
87960+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
87961+ goto out;
87962+#endif
87963+
87964 prot |= PROT_EXEC;
87965 acc_mode |= S_IXUGO;
87966 }
87967@@ -1119,6 +1136,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
87968 if (err)
87969 goto out_unlock;
87970
87971+#ifdef CONFIG_GRKERNSEC
87972+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
87973+ shp->shm_perm.cuid, shmid) ||
87974+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
87975+ err = -EACCES;
87976+ goto out_unlock;
87977+ }
87978+#endif
87979+
87980 ipc_lock_object(&shp->shm_perm);
87981
87982 /* check if shm_destroy() is tearing down shp */
87983@@ -1131,6 +1157,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
87984 path = shp->shm_file->f_path;
87985 path_get(&path);
87986 shp->shm_nattch++;
87987+#ifdef CONFIG_GRKERNSEC
87988+ shp->shm_lapid = current->pid;
87989+#endif
87990 size = i_size_read(path.dentry->d_inode);
87991 ipc_unlock_object(&shp->shm_perm);
87992 rcu_read_unlock();
87993diff --git a/ipc/util.c b/ipc/util.c
87994index 88adc32..3867c68 100644
87995--- a/ipc/util.c
87996+++ b/ipc/util.c
87997@@ -71,6 +71,8 @@ struct ipc_proc_iface {
87998 int (*show)(struct seq_file *, void *);
87999 };
88000
88001+extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
88002+
88003 static void ipc_memory_notifier(struct work_struct *work)
88004 {
88005 ipcns_notify(IPCNS_MEMCHANGED);
88006@@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
88007 granted_mode >>= 6;
88008 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
88009 granted_mode >>= 3;
88010+
88011+ if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
88012+ return -1;
88013+
88014 /* is there some bit set in requested_mode but not in granted_mode? */
88015 if ((requested_mode & ~granted_mode & 0007) &&
88016 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
88017diff --git a/kernel/audit.c b/kernel/audit.c
88018index cebb11d..4e0295f 100644
88019--- a/kernel/audit.c
88020+++ b/kernel/audit.c
88021@@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
88022 3) suppressed due to audit_rate_limit
88023 4) suppressed due to audit_backlog_limit
88024 */
88025-static atomic_t audit_lost = ATOMIC_INIT(0);
88026+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
88027
88028 /* The netlink socket. */
88029 static struct sock *audit_sock;
88030@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
88031 unsigned long now;
88032 int print;
88033
88034- atomic_inc(&audit_lost);
88035+ atomic_inc_unchecked(&audit_lost);
88036
88037 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
88038
88039@@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
88040 if (print) {
88041 if (printk_ratelimit())
88042 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
88043- atomic_read(&audit_lost),
88044+ atomic_read_unchecked(&audit_lost),
88045 audit_rate_limit,
88046 audit_backlog_limit);
88047 audit_panic(message);
88048@@ -840,7 +840,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
88049 s.pid = audit_pid;
88050 s.rate_limit = audit_rate_limit;
88051 s.backlog_limit = audit_backlog_limit;
88052- s.lost = atomic_read(&audit_lost);
88053+ s.lost = atomic_read_unchecked(&audit_lost);
88054 s.backlog = skb_queue_len(&audit_skb_queue);
88055 s.version = AUDIT_VERSION_LATEST;
88056 s.backlog_wait_time = audit_backlog_wait_time;
88057diff --git a/kernel/auditsc.c b/kernel/auditsc.c
88058index e420a0c..38137fa 100644
88059--- a/kernel/auditsc.c
88060+++ b/kernel/auditsc.c
88061@@ -2014,7 +2014,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
88062 }
88063
88064 /* global counter which is incremented every time something logs in */
88065-static atomic_t session_id = ATOMIC_INIT(0);
88066+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
88067
88068 static int audit_set_loginuid_perm(kuid_t loginuid)
88069 {
88070@@ -2081,7 +2081,7 @@ int audit_set_loginuid(kuid_t loginuid)
88071
88072 /* are we setting or clearing? */
88073 if (uid_valid(loginuid))
88074- sessionid = (unsigned int)atomic_inc_return(&session_id);
88075+ sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
88076
88077 task->sessionid = sessionid;
88078 task->loginuid = loginuid;
88079diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
88080index d6594e4..597264b 100644
88081--- a/kernel/bpf/core.c
88082+++ b/kernel/bpf/core.c
88083@@ -143,14 +143,17 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr,
88084 * random section of illegal instructions.
88085 */
88086 size = round_up(proglen + sizeof(*hdr) + 128, PAGE_SIZE);
88087- hdr = module_alloc(size);
88088+ hdr = module_alloc_exec(size);
88089 if (hdr == NULL)
88090 return NULL;
88091
88092 /* Fill space with illegal/arch-dep instructions. */
88093 bpf_fill_ill_insns(hdr, size);
88094
88095+ pax_open_kernel();
88096 hdr->pages = size / PAGE_SIZE;
88097+ pax_close_kernel();
88098+
88099 hole = min_t(unsigned int, size - (proglen + sizeof(*hdr)),
88100 PAGE_SIZE - sizeof(*hdr));
88101 start = (prandom_u32() % hole) & ~(alignment - 1);
88102@@ -163,7 +166,7 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr,
88103
88104 void bpf_jit_binary_free(struct bpf_binary_header *hdr)
88105 {
88106- module_free(NULL, hdr);
88107+ module_free_exec(NULL, hdr);
88108 }
88109 #endif /* CONFIG_BPF_JIT */
88110
88111diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
88112index ba61c8c..c60c486 100644
88113--- a/kernel/bpf/syscall.c
88114+++ b/kernel/bpf/syscall.c
88115@@ -539,11 +539,15 @@ SYSCALL_DEFINE3(bpf, int, cmd, union bpf_attr __user *, uattr, unsigned int, siz
88116 int err;
88117
88118 /* the syscall is limited to root temporarily. This restriction will be
88119- * lifted when security audit is clean. Note that eBPF+tracing must have
88120- * this restriction, since it may pass kernel data to user space
88121+ * lifted by upstream when a half-assed security audit is clean. Note
88122+ * that eBPF+tracing must have this restriction, since it may pass
88123+ * kernel data to user space
88124 */
88125 if (!capable(CAP_SYS_ADMIN))
88126 return -EPERM;
88127+#ifdef CONFIG_GRKERNSEC
88128+ return -EPERM;
88129+#endif
88130
88131 if (!access_ok(VERIFY_READ, uattr, 1))
88132 return -EFAULT;
88133diff --git a/kernel/capability.c b/kernel/capability.c
88134index 989f5bf..d317ca0 100644
88135--- a/kernel/capability.c
88136+++ b/kernel/capability.c
88137@@ -192,6 +192,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
88138 * before modification is attempted and the application
88139 * fails.
88140 */
88141+ if (tocopy > ARRAY_SIZE(kdata))
88142+ return -EFAULT;
88143+
88144 if (copy_to_user(dataptr, kdata, tocopy
88145 * sizeof(struct __user_cap_data_struct))) {
88146 return -EFAULT;
88147@@ -297,10 +300,11 @@ bool has_ns_capability(struct task_struct *t,
88148 int ret;
88149
88150 rcu_read_lock();
88151- ret = security_capable(__task_cred(t), ns, cap);
88152+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
88153+ gr_task_is_capable(t, __task_cred(t), cap);
88154 rcu_read_unlock();
88155
88156- return (ret == 0);
88157+ return ret;
88158 }
88159
88160 /**
88161@@ -337,10 +341,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
88162 int ret;
88163
88164 rcu_read_lock();
88165- ret = security_capable_noaudit(__task_cred(t), ns, cap);
88166+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
88167 rcu_read_unlock();
88168
88169- return (ret == 0);
88170+ return ret;
88171 }
88172
88173 /**
88174@@ -378,7 +382,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
88175 BUG();
88176 }
88177
88178- if (security_capable(current_cred(), ns, cap) == 0) {
88179+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
88180 current->flags |= PF_SUPERPRIV;
88181 return true;
88182 }
88183@@ -386,6 +390,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
88184 }
88185 EXPORT_SYMBOL(ns_capable);
88186
88187+bool ns_capable_nolog(struct user_namespace *ns, int cap)
88188+{
88189+ if (unlikely(!cap_valid(cap))) {
88190+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
88191+ BUG();
88192+ }
88193+
88194+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
88195+ current->flags |= PF_SUPERPRIV;
88196+ return true;
88197+ }
88198+ return false;
88199+}
88200+EXPORT_SYMBOL(ns_capable_nolog);
88201+
88202 /**
88203 * file_ns_capable - Determine if the file's opener had a capability in effect
88204 * @file: The file we want to check
88205@@ -427,6 +446,12 @@ bool capable(int cap)
88206 }
88207 EXPORT_SYMBOL(capable);
88208
88209+bool capable_nolog(int cap)
88210+{
88211+ return ns_capable_nolog(&init_user_ns, cap);
88212+}
88213+EXPORT_SYMBOL(capable_nolog);
88214+
88215 /**
88216 * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
88217 * @inode: The inode in question
88218@@ -444,3 +469,12 @@ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
88219 kgid_has_mapping(ns, inode->i_gid);
88220 }
88221 EXPORT_SYMBOL(capable_wrt_inode_uidgid);
88222+
88223+bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap)
88224+{
88225+ struct user_namespace *ns = current_user_ns();
88226+
88227+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
88228+ kgid_has_mapping(ns, inode->i_gid);
88229+}
88230+EXPORT_SYMBOL(capable_wrt_inode_uidgid_nolog);
88231diff --git a/kernel/cgroup.c b/kernel/cgroup.c
88232index 136ecea..45157a6 100644
88233--- a/kernel/cgroup.c
88234+++ b/kernel/cgroup.c
88235@@ -5276,6 +5276,9 @@ static void cgroup_release_agent(struct work_struct *work)
88236 if (!pathbuf || !agentbuf)
88237 goto out;
88238
88239+ if (agentbuf[0] == '\0')
88240+ goto out;
88241+
88242 path = cgroup_path(cgrp, pathbuf, PATH_MAX);
88243 if (!path)
88244 goto out;
88245@@ -5461,7 +5464,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
88246 struct task_struct *task;
88247 int count = 0;
88248
88249- seq_printf(seq, "css_set %p\n", cset);
88250+ seq_printf(seq, "css_set %pK\n", cset);
88251
88252 list_for_each_entry(task, &cset->tasks, cg_list) {
88253 if (count++ > MAX_TASKS_SHOWN_PER_CSS)
88254diff --git a/kernel/compat.c b/kernel/compat.c
88255index ebb3c36..1df606e 100644
88256--- a/kernel/compat.c
88257+++ b/kernel/compat.c
88258@@ -13,6 +13,7 @@
88259
88260 #include <linux/linkage.h>
88261 #include <linux/compat.h>
88262+#include <linux/module.h>
88263 #include <linux/errno.h>
88264 #include <linux/time.h>
88265 #include <linux/signal.h>
88266@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
88267 mm_segment_t oldfs;
88268 long ret;
88269
88270- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
88271+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
88272 oldfs = get_fs();
88273 set_fs(KERNEL_DS);
88274 ret = hrtimer_nanosleep_restart(restart);
88275@@ -252,7 +253,7 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
88276 oldfs = get_fs();
88277 set_fs(KERNEL_DS);
88278 ret = hrtimer_nanosleep(&tu,
88279- rmtp ? (struct timespec __user *)&rmt : NULL,
88280+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
88281 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
88282 set_fs(oldfs);
88283
88284@@ -379,7 +380,7 @@ COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set)
88285 mm_segment_t old_fs = get_fs();
88286
88287 set_fs(KERNEL_DS);
88288- ret = sys_sigpending((old_sigset_t __user *) &s);
88289+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
88290 set_fs(old_fs);
88291 if (ret == 0)
88292 ret = put_user(s, set);
88293@@ -469,7 +470,7 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
88294 mm_segment_t old_fs = get_fs();
88295
88296 set_fs(KERNEL_DS);
88297- ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r);
88298+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
88299 set_fs(old_fs);
88300
88301 if (!ret) {
88302@@ -551,8 +552,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
88303 set_fs (KERNEL_DS);
88304 ret = sys_wait4(pid,
88305 (stat_addr ?
88306- (unsigned int __user *) &status : NULL),
88307- options, (struct rusage __user *) &r);
88308+ (unsigned int __force_user *) &status : NULL),
88309+ options, (struct rusage __force_user *) &r);
88310 set_fs (old_fs);
88311
88312 if (ret > 0) {
88313@@ -578,8 +579,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
88314 memset(&info, 0, sizeof(info));
88315
88316 set_fs(KERNEL_DS);
88317- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
88318- uru ? (struct rusage __user *)&ru : NULL);
88319+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
88320+ uru ? (struct rusage __force_user *)&ru : NULL);
88321 set_fs(old_fs);
88322
88323 if ((ret < 0) || (info.si_signo == 0))
88324@@ -713,8 +714,8 @@ COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
88325 oldfs = get_fs();
88326 set_fs(KERNEL_DS);
88327 err = sys_timer_settime(timer_id, flags,
88328- (struct itimerspec __user *) &newts,
88329- (struct itimerspec __user *) &oldts);
88330+ (struct itimerspec __force_user *) &newts,
88331+ (struct itimerspec __force_user *) &oldts);
88332 set_fs(oldfs);
88333 if (!err && old && put_compat_itimerspec(old, &oldts))
88334 return -EFAULT;
88335@@ -731,7 +732,7 @@ COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
88336 oldfs = get_fs();
88337 set_fs(KERNEL_DS);
88338 err = sys_timer_gettime(timer_id,
88339- (struct itimerspec __user *) &ts);
88340+ (struct itimerspec __force_user *) &ts);
88341 set_fs(oldfs);
88342 if (!err && put_compat_itimerspec(setting, &ts))
88343 return -EFAULT;
88344@@ -750,7 +751,7 @@ COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
88345 oldfs = get_fs();
88346 set_fs(KERNEL_DS);
88347 err = sys_clock_settime(which_clock,
88348- (struct timespec __user *) &ts);
88349+ (struct timespec __force_user *) &ts);
88350 set_fs(oldfs);
88351 return err;
88352 }
88353@@ -765,7 +766,7 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
88354 oldfs = get_fs();
88355 set_fs(KERNEL_DS);
88356 err = sys_clock_gettime(which_clock,
88357- (struct timespec __user *) &ts);
88358+ (struct timespec __force_user *) &ts);
88359 set_fs(oldfs);
88360 if (!err && compat_put_timespec(&ts, tp))
88361 return -EFAULT;
88362@@ -785,7 +786,7 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
88363
88364 oldfs = get_fs();
88365 set_fs(KERNEL_DS);
88366- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
88367+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
88368 set_fs(oldfs);
88369
88370 err = compat_put_timex(utp, &txc);
88371@@ -805,7 +806,7 @@ COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
88372 oldfs = get_fs();
88373 set_fs(KERNEL_DS);
88374 err = sys_clock_getres(which_clock,
88375- (struct timespec __user *) &ts);
88376+ (struct timespec __force_user *) &ts);
88377 set_fs(oldfs);
88378 if (!err && tp && compat_put_timespec(&ts, tp))
88379 return -EFAULT;
88380@@ -819,7 +820,7 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
88381 struct timespec tu;
88382 struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
88383
88384- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
88385+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
88386 oldfs = get_fs();
88387 set_fs(KERNEL_DS);
88388 err = clock_nanosleep_restart(restart);
88389@@ -851,8 +852,8 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
88390 oldfs = get_fs();
88391 set_fs(KERNEL_DS);
88392 err = sys_clock_nanosleep(which_clock, flags,
88393- (struct timespec __user *) &in,
88394- (struct timespec __user *) &out);
88395+ (struct timespec __force_user *) &in,
88396+ (struct timespec __force_user *) &out);
88397 set_fs(oldfs);
88398
88399 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
88400@@ -1146,7 +1147,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
88401 mm_segment_t old_fs = get_fs();
88402
88403 set_fs(KERNEL_DS);
88404- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
88405+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
88406 set_fs(old_fs);
88407 if (compat_put_timespec(&t, interval))
88408 return -EFAULT;
88409diff --git a/kernel/configs.c b/kernel/configs.c
88410index c18b1f1..b9a0132 100644
88411--- a/kernel/configs.c
88412+++ b/kernel/configs.c
88413@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
88414 struct proc_dir_entry *entry;
88415
88416 /* create the current config file */
88417+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
88418+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
88419+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
88420+ &ikconfig_file_ops);
88421+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88422+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
88423+ &ikconfig_file_ops);
88424+#endif
88425+#else
88426 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
88427 &ikconfig_file_ops);
88428+#endif
88429+
88430 if (!entry)
88431 return -ENOMEM;
88432
88433diff --git a/kernel/cred.c b/kernel/cred.c
88434index e0573a4..26c0fd3 100644
88435--- a/kernel/cred.c
88436+++ b/kernel/cred.c
88437@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
88438 validate_creds(cred);
88439 alter_cred_subscribers(cred, -1);
88440 put_cred(cred);
88441+
88442+#ifdef CONFIG_GRKERNSEC_SETXID
88443+ cred = (struct cred *) tsk->delayed_cred;
88444+ if (cred != NULL) {
88445+ tsk->delayed_cred = NULL;
88446+ validate_creds(cred);
88447+ alter_cred_subscribers(cred, -1);
88448+ put_cred(cred);
88449+ }
88450+#endif
88451 }
88452
88453 /**
88454@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
88455 * Always returns 0 thus allowing this function to be tail-called at the end
88456 * of, say, sys_setgid().
88457 */
88458-int commit_creds(struct cred *new)
88459+static int __commit_creds(struct cred *new)
88460 {
88461 struct task_struct *task = current;
88462 const struct cred *old = task->real_cred;
88463@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
88464
88465 get_cred(new); /* we will require a ref for the subj creds too */
88466
88467+ gr_set_role_label(task, new->uid, new->gid);
88468+
88469 /* dumpability changes */
88470 if (!uid_eq(old->euid, new->euid) ||
88471 !gid_eq(old->egid, new->egid) ||
88472@@ -479,6 +491,105 @@ int commit_creds(struct cred *new)
88473 put_cred(old);
88474 return 0;
88475 }
88476+#ifdef CONFIG_GRKERNSEC_SETXID
88477+extern int set_user(struct cred *new);
88478+
88479+void gr_delayed_cred_worker(void)
88480+{
88481+ const struct cred *new = current->delayed_cred;
88482+ struct cred *ncred;
88483+
88484+ current->delayed_cred = NULL;
88485+
88486+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
88487+ // from doing get_cred on it when queueing this
88488+ put_cred(new);
88489+ return;
88490+ } else if (new == NULL)
88491+ return;
88492+
88493+ ncred = prepare_creds();
88494+ if (!ncred)
88495+ goto die;
88496+ // uids
88497+ ncred->uid = new->uid;
88498+ ncred->euid = new->euid;
88499+ ncred->suid = new->suid;
88500+ ncred->fsuid = new->fsuid;
88501+ // gids
88502+ ncred->gid = new->gid;
88503+ ncred->egid = new->egid;
88504+ ncred->sgid = new->sgid;
88505+ ncred->fsgid = new->fsgid;
88506+ // groups
88507+ set_groups(ncred, new->group_info);
88508+ // caps
88509+ ncred->securebits = new->securebits;
88510+ ncred->cap_inheritable = new->cap_inheritable;
88511+ ncred->cap_permitted = new->cap_permitted;
88512+ ncred->cap_effective = new->cap_effective;
88513+ ncred->cap_bset = new->cap_bset;
88514+
88515+ if (set_user(ncred)) {
88516+ abort_creds(ncred);
88517+ goto die;
88518+ }
88519+
88520+ // from doing get_cred on it when queueing this
88521+ put_cred(new);
88522+
88523+ __commit_creds(ncred);
88524+ return;
88525+die:
88526+ // from doing get_cred on it when queueing this
88527+ put_cred(new);
88528+ do_group_exit(SIGKILL);
88529+}
88530+#endif
88531+
88532+int commit_creds(struct cred *new)
88533+{
88534+#ifdef CONFIG_GRKERNSEC_SETXID
88535+ int ret;
88536+ int schedule_it = 0;
88537+ struct task_struct *t;
88538+ unsigned oldsecurebits = current_cred()->securebits;
88539+
88540+ /* we won't get called with tasklist_lock held for writing
88541+ and interrupts disabled as the cred struct in that case is
88542+ init_cred
88543+ */
88544+ if (grsec_enable_setxid && !current_is_single_threaded() &&
88545+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
88546+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
88547+ schedule_it = 1;
88548+ }
88549+ ret = __commit_creds(new);
88550+ if (schedule_it) {
88551+ rcu_read_lock();
88552+ read_lock(&tasklist_lock);
88553+ for (t = next_thread(current); t != current;
88554+ t = next_thread(t)) {
88555+ /* we'll check if the thread has uid 0 in
88556+ * the delayed worker routine
88557+ */
88558+ if (task_securebits(t) == oldsecurebits &&
88559+ t->delayed_cred == NULL) {
88560+ t->delayed_cred = get_cred(new);
88561+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
88562+ set_tsk_need_resched(t);
88563+ }
88564+ }
88565+ read_unlock(&tasklist_lock);
88566+ rcu_read_unlock();
88567+ }
88568+
88569+ return ret;
88570+#else
88571+ return __commit_creds(new);
88572+#endif
88573+}
88574+
88575 EXPORT_SYMBOL(commit_creds);
88576
88577 /**
88578diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
88579index 1adf62b..7736e06 100644
88580--- a/kernel/debug/debug_core.c
88581+++ b/kernel/debug/debug_core.c
88582@@ -124,7 +124,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
88583 */
88584 static atomic_t masters_in_kgdb;
88585 static atomic_t slaves_in_kgdb;
88586-static atomic_t kgdb_break_tasklet_var;
88587+static atomic_unchecked_t kgdb_break_tasklet_var;
88588 atomic_t kgdb_setting_breakpoint;
88589
88590 struct task_struct *kgdb_usethread;
88591@@ -134,7 +134,7 @@ int kgdb_single_step;
88592 static pid_t kgdb_sstep_pid;
88593
88594 /* to keep track of the CPU which is doing the single stepping*/
88595-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
88596+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
88597
88598 /*
88599 * If you are debugging a problem where roundup (the collection of
88600@@ -549,7 +549,7 @@ return_normal:
88601 * kernel will only try for the value of sstep_tries before
88602 * giving up and continuing on.
88603 */
88604- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
88605+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
88606 (kgdb_info[cpu].task &&
88607 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
88608 atomic_set(&kgdb_active, -1);
88609@@ -647,8 +647,8 @@ cpu_master_loop:
88610 }
88611
88612 kgdb_restore:
88613- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
88614- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
88615+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
88616+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
88617 if (kgdb_info[sstep_cpu].task)
88618 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
88619 else
88620@@ -925,18 +925,18 @@ static void kgdb_unregister_callbacks(void)
88621 static void kgdb_tasklet_bpt(unsigned long ing)
88622 {
88623 kgdb_breakpoint();
88624- atomic_set(&kgdb_break_tasklet_var, 0);
88625+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
88626 }
88627
88628 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
88629
88630 void kgdb_schedule_breakpoint(void)
88631 {
88632- if (atomic_read(&kgdb_break_tasklet_var) ||
88633+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
88634 atomic_read(&kgdb_active) != -1 ||
88635 atomic_read(&kgdb_setting_breakpoint))
88636 return;
88637- atomic_inc(&kgdb_break_tasklet_var);
88638+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
88639 tasklet_schedule(&kgdb_tasklet_breakpoint);
88640 }
88641 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
88642diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
88643index 379650b..30c5180 100644
88644--- a/kernel/debug/kdb/kdb_main.c
88645+++ b/kernel/debug/kdb/kdb_main.c
88646@@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
88647 continue;
88648
88649 kdb_printf("%-20s%8u 0x%p ", mod->name,
88650- mod->core_size, (void *)mod);
88651+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
88652 #ifdef CONFIG_MODULE_UNLOAD
88653 kdb_printf("%4ld ", module_refcount(mod));
88654 #endif
88655@@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
88656 kdb_printf(" (Loading)");
88657 else
88658 kdb_printf(" (Live)");
88659- kdb_printf(" 0x%p", mod->module_core);
88660+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
88661
88662 #ifdef CONFIG_MODULE_UNLOAD
88663 {
88664diff --git a/kernel/events/core.c b/kernel/events/core.c
88665index 1cd5eef..e8b5af9 100644
88666--- a/kernel/events/core.c
88667+++ b/kernel/events/core.c
88668@@ -170,8 +170,15 @@ static struct srcu_struct pmus_srcu;
88669 * 0 - disallow raw tracepoint access for unpriv
88670 * 1 - disallow cpu events for unpriv
88671 * 2 - disallow kernel profiling for unpriv
88672+ * 3 - disallow all unpriv perf event use
88673 */
88674-int sysctl_perf_event_paranoid __read_mostly = 1;
88675+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
88676+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
88677+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
88678+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
88679+#else
88680+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
88681+#endif
88682
88683 /* Minimum for 512 kiB + 1 user control page */
88684 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
88685@@ -197,7 +204,7 @@ void update_perf_cpu_limits(void)
88686
88687 tmp *= sysctl_perf_cpu_time_max_percent;
88688 do_div(tmp, 100);
88689- ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
88690+ ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
88691 }
88692
88693 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
88694@@ -303,7 +310,7 @@ void perf_sample_event_took(u64 sample_len_ns)
88695 }
88696 }
88697
88698-static atomic64_t perf_event_id;
88699+static atomic64_unchecked_t perf_event_id;
88700
88701 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
88702 enum event_type_t event_type);
88703@@ -3102,7 +3109,7 @@ static void __perf_event_read(void *info)
88704
88705 static inline u64 perf_event_count(struct perf_event *event)
88706 {
88707- return local64_read(&event->count) + atomic64_read(&event->child_count);
88708+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
88709 }
88710
88711 static u64 perf_event_read(struct perf_event *event)
88712@@ -3528,9 +3535,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
88713 mutex_lock(&event->child_mutex);
88714 total += perf_event_read(event);
88715 *enabled += event->total_time_enabled +
88716- atomic64_read(&event->child_total_time_enabled);
88717+ atomic64_read_unchecked(&event->child_total_time_enabled);
88718 *running += event->total_time_running +
88719- atomic64_read(&event->child_total_time_running);
88720+ atomic64_read_unchecked(&event->child_total_time_running);
88721
88722 list_for_each_entry(child, &event->child_list, child_list) {
88723 total += perf_event_read(child);
88724@@ -3994,10 +4001,10 @@ void perf_event_update_userpage(struct perf_event *event)
88725 userpg->offset -= local64_read(&event->hw.prev_count);
88726
88727 userpg->time_enabled = enabled +
88728- atomic64_read(&event->child_total_time_enabled);
88729+ atomic64_read_unchecked(&event->child_total_time_enabled);
88730
88731 userpg->time_running = running +
88732- atomic64_read(&event->child_total_time_running);
88733+ atomic64_read_unchecked(&event->child_total_time_running);
88734
88735 arch_perf_update_userpage(userpg, now);
88736
88737@@ -4561,7 +4568,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
88738
88739 /* Data. */
88740 sp = perf_user_stack_pointer(regs);
88741- rem = __output_copy_user(handle, (void *) sp, dump_size);
88742+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
88743 dyn_size = dump_size - rem;
88744
88745 perf_output_skip(handle, rem);
88746@@ -4652,11 +4659,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
88747 values[n++] = perf_event_count(event);
88748 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
88749 values[n++] = enabled +
88750- atomic64_read(&event->child_total_time_enabled);
88751+ atomic64_read_unchecked(&event->child_total_time_enabled);
88752 }
88753 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
88754 values[n++] = running +
88755- atomic64_read(&event->child_total_time_running);
88756+ atomic64_read_unchecked(&event->child_total_time_running);
88757 }
88758 if (read_format & PERF_FORMAT_ID)
88759 values[n++] = primary_event_id(event);
88760@@ -6958,7 +6965,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
88761 event->parent = parent_event;
88762
88763 event->ns = get_pid_ns(task_active_pid_ns(current));
88764- event->id = atomic64_inc_return(&perf_event_id);
88765+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
88766
88767 event->state = PERF_EVENT_STATE_INACTIVE;
88768
88769@@ -7237,6 +7244,11 @@ SYSCALL_DEFINE5(perf_event_open,
88770 if (flags & ~PERF_FLAG_ALL)
88771 return -EINVAL;
88772
88773+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
88774+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
88775+ return -EACCES;
88776+#endif
88777+
88778 err = perf_copy_attr(attr_uptr, &attr);
88779 if (err)
88780 return err;
88781@@ -7592,10 +7604,10 @@ static void sync_child_event(struct perf_event *child_event,
88782 /*
88783 * Add back the child's count to the parent's count:
88784 */
88785- atomic64_add(child_val, &parent_event->child_count);
88786- atomic64_add(child_event->total_time_enabled,
88787+ atomic64_add_unchecked(child_val, &parent_event->child_count);
88788+ atomic64_add_unchecked(child_event->total_time_enabled,
88789 &parent_event->child_total_time_enabled);
88790- atomic64_add(child_event->total_time_running,
88791+ atomic64_add_unchecked(child_event->total_time_running,
88792 &parent_event->child_total_time_running);
88793
88794 /*
88795diff --git a/kernel/events/internal.h b/kernel/events/internal.h
88796index 569b2187..19940d9 100644
88797--- a/kernel/events/internal.h
88798+++ b/kernel/events/internal.h
88799@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
88800 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
88801 }
88802
88803-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
88804+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
88805 static inline unsigned long \
88806 func_name(struct perf_output_handle *handle, \
88807- const void *buf, unsigned long len) \
88808+ const void user *buf, unsigned long len) \
88809 { \
88810 unsigned long size, written; \
88811 \
88812@@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
88813 return 0;
88814 }
88815
88816-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
88817+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
88818
88819 static inline unsigned long
88820 memcpy_skip(void *dst, const void *src, unsigned long n)
88821@@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
88822 return 0;
88823 }
88824
88825-DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
88826+DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
88827
88828 #ifndef arch_perf_out_copy_user
88829 #define arch_perf_out_copy_user arch_perf_out_copy_user
88830@@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
88831 }
88832 #endif
88833
88834-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
88835+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
88836
88837 /* Callchain handling */
88838 extern struct perf_callchain_entry *
88839diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
88840index ed8f2cd..fe8030c 100644
88841--- a/kernel/events/uprobes.c
88842+++ b/kernel/events/uprobes.c
88843@@ -1670,7 +1670,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
88844 {
88845 struct page *page;
88846 uprobe_opcode_t opcode;
88847- int result;
88848+ long result;
88849
88850 pagefault_disable();
88851 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
88852diff --git a/kernel/exit.c b/kernel/exit.c
88853index 5d30019..934add5 100644
88854--- a/kernel/exit.c
88855+++ b/kernel/exit.c
88856@@ -174,6 +174,10 @@ void release_task(struct task_struct *p)
88857 struct task_struct *leader;
88858 int zap_leader;
88859 repeat:
88860+#ifdef CONFIG_NET
88861+ gr_del_task_from_ip_table(p);
88862+#endif
88863+
88864 /* don't need to get the RCU readlock here - the process is dead and
88865 * can't be modifying its own credentials. But shut RCU-lockdep up */
88866 rcu_read_lock();
88867@@ -670,6 +674,8 @@ void do_exit(long code)
88868 int group_dead;
88869 TASKS_RCU(int tasks_rcu_i);
88870
88871+ set_fs(USER_DS);
88872+
88873 profile_task_exit(tsk);
88874
88875 WARN_ON(blk_needs_flush_plug(tsk));
88876@@ -686,7 +692,6 @@ void do_exit(long code)
88877 * mm_release()->clear_child_tid() from writing to a user-controlled
88878 * kernel address.
88879 */
88880- set_fs(USER_DS);
88881
88882 ptrace_event(PTRACE_EVENT_EXIT, code);
88883
88884@@ -744,6 +749,9 @@ void do_exit(long code)
88885 tsk->exit_code = code;
88886 taskstats_exit(tsk, group_dead);
88887
88888+ gr_acl_handle_psacct(tsk, code);
88889+ gr_acl_handle_exit();
88890+
88891 exit_mm(tsk);
88892
88893 if (group_dead)
88894@@ -863,7 +871,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
88895 * Take down every thread in the group. This is called by fatal signals
88896 * as well as by sys_exit_group (below).
88897 */
88898-void
88899+__noreturn void
88900 do_group_exit(int exit_code)
88901 {
88902 struct signal_struct *sig = current->signal;
88903diff --git a/kernel/fork.c b/kernel/fork.c
88904index 9b7d746..5b898ab 100644
88905--- a/kernel/fork.c
88906+++ b/kernel/fork.c
88907@@ -183,6 +183,48 @@ void thread_info_cache_init(void)
88908 # endif
88909 #endif
88910
88911+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
88912+static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
88913+ int node, void **lowmem_stack)
88914+{
88915+ struct page *pages[THREAD_SIZE / PAGE_SIZE];
88916+ void *ret = NULL;
88917+ unsigned int i;
88918+
88919+ *lowmem_stack = alloc_thread_info_node(tsk, node);
88920+ if (*lowmem_stack == NULL)
88921+ goto out;
88922+
88923+ for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
88924+ pages[i] = virt_to_page(*lowmem_stack + (i * PAGE_SIZE));
88925+
88926+ /* use VM_IOREMAP to gain THREAD_SIZE alignment */
88927+ ret = vmap(pages, THREAD_SIZE / PAGE_SIZE, VM_IOREMAP, PAGE_KERNEL);
88928+ if (ret == NULL) {
88929+ free_thread_info(*lowmem_stack);
88930+ *lowmem_stack = NULL;
88931+ }
88932+
88933+out:
88934+ return ret;
88935+}
88936+
88937+static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
88938+{
88939+ unmap_process_stacks(tsk);
88940+}
88941+#else
88942+static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
88943+ int node, void **lowmem_stack)
88944+{
88945+ return alloc_thread_info_node(tsk, node);
88946+}
88947+static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
88948+{
88949+ free_thread_info(ti);
88950+}
88951+#endif
88952+
88953 /* SLAB cache for signal_struct structures (tsk->signal) */
88954 static struct kmem_cache *signal_cachep;
88955
88956@@ -201,18 +243,22 @@ struct kmem_cache *vm_area_cachep;
88957 /* SLAB cache for mm_struct structures (tsk->mm) */
88958 static struct kmem_cache *mm_cachep;
88959
88960-static void account_kernel_stack(struct thread_info *ti, int account)
88961+static void account_kernel_stack(struct task_struct *tsk, struct thread_info *ti, int account)
88962 {
88963+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
88964+ struct zone *zone = page_zone(virt_to_page(tsk->lowmem_stack));
88965+#else
88966 struct zone *zone = page_zone(virt_to_page(ti));
88967+#endif
88968
88969 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
88970 }
88971
88972 void free_task(struct task_struct *tsk)
88973 {
88974- account_kernel_stack(tsk->stack, -1);
88975+ account_kernel_stack(tsk, tsk->stack, -1);
88976 arch_release_thread_info(tsk->stack);
88977- free_thread_info(tsk->stack);
88978+ gr_free_thread_info(tsk, tsk->stack);
88979 rt_mutex_debug_task_free(tsk);
88980 ftrace_graph_exit_task(tsk);
88981 put_seccomp_filter(tsk);
88982@@ -306,6 +352,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
88983 {
88984 struct task_struct *tsk;
88985 struct thread_info *ti;
88986+ void *lowmem_stack;
88987 int node = tsk_fork_get_node(orig);
88988 int err;
88989
88990@@ -313,7 +360,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
88991 if (!tsk)
88992 return NULL;
88993
88994- ti = alloc_thread_info_node(tsk, node);
88995+ ti = gr_alloc_thread_info_node(tsk, node, &lowmem_stack);
88996 if (!ti)
88997 goto free_tsk;
88998
88999@@ -322,6 +369,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89000 goto free_ti;
89001
89002 tsk->stack = ti;
89003+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89004+ tsk->lowmem_stack = lowmem_stack;
89005+#endif
89006 #ifdef CONFIG_SECCOMP
89007 /*
89008 * We must handle setting up seccomp filters once we're under
89009@@ -338,7 +388,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89010 set_task_stack_end_magic(tsk);
89011
89012 #ifdef CONFIG_CC_STACKPROTECTOR
89013- tsk->stack_canary = get_random_int();
89014+ tsk->stack_canary = pax_get_random_long();
89015 #endif
89016
89017 /*
89018@@ -352,24 +402,92 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89019 tsk->splice_pipe = NULL;
89020 tsk->task_frag.page = NULL;
89021
89022- account_kernel_stack(ti, 1);
89023+ account_kernel_stack(tsk, ti, 1);
89024
89025 return tsk;
89026
89027 free_ti:
89028- free_thread_info(ti);
89029+ gr_free_thread_info(tsk, ti);
89030 free_tsk:
89031 free_task_struct(tsk);
89032 return NULL;
89033 }
89034
89035 #ifdef CONFIG_MMU
89036-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89037+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
89038+{
89039+ struct vm_area_struct *tmp;
89040+ unsigned long charge;
89041+ struct file *file;
89042+ int retval;
89043+
89044+ charge = 0;
89045+ if (mpnt->vm_flags & VM_ACCOUNT) {
89046+ unsigned long len = vma_pages(mpnt);
89047+
89048+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
89049+ goto fail_nomem;
89050+ charge = len;
89051+ }
89052+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89053+ if (!tmp)
89054+ goto fail_nomem;
89055+ *tmp = *mpnt;
89056+ tmp->vm_mm = mm;
89057+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
89058+ retval = vma_dup_policy(mpnt, tmp);
89059+ if (retval)
89060+ goto fail_nomem_policy;
89061+ if (anon_vma_fork(tmp, mpnt))
89062+ goto fail_nomem_anon_vma_fork;
89063+ tmp->vm_flags &= ~VM_LOCKED;
89064+ tmp->vm_next = tmp->vm_prev = NULL;
89065+ tmp->vm_mirror = NULL;
89066+ file = tmp->vm_file;
89067+ if (file) {
89068+ struct inode *inode = file_inode(file);
89069+ struct address_space *mapping = file->f_mapping;
89070+
89071+ get_file(file);
89072+ if (tmp->vm_flags & VM_DENYWRITE)
89073+ atomic_dec(&inode->i_writecount);
89074+ mutex_lock(&mapping->i_mmap_mutex);
89075+ if (tmp->vm_flags & VM_SHARED)
89076+ atomic_inc(&mapping->i_mmap_writable);
89077+ flush_dcache_mmap_lock(mapping);
89078+ /* insert tmp into the share list, just after mpnt */
89079+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
89080+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
89081+ else
89082+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
89083+ flush_dcache_mmap_unlock(mapping);
89084+ mutex_unlock(&mapping->i_mmap_mutex);
89085+ }
89086+
89087+ /*
89088+ * Clear hugetlb-related page reserves for children. This only
89089+ * affects MAP_PRIVATE mappings. Faults generated by the child
89090+ * are not guaranteed to succeed, even if read-only
89091+ */
89092+ if (is_vm_hugetlb_page(tmp))
89093+ reset_vma_resv_huge_pages(tmp);
89094+
89095+ return tmp;
89096+
89097+fail_nomem_anon_vma_fork:
89098+ mpol_put(vma_policy(tmp));
89099+fail_nomem_policy:
89100+ kmem_cache_free(vm_area_cachep, tmp);
89101+fail_nomem:
89102+ vm_unacct_memory(charge);
89103+ return NULL;
89104+}
89105+
89106+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89107 {
89108 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
89109 struct rb_node **rb_link, *rb_parent;
89110 int retval;
89111- unsigned long charge;
89112
89113 uprobe_start_dup_mmap();
89114 down_write(&oldmm->mmap_sem);
89115@@ -397,55 +515,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89116
89117 prev = NULL;
89118 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
89119- struct file *file;
89120-
89121 if (mpnt->vm_flags & VM_DONTCOPY) {
89122 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
89123 -vma_pages(mpnt));
89124 continue;
89125 }
89126- charge = 0;
89127- if (mpnt->vm_flags & VM_ACCOUNT) {
89128- unsigned long len = vma_pages(mpnt);
89129-
89130- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
89131- goto fail_nomem;
89132- charge = len;
89133- }
89134- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89135- if (!tmp)
89136- goto fail_nomem;
89137- *tmp = *mpnt;
89138- INIT_LIST_HEAD(&tmp->anon_vma_chain);
89139- retval = vma_dup_policy(mpnt, tmp);
89140- if (retval)
89141- goto fail_nomem_policy;
89142- tmp->vm_mm = mm;
89143- if (anon_vma_fork(tmp, mpnt))
89144- goto fail_nomem_anon_vma_fork;
89145- tmp->vm_flags &= ~VM_LOCKED;
89146- tmp->vm_next = tmp->vm_prev = NULL;
89147- file = tmp->vm_file;
89148- if (file) {
89149- struct inode *inode = file_inode(file);
89150- struct address_space *mapping = file->f_mapping;
89151-
89152- get_file(file);
89153- if (tmp->vm_flags & VM_DENYWRITE)
89154- atomic_dec(&inode->i_writecount);
89155- mutex_lock(&mapping->i_mmap_mutex);
89156- if (tmp->vm_flags & VM_SHARED)
89157- atomic_inc(&mapping->i_mmap_writable);
89158- flush_dcache_mmap_lock(mapping);
89159- /* insert tmp into the share list, just after mpnt */
89160- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
89161- vma_nonlinear_insert(tmp,
89162- &mapping->i_mmap_nonlinear);
89163- else
89164- vma_interval_tree_insert_after(tmp, mpnt,
89165- &mapping->i_mmap);
89166- flush_dcache_mmap_unlock(mapping);
89167- mutex_unlock(&mapping->i_mmap_mutex);
89168+ tmp = dup_vma(mm, oldmm, mpnt);
89169+ if (!tmp) {
89170+ retval = -ENOMEM;
89171+ goto out;
89172 }
89173
89174 /*
89175@@ -477,6 +555,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89176 if (retval)
89177 goto out;
89178 }
89179+
89180+#ifdef CONFIG_PAX_SEGMEXEC
89181+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
89182+ struct vm_area_struct *mpnt_m;
89183+
89184+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
89185+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
89186+
89187+ if (!mpnt->vm_mirror)
89188+ continue;
89189+
89190+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
89191+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
89192+ mpnt->vm_mirror = mpnt_m;
89193+ } else {
89194+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
89195+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
89196+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
89197+ mpnt->vm_mirror->vm_mirror = mpnt;
89198+ }
89199+ }
89200+ BUG_ON(mpnt_m);
89201+ }
89202+#endif
89203+
89204 /* a new mm has just been created */
89205 arch_dup_mmap(oldmm, mm);
89206 retval = 0;
89207@@ -486,14 +589,6 @@ out:
89208 up_write(&oldmm->mmap_sem);
89209 uprobe_end_dup_mmap();
89210 return retval;
89211-fail_nomem_anon_vma_fork:
89212- mpol_put(vma_policy(tmp));
89213-fail_nomem_policy:
89214- kmem_cache_free(vm_area_cachep, tmp);
89215-fail_nomem:
89216- retval = -ENOMEM;
89217- vm_unacct_memory(charge);
89218- goto out;
89219 }
89220
89221 static inline int mm_alloc_pgd(struct mm_struct *mm)
89222@@ -734,8 +829,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
89223 return ERR_PTR(err);
89224
89225 mm = get_task_mm(task);
89226- if (mm && mm != current->mm &&
89227- !ptrace_may_access(task, mode)) {
89228+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
89229+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
89230 mmput(mm);
89231 mm = ERR_PTR(-EACCES);
89232 }
89233@@ -938,13 +1033,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
89234 spin_unlock(&fs->lock);
89235 return -EAGAIN;
89236 }
89237- fs->users++;
89238+ atomic_inc(&fs->users);
89239 spin_unlock(&fs->lock);
89240 return 0;
89241 }
89242 tsk->fs = copy_fs_struct(fs);
89243 if (!tsk->fs)
89244 return -ENOMEM;
89245+ /* Carry through gr_chroot_dentry and is_chrooted instead
89246+ of recomputing it here. Already copied when the task struct
89247+ is duplicated. This allows pivot_root to not be treated as
89248+ a chroot
89249+ */
89250+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
89251+
89252 return 0;
89253 }
89254
89255@@ -1179,7 +1281,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
89256 * parts of the process environment (as per the clone
89257 * flags). The actual kick-off is left to the caller.
89258 */
89259-static struct task_struct *copy_process(unsigned long clone_flags,
89260+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
89261 unsigned long stack_start,
89262 unsigned long stack_size,
89263 int __user *child_tidptr,
89264@@ -1250,6 +1352,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
89265 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
89266 #endif
89267 retval = -EAGAIN;
89268+
89269+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
89270+
89271 if (atomic_read(&p->real_cred->user->processes) >=
89272 task_rlimit(p, RLIMIT_NPROC)) {
89273 if (p->real_cred->user != INIT_USER &&
89274@@ -1499,6 +1604,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
89275 goto bad_fork_free_pid;
89276 }
89277
89278+ /* synchronizes with gr_set_acls()
89279+ we need to call this past the point of no return for fork()
89280+ */
89281+ gr_copy_label(p);
89282+
89283 if (likely(p->pid)) {
89284 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
89285
89286@@ -1589,6 +1699,8 @@ bad_fork_cleanup_count:
89287 bad_fork_free:
89288 free_task(p);
89289 fork_out:
89290+ gr_log_forkfail(retval);
89291+
89292 return ERR_PTR(retval);
89293 }
89294
89295@@ -1650,6 +1762,7 @@ long do_fork(unsigned long clone_flags,
89296
89297 p = copy_process(clone_flags, stack_start, stack_size,
89298 child_tidptr, NULL, trace);
89299+ add_latent_entropy();
89300 /*
89301 * Do this prior waking up the new thread - the thread pointer
89302 * might get invalid after that point, if the thread exits quickly.
89303@@ -1666,6 +1779,8 @@ long do_fork(unsigned long clone_flags,
89304 if (clone_flags & CLONE_PARENT_SETTID)
89305 put_user(nr, parent_tidptr);
89306
89307+ gr_handle_brute_check();
89308+
89309 if (clone_flags & CLONE_VFORK) {
89310 p->vfork_done = &vfork;
89311 init_completion(&vfork);
89312@@ -1784,7 +1899,7 @@ void __init proc_caches_init(void)
89313 mm_cachep = kmem_cache_create("mm_struct",
89314 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
89315 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
89316- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
89317+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
89318 mmap_init();
89319 nsproxy_cache_init();
89320 }
89321@@ -1824,7 +1939,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
89322 return 0;
89323
89324 /* don't need lock here; in the worst case we'll do useless copy */
89325- if (fs->users == 1)
89326+ if (atomic_read(&fs->users) == 1)
89327 return 0;
89328
89329 *new_fsp = copy_fs_struct(fs);
89330@@ -1936,7 +2051,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
89331 fs = current->fs;
89332 spin_lock(&fs->lock);
89333 current->fs = new_fs;
89334- if (--fs->users)
89335+ gr_set_chroot_entries(current, &current->fs->root);
89336+ if (atomic_dec_return(&fs->users))
89337 new_fs = NULL;
89338 else
89339 new_fs = fs;
89340diff --git a/kernel/futex.c b/kernel/futex.c
89341index 63678b5..512f9af 100644
89342--- a/kernel/futex.c
89343+++ b/kernel/futex.c
89344@@ -201,7 +201,7 @@ struct futex_pi_state {
89345 atomic_t refcount;
89346
89347 union futex_key key;
89348-};
89349+} __randomize_layout;
89350
89351 /**
89352 * struct futex_q - The hashed futex queue entry, one per waiting task
89353@@ -235,7 +235,7 @@ struct futex_q {
89354 struct rt_mutex_waiter *rt_waiter;
89355 union futex_key *requeue_pi_key;
89356 u32 bitset;
89357-};
89358+} __randomize_layout;
89359
89360 static const struct futex_q futex_q_init = {
89361 /* list gets initialized in queue_me()*/
89362@@ -402,6 +402,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
89363 struct page *page, *page_head;
89364 int err, ro = 0;
89365
89366+#ifdef CONFIG_PAX_SEGMEXEC
89367+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
89368+ return -EFAULT;
89369+#endif
89370+
89371 /*
89372 * The futex address must be "naturally" aligned.
89373 */
89374@@ -601,7 +606,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
89375
89376 static int get_futex_value_locked(u32 *dest, u32 __user *from)
89377 {
89378- int ret;
89379+ unsigned long ret;
89380
89381 pagefault_disable();
89382 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
89383@@ -3006,6 +3011,7 @@ static void __init futex_detect_cmpxchg(void)
89384 {
89385 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
89386 u32 curval;
89387+ mm_segment_t oldfs;
89388
89389 /*
89390 * This will fail and we want it. Some arch implementations do
89391@@ -3017,8 +3023,11 @@ static void __init futex_detect_cmpxchg(void)
89392 * implementation, the non-functional ones will return
89393 * -ENOSYS.
89394 */
89395+ oldfs = get_fs();
89396+ set_fs(USER_DS);
89397 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
89398 futex_cmpxchg_enabled = 1;
89399+ set_fs(oldfs);
89400 #endif
89401 }
89402
89403diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
89404index 55c8c93..9ba7ad6 100644
89405--- a/kernel/futex_compat.c
89406+++ b/kernel/futex_compat.c
89407@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
89408 return 0;
89409 }
89410
89411-static void __user *futex_uaddr(struct robust_list __user *entry,
89412+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
89413 compat_long_t futex_offset)
89414 {
89415 compat_uptr_t base = ptr_to_compat(entry);
89416diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
89417index b358a80..fc25240 100644
89418--- a/kernel/gcov/base.c
89419+++ b/kernel/gcov/base.c
89420@@ -114,11 +114,6 @@ void gcov_enable_events(void)
89421 }
89422
89423 #ifdef CONFIG_MODULES
89424-static inline int within(void *addr, void *start, unsigned long size)
89425-{
89426- return ((addr >= start) && (addr < start + size));
89427-}
89428-
89429 /* Update list and generate events when modules are unloaded. */
89430 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
89431 void *data)
89432@@ -133,7 +128,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
89433
89434 /* Remove entries located in module from linked list. */
89435 while ((info = gcov_info_next(info))) {
89436- if (within(info, mod->module_core, mod->core_size)) {
89437+ if (within_module_core_rw((unsigned long)info, mod)) {
89438 gcov_info_unlink(prev, info);
89439 if (gcov_events_enabled)
89440 gcov_event(GCOV_REMOVE, info);
89441diff --git a/kernel/jump_label.c b/kernel/jump_label.c
89442index 9019f15..9a3c42e 100644
89443--- a/kernel/jump_label.c
89444+++ b/kernel/jump_label.c
89445@@ -14,6 +14,7 @@
89446 #include <linux/err.h>
89447 #include <linux/static_key.h>
89448 #include <linux/jump_label_ratelimit.h>
89449+#include <linux/mm.h>
89450
89451 #ifdef HAVE_JUMP_LABEL
89452
89453@@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
89454
89455 size = (((unsigned long)stop - (unsigned long)start)
89456 / sizeof(struct jump_entry));
89457+ pax_open_kernel();
89458 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
89459+ pax_close_kernel();
89460 }
89461
89462 static void jump_label_update(struct static_key *key, int enable);
89463@@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
89464 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
89465 struct jump_entry *iter;
89466
89467+ pax_open_kernel();
89468 for (iter = iter_start; iter < iter_stop; iter++) {
89469 if (within_module_init(iter->code, mod))
89470 iter->code = 0;
89471 }
89472+ pax_close_kernel();
89473 }
89474
89475 static int
89476diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
89477index 5c5987f..bc502b0 100644
89478--- a/kernel/kallsyms.c
89479+++ b/kernel/kallsyms.c
89480@@ -11,6 +11,9 @@
89481 * Changed the compression method from stem compression to "table lookup"
89482 * compression (see scripts/kallsyms.c for a more complete description)
89483 */
89484+#ifdef CONFIG_GRKERNSEC_HIDESYM
89485+#define __INCLUDED_BY_HIDESYM 1
89486+#endif
89487 #include <linux/kallsyms.h>
89488 #include <linux/module.h>
89489 #include <linux/init.h>
89490@@ -54,12 +57,33 @@ extern const unsigned long kallsyms_markers[] __weak;
89491
89492 static inline int is_kernel_inittext(unsigned long addr)
89493 {
89494+ if (system_state != SYSTEM_BOOTING)
89495+ return 0;
89496+
89497 if (addr >= (unsigned long)_sinittext
89498 && addr <= (unsigned long)_einittext)
89499 return 1;
89500 return 0;
89501 }
89502
89503+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89504+#ifdef CONFIG_MODULES
89505+static inline int is_module_text(unsigned long addr)
89506+{
89507+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
89508+ return 1;
89509+
89510+ addr = ktla_ktva(addr);
89511+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
89512+}
89513+#else
89514+static inline int is_module_text(unsigned long addr)
89515+{
89516+ return 0;
89517+}
89518+#endif
89519+#endif
89520+
89521 static inline int is_kernel_text(unsigned long addr)
89522 {
89523 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
89524@@ -70,13 +94,28 @@ static inline int is_kernel_text(unsigned long addr)
89525
89526 static inline int is_kernel(unsigned long addr)
89527 {
89528+
89529+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89530+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
89531+ return 1;
89532+
89533+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
89534+#else
89535 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
89536+#endif
89537+
89538 return 1;
89539 return in_gate_area_no_mm(addr);
89540 }
89541
89542 static int is_ksym_addr(unsigned long addr)
89543 {
89544+
89545+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89546+ if (is_module_text(addr))
89547+ return 0;
89548+#endif
89549+
89550 if (all_var)
89551 return is_kernel(addr);
89552
89553@@ -481,7 +520,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
89554
89555 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
89556 {
89557- iter->name[0] = '\0';
89558 iter->nameoff = get_symbol_offset(new_pos);
89559 iter->pos = new_pos;
89560 }
89561@@ -529,6 +567,11 @@ static int s_show(struct seq_file *m, void *p)
89562 {
89563 struct kallsym_iter *iter = m->private;
89564
89565+#ifdef CONFIG_GRKERNSEC_HIDESYM
89566+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
89567+ return 0;
89568+#endif
89569+
89570 /* Some debugging symbols have no name. Ignore them. */
89571 if (!iter->name[0])
89572 return 0;
89573@@ -542,6 +585,7 @@ static int s_show(struct seq_file *m, void *p)
89574 */
89575 type = iter->exported ? toupper(iter->type) :
89576 tolower(iter->type);
89577+
89578 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
89579 type, iter->name, iter->module_name);
89580 } else
89581diff --git a/kernel/kcmp.c b/kernel/kcmp.c
89582index 0aa69ea..a7fcafb 100644
89583--- a/kernel/kcmp.c
89584+++ b/kernel/kcmp.c
89585@@ -100,6 +100,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
89586 struct task_struct *task1, *task2;
89587 int ret;
89588
89589+#ifdef CONFIG_GRKERNSEC
89590+ return -ENOSYS;
89591+#endif
89592+
89593 rcu_read_lock();
89594
89595 /*
89596diff --git a/kernel/kexec.c b/kernel/kexec.c
89597index 2abf9f6..c40cf85 100644
89598--- a/kernel/kexec.c
89599+++ b/kernel/kexec.c
89600@@ -1349,7 +1349,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry,
89601 compat_ulong_t, flags)
89602 {
89603 struct compat_kexec_segment in;
89604- struct kexec_segment out, __user *ksegments;
89605+ struct kexec_segment out;
89606+ struct kexec_segment __user *ksegments;
89607 unsigned long i, result;
89608
89609 /* Don't allow clients that don't understand the native
89610diff --git a/kernel/kmod.c b/kernel/kmod.c
89611index 80f7a6d..3c476d3 100644
89612--- a/kernel/kmod.c
89613+++ b/kernel/kmod.c
89614@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
89615 kfree(info->argv);
89616 }
89617
89618-static int call_modprobe(char *module_name, int wait)
89619+static int call_modprobe(char *module_name, char *module_param, int wait)
89620 {
89621 struct subprocess_info *info;
89622 static char *envp[] = {
89623@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
89624 NULL
89625 };
89626
89627- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
89628+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
89629 if (!argv)
89630 goto out;
89631
89632@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
89633 argv[1] = "-q";
89634 argv[2] = "--";
89635 argv[3] = module_name; /* check free_modprobe_argv() */
89636- argv[4] = NULL;
89637+ argv[4] = module_param;
89638+ argv[5] = NULL;
89639
89640 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
89641 NULL, free_modprobe_argv, NULL);
89642@@ -129,9 +130,8 @@ out:
89643 * If module auto-loading support is disabled then this function
89644 * becomes a no-operation.
89645 */
89646-int __request_module(bool wait, const char *fmt, ...)
89647+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
89648 {
89649- va_list args;
89650 char module_name[MODULE_NAME_LEN];
89651 unsigned int max_modprobes;
89652 int ret;
89653@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
89654 if (!modprobe_path[0])
89655 return 0;
89656
89657- va_start(args, fmt);
89658- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
89659- va_end(args);
89660+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
89661 if (ret >= MODULE_NAME_LEN)
89662 return -ENAMETOOLONG;
89663
89664@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
89665 if (ret)
89666 return ret;
89667
89668+#ifdef CONFIG_GRKERNSEC_MODHARDEN
89669+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
89670+ /* hack to workaround consolekit/udisks stupidity */
89671+ read_lock(&tasklist_lock);
89672+ if (!strcmp(current->comm, "mount") &&
89673+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
89674+ read_unlock(&tasklist_lock);
89675+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
89676+ return -EPERM;
89677+ }
89678+ read_unlock(&tasklist_lock);
89679+ }
89680+#endif
89681+
89682 /* If modprobe needs a service that is in a module, we get a recursive
89683 * loop. Limit the number of running kmod threads to max_threads/2 or
89684 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
89685@@ -188,16 +200,61 @@ int __request_module(bool wait, const char *fmt, ...)
89686
89687 trace_module_request(module_name, wait, _RET_IP_);
89688
89689- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
89690+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
89691
89692 atomic_dec(&kmod_concurrent);
89693 return ret;
89694 }
89695+
89696+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
89697+{
89698+ va_list args;
89699+ int ret;
89700+
89701+ va_start(args, fmt);
89702+ ret = ____request_module(wait, module_param, fmt, args);
89703+ va_end(args);
89704+
89705+ return ret;
89706+}
89707+
89708+int __request_module(bool wait, const char *fmt, ...)
89709+{
89710+ va_list args;
89711+ int ret;
89712+
89713+#ifdef CONFIG_GRKERNSEC_MODHARDEN
89714+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
89715+ char module_param[MODULE_NAME_LEN];
89716+
89717+ memset(module_param, 0, sizeof(module_param));
89718+
89719+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
89720+
89721+ va_start(args, fmt);
89722+ ret = ____request_module(wait, module_param, fmt, args);
89723+ va_end(args);
89724+
89725+ return ret;
89726+ }
89727+#endif
89728+
89729+ va_start(args, fmt);
89730+ ret = ____request_module(wait, NULL, fmt, args);
89731+ va_end(args);
89732+
89733+ return ret;
89734+}
89735+
89736 EXPORT_SYMBOL(__request_module);
89737 #endif /* CONFIG_MODULES */
89738
89739 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
89740 {
89741+#ifdef CONFIG_GRKERNSEC
89742+ kfree(info->path);
89743+ info->path = info->origpath;
89744+#endif
89745 if (info->cleanup)
89746 (*info->cleanup)(info);
89747 kfree(info);
89748@@ -240,6 +297,20 @@ static int ____call_usermodehelper(void *data)
89749 */
89750 set_user_nice(current, 0);
89751
89752+#ifdef CONFIG_GRKERNSEC
89753+ /* this is race-free as far as userland is concerned as we copied
89754+ out the path to be used prior to this point and are now operating
89755+ on that copy
89756+ */
89757+ if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
89758+ strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
89759+ strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
89760+ printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
89761+ retval = -EPERM;
89762+ goto out;
89763+ }
89764+#endif
89765+
89766 retval = -ENOMEM;
89767 new = prepare_kernel_cred(current);
89768 if (!new)
89769@@ -262,8 +333,8 @@ static int ____call_usermodehelper(void *data)
89770 commit_creds(new);
89771
89772 retval = do_execve(getname_kernel(sub_info->path),
89773- (const char __user *const __user *)sub_info->argv,
89774- (const char __user *const __user *)sub_info->envp);
89775+ (const char __user *const __force_user *)sub_info->argv,
89776+ (const char __user *const __force_user *)sub_info->envp);
89777 out:
89778 sub_info->retval = retval;
89779 /* wait_for_helper() will call umh_complete if UHM_WAIT_PROC. */
89780@@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
89781 *
89782 * Thus the __user pointer cast is valid here.
89783 */
89784- sys_wait4(pid, (int __user *)&ret, 0, NULL);
89785+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
89786
89787 /*
89788 * If ret is 0, either ____call_usermodehelper failed and the
89789@@ -532,7 +603,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
89790 goto out;
89791
89792 INIT_WORK(&sub_info->work, __call_usermodehelper);
89793+#ifdef CONFIG_GRKERNSEC
89794+ sub_info->origpath = path;
89795+ sub_info->path = kstrdup(path, gfp_mask);
89796+#else
89797 sub_info->path = path;
89798+#endif
89799 sub_info->argv = argv;
89800 sub_info->envp = envp;
89801
89802@@ -645,7 +721,7 @@ EXPORT_SYMBOL(call_usermodehelper);
89803 static int proc_cap_handler(struct ctl_table *table, int write,
89804 void __user *buffer, size_t *lenp, loff_t *ppos)
89805 {
89806- struct ctl_table t;
89807+ ctl_table_no_const t;
89808 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
89809 kernel_cap_t new_cap;
89810 int err, i;
89811diff --git a/kernel/kprobes.c b/kernel/kprobes.c
89812index 3995f54..e247879 100644
89813--- a/kernel/kprobes.c
89814+++ b/kernel/kprobes.c
89815@@ -31,6 +31,9 @@
89816 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
89817 * <prasanna@in.ibm.com> added function-return probes.
89818 */
89819+#ifdef CONFIG_GRKERNSEC_HIDESYM
89820+#define __INCLUDED_BY_HIDESYM 1
89821+#endif
89822 #include <linux/kprobes.h>
89823 #include <linux/hash.h>
89824 #include <linux/init.h>
89825@@ -122,12 +125,12 @@ enum kprobe_slot_state {
89826
89827 static void *alloc_insn_page(void)
89828 {
89829- return module_alloc(PAGE_SIZE);
89830+ return module_alloc_exec(PAGE_SIZE);
89831 }
89832
89833 static void free_insn_page(void *page)
89834 {
89835- module_free(NULL, page);
89836+ module_free_exec(NULL, page);
89837 }
89838
89839 struct kprobe_insn_cache kprobe_insn_slots = {
89840@@ -2187,11 +2190,11 @@ static void report_probe(struct seq_file *pi, struct kprobe *p,
89841 kprobe_type = "k";
89842
89843 if (sym)
89844- seq_printf(pi, "%p %s %s+0x%x %s ",
89845+ seq_printf(pi, "%pK %s %s+0x%x %s ",
89846 p->addr, kprobe_type, sym, offset,
89847 (modname ? modname : " "));
89848 else
89849- seq_printf(pi, "%p %s %p ",
89850+ seq_printf(pi, "%pK %s %pK ",
89851 p->addr, kprobe_type, p->addr);
89852
89853 if (!pp)
89854diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
89855index 6683cce..daf8999 100644
89856--- a/kernel/ksysfs.c
89857+++ b/kernel/ksysfs.c
89858@@ -50,6 +50,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
89859 {
89860 if (count+1 > UEVENT_HELPER_PATH_LEN)
89861 return -ENOENT;
89862+ if (!capable(CAP_SYS_ADMIN))
89863+ return -EPERM;
89864 memcpy(uevent_helper, buf, count);
89865 uevent_helper[count] = '\0';
89866 if (count && uevent_helper[count-1] == '\n')
89867@@ -176,7 +178,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
89868 return count;
89869 }
89870
89871-static struct bin_attribute notes_attr = {
89872+static bin_attribute_no_const notes_attr __read_only = {
89873 .attr = {
89874 .name = "notes",
89875 .mode = S_IRUGO,
89876diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
89877index 88d0d44..e9ce0ee 100644
89878--- a/kernel/locking/lockdep.c
89879+++ b/kernel/locking/lockdep.c
89880@@ -599,6 +599,10 @@ static int static_obj(void *obj)
89881 end = (unsigned long) &_end,
89882 addr = (unsigned long) obj;
89883
89884+#ifdef CONFIG_PAX_KERNEXEC
89885+ start = ktla_ktva(start);
89886+#endif
89887+
89888 /*
89889 * static variable?
89890 */
89891@@ -740,6 +744,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
89892 if (!static_obj(lock->key)) {
89893 debug_locks_off();
89894 printk("INFO: trying to register non-static key.\n");
89895+ printk("lock:%pS key:%pS.\n", lock, lock->key);
89896 printk("the code is fine but needs lockdep annotation.\n");
89897 printk("turning off the locking correctness validator.\n");
89898 dump_stack();
89899@@ -3081,7 +3086,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
89900 if (!class)
89901 return 0;
89902 }
89903- atomic_inc((atomic_t *)&class->ops);
89904+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
89905 if (very_verbose(class)) {
89906 printk("\nacquire class [%p] %s", class->key, class->name);
89907 if (class->name_version > 1)
89908diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
89909index ef43ac4..2720dfa 100644
89910--- a/kernel/locking/lockdep_proc.c
89911+++ b/kernel/locking/lockdep_proc.c
89912@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
89913 return 0;
89914 }
89915
89916- seq_printf(m, "%p", class->key);
89917+ seq_printf(m, "%pK", class->key);
89918 #ifdef CONFIG_DEBUG_LOCKDEP
89919 seq_printf(m, " OPS:%8ld", class->ops);
89920 #endif
89921@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
89922
89923 list_for_each_entry(entry, &class->locks_after, entry) {
89924 if (entry->distance == 1) {
89925- seq_printf(m, " -> [%p] ", entry->class->key);
89926+ seq_printf(m, " -> [%pK] ", entry->class->key);
89927 print_name(m, entry->class);
89928 seq_puts(m, "\n");
89929 }
89930@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
89931 if (!class->key)
89932 continue;
89933
89934- seq_printf(m, "[%p] ", class->key);
89935+ seq_printf(m, "[%pK] ", class->key);
89936 print_name(m, class);
89937 seq_puts(m, "\n");
89938 }
89939@@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
89940 if (!i)
89941 seq_line(m, '-', 40-namelen, namelen);
89942
89943- snprintf(ip, sizeof(ip), "[<%p>]",
89944+ snprintf(ip, sizeof(ip), "[<%pK>]",
89945 (void *)class->contention_point[i]);
89946 seq_printf(m, "%40s %14lu %29s %pS\n",
89947 name, stats->contention_point[i],
89948@@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
89949 if (!i)
89950 seq_line(m, '-', 40-namelen, namelen);
89951
89952- snprintf(ip, sizeof(ip), "[<%p>]",
89953+ snprintf(ip, sizeof(ip), "[<%pK>]",
89954 (void *)class->contending_point[i]);
89955 seq_printf(m, "%40s %14lu %29s %pS\n",
89956 name, stats->contending_point[i],
89957diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
89958index 9887a90..0cd2b1d 100644
89959--- a/kernel/locking/mcs_spinlock.c
89960+++ b/kernel/locking/mcs_spinlock.c
89961@@ -100,7 +100,7 @@ bool osq_lock(struct optimistic_spin_queue *lock)
89962
89963 prev = decode_cpu(old);
89964 node->prev = prev;
89965- ACCESS_ONCE(prev->next) = node;
89966+ ACCESS_ONCE_RW(prev->next) = node;
89967
89968 /*
89969 * Normally @prev is untouchable after the above store; because at that
89970@@ -172,8 +172,8 @@ unqueue:
89971 * it will wait in Step-A.
89972 */
89973
89974- ACCESS_ONCE(next->prev) = prev;
89975- ACCESS_ONCE(prev->next) = next;
89976+ ACCESS_ONCE_RW(next->prev) = prev;
89977+ ACCESS_ONCE_RW(prev->next) = next;
89978
89979 return false;
89980 }
89981@@ -195,13 +195,13 @@ void osq_unlock(struct optimistic_spin_queue *lock)
89982 node = this_cpu_ptr(&osq_node);
89983 next = xchg(&node->next, NULL);
89984 if (next) {
89985- ACCESS_ONCE(next->locked) = 1;
89986+ ACCESS_ONCE_RW(next->locked) = 1;
89987 return;
89988 }
89989
89990 next = osq_wait_next(lock, node, NULL);
89991 if (next)
89992- ACCESS_ONCE(next->locked) = 1;
89993+ ACCESS_ONCE_RW(next->locked) = 1;
89994 }
89995
89996 #endif
89997diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
89998index 4d60986..5d351c1 100644
89999--- a/kernel/locking/mcs_spinlock.h
90000+++ b/kernel/locking/mcs_spinlock.h
90001@@ -78,7 +78,7 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
90002 */
90003 return;
90004 }
90005- ACCESS_ONCE(prev->next) = node;
90006+ ACCESS_ONCE_RW(prev->next) = node;
90007
90008 /* Wait until the lock holder passes the lock down. */
90009 arch_mcs_spin_lock_contended(&node->locked);
90010diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
90011index 5cf6731..ce3bc5a 100644
90012--- a/kernel/locking/mutex-debug.c
90013+++ b/kernel/locking/mutex-debug.c
90014@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
90015 }
90016
90017 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90018- struct thread_info *ti)
90019+ struct task_struct *task)
90020 {
90021 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
90022
90023 /* Mark the current thread as blocked on the lock: */
90024- ti->task->blocked_on = waiter;
90025+ task->blocked_on = waiter;
90026 }
90027
90028 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90029- struct thread_info *ti)
90030+ struct task_struct *task)
90031 {
90032 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
90033- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
90034- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
90035- ti->task->blocked_on = NULL;
90036+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
90037+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
90038+ task->blocked_on = NULL;
90039
90040 list_del_init(&waiter->list);
90041 waiter->task = NULL;
90042diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
90043index 0799fd3..d06ae3b 100644
90044--- a/kernel/locking/mutex-debug.h
90045+++ b/kernel/locking/mutex-debug.h
90046@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
90047 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
90048 extern void debug_mutex_add_waiter(struct mutex *lock,
90049 struct mutex_waiter *waiter,
90050- struct thread_info *ti);
90051+ struct task_struct *task);
90052 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90053- struct thread_info *ti);
90054+ struct task_struct *task);
90055 extern void debug_mutex_unlock(struct mutex *lock);
90056 extern void debug_mutex_init(struct mutex *lock, const char *name,
90057 struct lock_class_key *key);
90058diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
90059index dadbf88..4500507 100644
90060--- a/kernel/locking/mutex.c
90061+++ b/kernel/locking/mutex.c
90062@@ -518,7 +518,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
90063 goto skip_wait;
90064
90065 debug_mutex_lock_common(lock, &waiter);
90066- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
90067+ debug_mutex_add_waiter(lock, &waiter, task);
90068
90069 /* add waiting tasks to the end of the waitqueue (FIFO): */
90070 list_add_tail(&waiter.list, &lock->wait_list);
90071@@ -563,7 +563,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
90072 schedule_preempt_disabled();
90073 spin_lock_mutex(&lock->wait_lock, flags);
90074 }
90075- mutex_remove_waiter(lock, &waiter, current_thread_info());
90076+ mutex_remove_waiter(lock, &waiter, task);
90077 /* set it to 0 if there are no waiters left: */
90078 if (likely(list_empty(&lock->wait_list)))
90079 atomic_set(&lock->count, 0);
90080@@ -600,7 +600,7 @@ skip_wait:
90081 return 0;
90082
90083 err:
90084- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
90085+ mutex_remove_waiter(lock, &waiter, task);
90086 spin_unlock_mutex(&lock->wait_lock, flags);
90087 debug_mutex_free_waiter(&waiter);
90088 mutex_release(&lock->dep_map, 1, ip);
90089diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
90090index 1d96dd0..994ff19 100644
90091--- a/kernel/locking/rtmutex-tester.c
90092+++ b/kernel/locking/rtmutex-tester.c
90093@@ -22,7 +22,7 @@
90094 #define MAX_RT_TEST_MUTEXES 8
90095
90096 static spinlock_t rttest_lock;
90097-static atomic_t rttest_event;
90098+static atomic_unchecked_t rttest_event;
90099
90100 struct test_thread_data {
90101 int opcode;
90102@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90103
90104 case RTTEST_LOCKCONT:
90105 td->mutexes[td->opdata] = 1;
90106- td->event = atomic_add_return(1, &rttest_event);
90107+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90108 return 0;
90109
90110 case RTTEST_RESET:
90111@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90112 return 0;
90113
90114 case RTTEST_RESETEVENT:
90115- atomic_set(&rttest_event, 0);
90116+ atomic_set_unchecked(&rttest_event, 0);
90117 return 0;
90118
90119 default:
90120@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90121 return ret;
90122
90123 td->mutexes[id] = 1;
90124- td->event = atomic_add_return(1, &rttest_event);
90125+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90126 rt_mutex_lock(&mutexes[id]);
90127- td->event = atomic_add_return(1, &rttest_event);
90128+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90129 td->mutexes[id] = 4;
90130 return 0;
90131
90132@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90133 return ret;
90134
90135 td->mutexes[id] = 1;
90136- td->event = atomic_add_return(1, &rttest_event);
90137+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90138 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
90139- td->event = atomic_add_return(1, &rttest_event);
90140+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90141 td->mutexes[id] = ret ? 0 : 4;
90142 return ret ? -EINTR : 0;
90143
90144@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90145 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
90146 return ret;
90147
90148- td->event = atomic_add_return(1, &rttest_event);
90149+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90150 rt_mutex_unlock(&mutexes[id]);
90151- td->event = atomic_add_return(1, &rttest_event);
90152+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90153 td->mutexes[id] = 0;
90154 return 0;
90155
90156@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90157 break;
90158
90159 td->mutexes[dat] = 2;
90160- td->event = atomic_add_return(1, &rttest_event);
90161+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90162 break;
90163
90164 default:
90165@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90166 return;
90167
90168 td->mutexes[dat] = 3;
90169- td->event = atomic_add_return(1, &rttest_event);
90170+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90171 break;
90172
90173 case RTTEST_LOCKNOWAIT:
90174@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90175 return;
90176
90177 td->mutexes[dat] = 1;
90178- td->event = atomic_add_return(1, &rttest_event);
90179+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90180 return;
90181
90182 default:
90183diff --git a/kernel/module.c b/kernel/module.c
90184index 88cec1d..d097c28 100644
90185--- a/kernel/module.c
90186+++ b/kernel/module.c
90187@@ -60,6 +60,7 @@
90188 #include <linux/jump_label.h>
90189 #include <linux/pfn.h>
90190 #include <linux/bsearch.h>
90191+#include <linux/grsecurity.h>
90192 #include <uapi/linux/module.h>
90193 #include "module-internal.h"
90194
90195@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
90196
90197 /* Bounds of module allocation, for speeding __module_address.
90198 * Protected by module_mutex. */
90199-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
90200+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
90201+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
90202
90203 int register_module_notifier(struct notifier_block * nb)
90204 {
90205@@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
90206 return true;
90207
90208 list_for_each_entry_rcu(mod, &modules, list) {
90209- struct symsearch arr[] = {
90210+ struct symsearch modarr[] = {
90211 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
90212 NOT_GPL_ONLY, false },
90213 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
90214@@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
90215 if (mod->state == MODULE_STATE_UNFORMED)
90216 continue;
90217
90218- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
90219+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
90220 return true;
90221 }
90222 return false;
90223@@ -488,7 +490,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
90224 if (!pcpusec->sh_size)
90225 return 0;
90226
90227- if (align > PAGE_SIZE) {
90228+ if (align-1 >= PAGE_SIZE) {
90229 pr_warn("%s: per-cpu alignment %li > %li\n",
90230 mod->name, align, PAGE_SIZE);
90231 align = PAGE_SIZE;
90232@@ -1060,7 +1062,7 @@ struct module_attribute module_uevent =
90233 static ssize_t show_coresize(struct module_attribute *mattr,
90234 struct module_kobject *mk, char *buffer)
90235 {
90236- return sprintf(buffer, "%u\n", mk->mod->core_size);
90237+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
90238 }
90239
90240 static struct module_attribute modinfo_coresize =
90241@@ -1069,7 +1071,7 @@ static struct module_attribute modinfo_coresize =
90242 static ssize_t show_initsize(struct module_attribute *mattr,
90243 struct module_kobject *mk, char *buffer)
90244 {
90245- return sprintf(buffer, "%u\n", mk->mod->init_size);
90246+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
90247 }
90248
90249 static struct module_attribute modinfo_initsize =
90250@@ -1161,12 +1163,29 @@ static int check_version(Elf_Shdr *sechdrs,
90251 goto bad_version;
90252 }
90253
90254+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90255+ /*
90256+ * avoid potentially printing jibberish on attempted load
90257+ * of a module randomized with a different seed
90258+ */
90259+ pr_warn("no symbol version for %s\n", symname);
90260+#else
90261 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
90262+#endif
90263 return 0;
90264
90265 bad_version:
90266+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90267+ /*
90268+ * avoid potentially printing jibberish on attempted load
90269+ * of a module randomized with a different seed
90270+ */
90271+ printk("attempted module disagrees about version of symbol %s\n",
90272+ symname);
90273+#else
90274 printk("%s: disagrees about version of symbol %s\n",
90275 mod->name, symname);
90276+#endif
90277 return 0;
90278 }
90279
90280@@ -1282,7 +1301,7 @@ resolve_symbol_wait(struct module *mod,
90281 */
90282 #ifdef CONFIG_SYSFS
90283
90284-#ifdef CONFIG_KALLSYMS
90285+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
90286 static inline bool sect_empty(const Elf_Shdr *sect)
90287 {
90288 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
90289@@ -1422,7 +1441,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
90290 {
90291 unsigned int notes, loaded, i;
90292 struct module_notes_attrs *notes_attrs;
90293- struct bin_attribute *nattr;
90294+ bin_attribute_no_const *nattr;
90295
90296 /* failed to create section attributes, so can't create notes */
90297 if (!mod->sect_attrs)
90298@@ -1534,7 +1553,7 @@ static void del_usage_links(struct module *mod)
90299 static int module_add_modinfo_attrs(struct module *mod)
90300 {
90301 struct module_attribute *attr;
90302- struct module_attribute *temp_attr;
90303+ module_attribute_no_const *temp_attr;
90304 int error = 0;
90305 int i;
90306
90307@@ -1755,21 +1774,21 @@ static void set_section_ro_nx(void *base,
90308
90309 static void unset_module_core_ro_nx(struct module *mod)
90310 {
90311- set_page_attributes(mod->module_core + mod->core_text_size,
90312- mod->module_core + mod->core_size,
90313+ set_page_attributes(mod->module_core_rw,
90314+ mod->module_core_rw + mod->core_size_rw,
90315 set_memory_x);
90316- set_page_attributes(mod->module_core,
90317- mod->module_core + mod->core_ro_size,
90318+ set_page_attributes(mod->module_core_rx,
90319+ mod->module_core_rx + mod->core_size_rx,
90320 set_memory_rw);
90321 }
90322
90323 static void unset_module_init_ro_nx(struct module *mod)
90324 {
90325- set_page_attributes(mod->module_init + mod->init_text_size,
90326- mod->module_init + mod->init_size,
90327+ set_page_attributes(mod->module_init_rw,
90328+ mod->module_init_rw + mod->init_size_rw,
90329 set_memory_x);
90330- set_page_attributes(mod->module_init,
90331- mod->module_init + mod->init_ro_size,
90332+ set_page_attributes(mod->module_init_rx,
90333+ mod->module_init_rx + mod->init_size_rx,
90334 set_memory_rw);
90335 }
90336
90337@@ -1782,14 +1801,14 @@ void set_all_modules_text_rw(void)
90338 list_for_each_entry_rcu(mod, &modules, list) {
90339 if (mod->state == MODULE_STATE_UNFORMED)
90340 continue;
90341- if ((mod->module_core) && (mod->core_text_size)) {
90342- set_page_attributes(mod->module_core,
90343- mod->module_core + mod->core_text_size,
90344+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
90345+ set_page_attributes(mod->module_core_rx,
90346+ mod->module_core_rx + mod->core_size_rx,
90347 set_memory_rw);
90348 }
90349- if ((mod->module_init) && (mod->init_text_size)) {
90350- set_page_attributes(mod->module_init,
90351- mod->module_init + mod->init_text_size,
90352+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
90353+ set_page_attributes(mod->module_init_rx,
90354+ mod->module_init_rx + mod->init_size_rx,
90355 set_memory_rw);
90356 }
90357 }
90358@@ -1805,14 +1824,14 @@ void set_all_modules_text_ro(void)
90359 list_for_each_entry_rcu(mod, &modules, list) {
90360 if (mod->state == MODULE_STATE_UNFORMED)
90361 continue;
90362- if ((mod->module_core) && (mod->core_text_size)) {
90363- set_page_attributes(mod->module_core,
90364- mod->module_core + mod->core_text_size,
90365+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
90366+ set_page_attributes(mod->module_core_rx,
90367+ mod->module_core_rx + mod->core_size_rx,
90368 set_memory_ro);
90369 }
90370- if ((mod->module_init) && (mod->init_text_size)) {
90371- set_page_attributes(mod->module_init,
90372- mod->module_init + mod->init_text_size,
90373+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
90374+ set_page_attributes(mod->module_init_rx,
90375+ mod->module_init_rx + mod->init_size_rx,
90376 set_memory_ro);
90377 }
90378 }
90379@@ -1865,16 +1884,19 @@ static void free_module(struct module *mod)
90380
90381 /* This may be NULL, but that's OK */
90382 unset_module_init_ro_nx(mod);
90383- module_free(mod, mod->module_init);
90384+ module_free(mod, mod->module_init_rw);
90385+ module_free_exec(mod, mod->module_init_rx);
90386 kfree(mod->args);
90387 percpu_modfree(mod);
90388
90389 /* Free lock-classes: */
90390- lockdep_free_key_range(mod->module_core, mod->core_size);
90391+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
90392+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
90393
90394 /* Finally, free the core (containing the module structure) */
90395 unset_module_core_ro_nx(mod);
90396- module_free(mod, mod->module_core);
90397+ module_free_exec(mod, mod->module_core_rx);
90398+ module_free(mod, mod->module_core_rw);
90399
90400 #ifdef CONFIG_MPU
90401 update_protections(current->mm);
90402@@ -1943,9 +1965,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90403 int ret = 0;
90404 const struct kernel_symbol *ksym;
90405
90406+#ifdef CONFIG_GRKERNSEC_MODHARDEN
90407+ int is_fs_load = 0;
90408+ int register_filesystem_found = 0;
90409+ char *p;
90410+
90411+ p = strstr(mod->args, "grsec_modharden_fs");
90412+ if (p) {
90413+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
90414+ /* copy \0 as well */
90415+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
90416+ is_fs_load = 1;
90417+ }
90418+#endif
90419+
90420 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
90421 const char *name = info->strtab + sym[i].st_name;
90422
90423+#ifdef CONFIG_GRKERNSEC_MODHARDEN
90424+ /* it's a real shame this will never get ripped and copied
90425+ upstream! ;(
90426+ */
90427+ if (is_fs_load && !strcmp(name, "register_filesystem"))
90428+ register_filesystem_found = 1;
90429+#endif
90430+
90431 switch (sym[i].st_shndx) {
90432 case SHN_COMMON:
90433 /* Ignore common symbols */
90434@@ -1970,7 +2014,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90435 ksym = resolve_symbol_wait(mod, info, name);
90436 /* Ok if resolved. */
90437 if (ksym && !IS_ERR(ksym)) {
90438+ pax_open_kernel();
90439 sym[i].st_value = ksym->value;
90440+ pax_close_kernel();
90441 break;
90442 }
90443
90444@@ -1989,11 +2035,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90445 secbase = (unsigned long)mod_percpu(mod);
90446 else
90447 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
90448+ pax_open_kernel();
90449 sym[i].st_value += secbase;
90450+ pax_close_kernel();
90451 break;
90452 }
90453 }
90454
90455+#ifdef CONFIG_GRKERNSEC_MODHARDEN
90456+ if (is_fs_load && !register_filesystem_found) {
90457+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
90458+ ret = -EPERM;
90459+ }
90460+#endif
90461+
90462 return ret;
90463 }
90464
90465@@ -2077,22 +2132,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
90466 || s->sh_entsize != ~0UL
90467 || strstarts(sname, ".init"))
90468 continue;
90469- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
90470+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
90471+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
90472+ else
90473+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
90474 pr_debug("\t%s\n", sname);
90475 }
90476- switch (m) {
90477- case 0: /* executable */
90478- mod->core_size = debug_align(mod->core_size);
90479- mod->core_text_size = mod->core_size;
90480- break;
90481- case 1: /* RO: text and ro-data */
90482- mod->core_size = debug_align(mod->core_size);
90483- mod->core_ro_size = mod->core_size;
90484- break;
90485- case 3: /* whole core */
90486- mod->core_size = debug_align(mod->core_size);
90487- break;
90488- }
90489 }
90490
90491 pr_debug("Init section allocation order:\n");
90492@@ -2106,23 +2151,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
90493 || s->sh_entsize != ~0UL
90494 || !strstarts(sname, ".init"))
90495 continue;
90496- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
90497- | INIT_OFFSET_MASK);
90498+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
90499+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
90500+ else
90501+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
90502+ s->sh_entsize |= INIT_OFFSET_MASK;
90503 pr_debug("\t%s\n", sname);
90504 }
90505- switch (m) {
90506- case 0: /* executable */
90507- mod->init_size = debug_align(mod->init_size);
90508- mod->init_text_size = mod->init_size;
90509- break;
90510- case 1: /* RO: text and ro-data */
90511- mod->init_size = debug_align(mod->init_size);
90512- mod->init_ro_size = mod->init_size;
90513- break;
90514- case 3: /* whole init */
90515- mod->init_size = debug_align(mod->init_size);
90516- break;
90517- }
90518 }
90519 }
90520
90521@@ -2295,7 +2330,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
90522
90523 /* Put symbol section at end of init part of module. */
90524 symsect->sh_flags |= SHF_ALLOC;
90525- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
90526+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
90527 info->index.sym) | INIT_OFFSET_MASK;
90528 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
90529
90530@@ -2312,13 +2347,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
90531 }
90532
90533 /* Append room for core symbols at end of core part. */
90534- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
90535- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
90536- mod->core_size += strtab_size;
90537+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
90538+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
90539+ mod->core_size_rx += strtab_size;
90540
90541 /* Put string table section at end of init part of module. */
90542 strsect->sh_flags |= SHF_ALLOC;
90543- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
90544+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
90545 info->index.str) | INIT_OFFSET_MASK;
90546 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
90547 }
90548@@ -2336,12 +2371,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
90549 /* Make sure we get permanent strtab: don't use info->strtab. */
90550 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
90551
90552+ pax_open_kernel();
90553+
90554 /* Set types up while we still have access to sections. */
90555 for (i = 0; i < mod->num_symtab; i++)
90556 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
90557
90558- mod->core_symtab = dst = mod->module_core + info->symoffs;
90559- mod->core_strtab = s = mod->module_core + info->stroffs;
90560+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
90561+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
90562 src = mod->symtab;
90563 for (ndst = i = 0; i < mod->num_symtab; i++) {
90564 if (i == 0 ||
90565@@ -2353,6 +2390,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
90566 }
90567 }
90568 mod->core_num_syms = ndst;
90569+
90570+ pax_close_kernel();
90571 }
90572 #else
90573 static inline void layout_symtab(struct module *mod, struct load_info *info)
90574@@ -2386,17 +2425,33 @@ void * __weak module_alloc(unsigned long size)
90575 return vmalloc_exec(size);
90576 }
90577
90578-static void *module_alloc_update_bounds(unsigned long size)
90579+static void *module_alloc_update_bounds_rw(unsigned long size)
90580 {
90581 void *ret = module_alloc(size);
90582
90583 if (ret) {
90584 mutex_lock(&module_mutex);
90585 /* Update module bounds. */
90586- if ((unsigned long)ret < module_addr_min)
90587- module_addr_min = (unsigned long)ret;
90588- if ((unsigned long)ret + size > module_addr_max)
90589- module_addr_max = (unsigned long)ret + size;
90590+ if ((unsigned long)ret < module_addr_min_rw)
90591+ module_addr_min_rw = (unsigned long)ret;
90592+ if ((unsigned long)ret + size > module_addr_max_rw)
90593+ module_addr_max_rw = (unsigned long)ret + size;
90594+ mutex_unlock(&module_mutex);
90595+ }
90596+ return ret;
90597+}
90598+
90599+static void *module_alloc_update_bounds_rx(unsigned long size)
90600+{
90601+ void *ret = module_alloc_exec(size);
90602+
90603+ if (ret) {
90604+ mutex_lock(&module_mutex);
90605+ /* Update module bounds. */
90606+ if ((unsigned long)ret < module_addr_min_rx)
90607+ module_addr_min_rx = (unsigned long)ret;
90608+ if ((unsigned long)ret + size > module_addr_max_rx)
90609+ module_addr_max_rx = (unsigned long)ret + size;
90610 mutex_unlock(&module_mutex);
90611 }
90612 return ret;
90613@@ -2650,7 +2705,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
90614 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
90615
90616 if (info->index.sym == 0) {
90617+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90618+ /*
90619+ * avoid potentially printing jibberish on attempted load
90620+ * of a module randomized with a different seed
90621+ */
90622+ pr_warn("module has no symbols (stripped?)\n");
90623+#else
90624 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
90625+#endif
90626 return ERR_PTR(-ENOEXEC);
90627 }
90628
90629@@ -2666,8 +2729,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
90630 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
90631 {
90632 const char *modmagic = get_modinfo(info, "vermagic");
90633+ const char *license = get_modinfo(info, "license");
90634 int err;
90635
90636+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
90637+ if (!license || !license_is_gpl_compatible(license))
90638+ return -ENOEXEC;
90639+#endif
90640+
90641 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
90642 modmagic = NULL;
90643
90644@@ -2692,7 +2761,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
90645 }
90646
90647 /* Set up license info based on the info section */
90648- set_license(mod, get_modinfo(info, "license"));
90649+ set_license(mod, license);
90650
90651 return 0;
90652 }
90653@@ -2786,7 +2855,7 @@ static int move_module(struct module *mod, struct load_info *info)
90654 void *ptr;
90655
90656 /* Do the allocs. */
90657- ptr = module_alloc_update_bounds(mod->core_size);
90658+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
90659 /*
90660 * The pointer to this block is stored in the module structure
90661 * which is inside the block. Just mark it as not being a
90662@@ -2796,11 +2865,11 @@ static int move_module(struct module *mod, struct load_info *info)
90663 if (!ptr)
90664 return -ENOMEM;
90665
90666- memset(ptr, 0, mod->core_size);
90667- mod->module_core = ptr;
90668+ memset(ptr, 0, mod->core_size_rw);
90669+ mod->module_core_rw = ptr;
90670
90671- if (mod->init_size) {
90672- ptr = module_alloc_update_bounds(mod->init_size);
90673+ if (mod->init_size_rw) {
90674+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
90675 /*
90676 * The pointer to this block is stored in the module structure
90677 * which is inside the block. This block doesn't need to be
90678@@ -2809,13 +2878,45 @@ static int move_module(struct module *mod, struct load_info *info)
90679 */
90680 kmemleak_ignore(ptr);
90681 if (!ptr) {
90682- module_free(mod, mod->module_core);
90683+ module_free(mod, mod->module_core_rw);
90684 return -ENOMEM;
90685 }
90686- memset(ptr, 0, mod->init_size);
90687- mod->module_init = ptr;
90688+ memset(ptr, 0, mod->init_size_rw);
90689+ mod->module_init_rw = ptr;
90690 } else
90691- mod->module_init = NULL;
90692+ mod->module_init_rw = NULL;
90693+
90694+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
90695+ kmemleak_not_leak(ptr);
90696+ if (!ptr) {
90697+ if (mod->module_init_rw)
90698+ module_free(mod, mod->module_init_rw);
90699+ module_free(mod, mod->module_core_rw);
90700+ return -ENOMEM;
90701+ }
90702+
90703+ pax_open_kernel();
90704+ memset(ptr, 0, mod->core_size_rx);
90705+ pax_close_kernel();
90706+ mod->module_core_rx = ptr;
90707+
90708+ if (mod->init_size_rx) {
90709+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
90710+ kmemleak_ignore(ptr);
90711+ if (!ptr && mod->init_size_rx) {
90712+ module_free_exec(mod, mod->module_core_rx);
90713+ if (mod->module_init_rw)
90714+ module_free(mod, mod->module_init_rw);
90715+ module_free(mod, mod->module_core_rw);
90716+ return -ENOMEM;
90717+ }
90718+
90719+ pax_open_kernel();
90720+ memset(ptr, 0, mod->init_size_rx);
90721+ pax_close_kernel();
90722+ mod->module_init_rx = ptr;
90723+ } else
90724+ mod->module_init_rx = NULL;
90725
90726 /* Transfer each section which specifies SHF_ALLOC */
90727 pr_debug("final section addresses:\n");
90728@@ -2826,16 +2927,45 @@ static int move_module(struct module *mod, struct load_info *info)
90729 if (!(shdr->sh_flags & SHF_ALLOC))
90730 continue;
90731
90732- if (shdr->sh_entsize & INIT_OFFSET_MASK)
90733- dest = mod->module_init
90734- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
90735- else
90736- dest = mod->module_core + shdr->sh_entsize;
90737+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
90738+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
90739+ dest = mod->module_init_rw
90740+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
90741+ else
90742+ dest = mod->module_init_rx
90743+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
90744+ } else {
90745+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
90746+ dest = mod->module_core_rw + shdr->sh_entsize;
90747+ else
90748+ dest = mod->module_core_rx + shdr->sh_entsize;
90749+ }
90750+
90751+ if (shdr->sh_type != SHT_NOBITS) {
90752+
90753+#ifdef CONFIG_PAX_KERNEXEC
90754+#ifdef CONFIG_X86_64
90755+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
90756+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
90757+#endif
90758+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
90759+ pax_open_kernel();
90760+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
90761+ pax_close_kernel();
90762+ } else
90763+#endif
90764
90765- if (shdr->sh_type != SHT_NOBITS)
90766 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
90767+ }
90768 /* Update sh_addr to point to copy in image. */
90769- shdr->sh_addr = (unsigned long)dest;
90770+
90771+#ifdef CONFIG_PAX_KERNEXEC
90772+ if (shdr->sh_flags & SHF_EXECINSTR)
90773+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
90774+ else
90775+#endif
90776+
90777+ shdr->sh_addr = (unsigned long)dest;
90778 pr_debug("\t0x%lx %s\n",
90779 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
90780 }
90781@@ -2892,12 +3022,12 @@ static void flush_module_icache(const struct module *mod)
90782 * Do it before processing of module parameters, so the module
90783 * can provide parameter accessor functions of its own.
90784 */
90785- if (mod->module_init)
90786- flush_icache_range((unsigned long)mod->module_init,
90787- (unsigned long)mod->module_init
90788- + mod->init_size);
90789- flush_icache_range((unsigned long)mod->module_core,
90790- (unsigned long)mod->module_core + mod->core_size);
90791+ if (mod->module_init_rx)
90792+ flush_icache_range((unsigned long)mod->module_init_rx,
90793+ (unsigned long)mod->module_init_rx
90794+ + mod->init_size_rx);
90795+ flush_icache_range((unsigned long)mod->module_core_rx,
90796+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
90797
90798 set_fs(old_fs);
90799 }
90800@@ -2954,8 +3084,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
90801 static void module_deallocate(struct module *mod, struct load_info *info)
90802 {
90803 percpu_modfree(mod);
90804- module_free(mod, mod->module_init);
90805- module_free(mod, mod->module_core);
90806+ module_free_exec(mod, mod->module_init_rx);
90807+ module_free_exec(mod, mod->module_core_rx);
90808+ module_free(mod, mod->module_init_rw);
90809+ module_free(mod, mod->module_core_rw);
90810 }
90811
90812 int __weak module_finalize(const Elf_Ehdr *hdr,
90813@@ -2968,7 +3100,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
90814 static int post_relocation(struct module *mod, const struct load_info *info)
90815 {
90816 /* Sort exception table now relocations are done. */
90817+ pax_open_kernel();
90818 sort_extable(mod->extable, mod->extable + mod->num_exentries);
90819+ pax_close_kernel();
90820
90821 /* Copy relocated percpu area over. */
90822 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
90823@@ -3077,11 +3211,12 @@ static int do_init_module(struct module *mod)
90824 mod->strtab = mod->core_strtab;
90825 #endif
90826 unset_module_init_ro_nx(mod);
90827- module_free(mod, mod->module_init);
90828- mod->module_init = NULL;
90829- mod->init_size = 0;
90830- mod->init_ro_size = 0;
90831- mod->init_text_size = 0;
90832+ module_free(mod, mod->module_init_rw);
90833+ module_free_exec(mod, mod->module_init_rx);
90834+ mod->module_init_rw = NULL;
90835+ mod->module_init_rx = NULL;
90836+ mod->init_size_rw = 0;
90837+ mod->init_size_rx = 0;
90838 mutex_unlock(&module_mutex);
90839 wake_up_all(&module_wq);
90840
90841@@ -3149,16 +3284,16 @@ static int complete_formation(struct module *mod, struct load_info *info)
90842 module_bug_finalize(info->hdr, info->sechdrs, mod);
90843
90844 /* Set RO and NX regions for core */
90845- set_section_ro_nx(mod->module_core,
90846- mod->core_text_size,
90847- mod->core_ro_size,
90848- mod->core_size);
90849+ set_section_ro_nx(mod->module_core_rx,
90850+ mod->core_size_rx,
90851+ mod->core_size_rx,
90852+ mod->core_size_rx);
90853
90854 /* Set RO and NX regions for init */
90855- set_section_ro_nx(mod->module_init,
90856- mod->init_text_size,
90857- mod->init_ro_size,
90858- mod->init_size);
90859+ set_section_ro_nx(mod->module_init_rx,
90860+ mod->init_size_rx,
90861+ mod->init_size_rx,
90862+ mod->init_size_rx);
90863
90864 /* Mark state as coming so strong_try_module_get() ignores us,
90865 * but kallsyms etc. can see us. */
90866@@ -3242,9 +3377,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
90867 if (err)
90868 goto free_unload;
90869
90870+ /* Now copy in args */
90871+ mod->args = strndup_user(uargs, ~0UL >> 1);
90872+ if (IS_ERR(mod->args)) {
90873+ err = PTR_ERR(mod->args);
90874+ goto free_unload;
90875+ }
90876+
90877 /* Set up MODINFO_ATTR fields */
90878 setup_modinfo(mod, info);
90879
90880+#ifdef CONFIG_GRKERNSEC_MODHARDEN
90881+ {
90882+ char *p, *p2;
90883+
90884+ if (strstr(mod->args, "grsec_modharden_netdev")) {
90885+ 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);
90886+ err = -EPERM;
90887+ goto free_modinfo;
90888+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
90889+ p += sizeof("grsec_modharden_normal") - 1;
90890+ p2 = strstr(p, "_");
90891+ if (p2) {
90892+ *p2 = '\0';
90893+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
90894+ *p2 = '_';
90895+ }
90896+ err = -EPERM;
90897+ goto free_modinfo;
90898+ }
90899+ }
90900+#endif
90901+
90902 /* Fix up syms, so that st_value is a pointer to location. */
90903 err = simplify_symbols(mod, info);
90904 if (err < 0)
90905@@ -3260,13 +3424,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
90906
90907 flush_module_icache(mod);
90908
90909- /* Now copy in args */
90910- mod->args = strndup_user(uargs, ~0UL >> 1);
90911- if (IS_ERR(mod->args)) {
90912- err = PTR_ERR(mod->args);
90913- goto free_arch_cleanup;
90914- }
90915-
90916 dynamic_debug_setup(info->debug, info->num_debug);
90917
90918 /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
90919@@ -3314,11 +3471,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
90920 ddebug_cleanup:
90921 dynamic_debug_remove(info->debug);
90922 synchronize_sched();
90923- kfree(mod->args);
90924- free_arch_cleanup:
90925 module_arch_cleanup(mod);
90926 free_modinfo:
90927 free_modinfo(mod);
90928+ kfree(mod->args);
90929 free_unload:
90930 module_unload_free(mod);
90931 unlink_mod:
90932@@ -3403,10 +3559,16 @@ static const char *get_ksymbol(struct module *mod,
90933 unsigned long nextval;
90934
90935 /* At worse, next value is at end of module */
90936- if (within_module_init(addr, mod))
90937- nextval = (unsigned long)mod->module_init+mod->init_text_size;
90938+ if (within_module_init_rx(addr, mod))
90939+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
90940+ else if (within_module_init_rw(addr, mod))
90941+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
90942+ else if (within_module_core_rx(addr, mod))
90943+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
90944+ else if (within_module_core_rw(addr, mod))
90945+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
90946 else
90947- nextval = (unsigned long)mod->module_core+mod->core_text_size;
90948+ return NULL;
90949
90950 /* Scan for closest preceding symbol, and next symbol. (ELF
90951 starts real symbols at 1). */
90952@@ -3654,7 +3816,7 @@ static int m_show(struct seq_file *m, void *p)
90953 return 0;
90954
90955 seq_printf(m, "%s %u",
90956- mod->name, mod->init_size + mod->core_size);
90957+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
90958 print_unload_info(m, mod);
90959
90960 /* Informative for users. */
90961@@ -3663,7 +3825,7 @@ static int m_show(struct seq_file *m, void *p)
90962 mod->state == MODULE_STATE_COMING ? "Loading":
90963 "Live");
90964 /* Used by oprofile and other similar tools. */
90965- seq_printf(m, " 0x%pK", mod->module_core);
90966+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
90967
90968 /* Taints info */
90969 if (mod->taints)
90970@@ -3699,7 +3861,17 @@ static const struct file_operations proc_modules_operations = {
90971
90972 static int __init proc_modules_init(void)
90973 {
90974+#ifndef CONFIG_GRKERNSEC_HIDESYM
90975+#ifdef CONFIG_GRKERNSEC_PROC_USER
90976+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
90977+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
90978+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
90979+#else
90980 proc_create("modules", 0, NULL, &proc_modules_operations);
90981+#endif
90982+#else
90983+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
90984+#endif
90985 return 0;
90986 }
90987 module_init(proc_modules_init);
90988@@ -3760,7 +3932,8 @@ struct module *__module_address(unsigned long addr)
90989 {
90990 struct module *mod;
90991
90992- if (addr < module_addr_min || addr > module_addr_max)
90993+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
90994+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
90995 return NULL;
90996
90997 list_for_each_entry_rcu(mod, &modules, list) {
90998@@ -3801,11 +3974,20 @@ bool is_module_text_address(unsigned long addr)
90999 */
91000 struct module *__module_text_address(unsigned long addr)
91001 {
91002- struct module *mod = __module_address(addr);
91003+ struct module *mod;
91004+
91005+#ifdef CONFIG_X86_32
91006+ addr = ktla_ktva(addr);
91007+#endif
91008+
91009+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
91010+ return NULL;
91011+
91012+ mod = __module_address(addr);
91013+
91014 if (mod) {
91015 /* Make sure it's within the text section. */
91016- if (!within(addr, mod->module_init, mod->init_text_size)
91017- && !within(addr, mod->module_core, mod->core_text_size))
91018+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
91019 mod = NULL;
91020 }
91021 return mod;
91022diff --git a/kernel/notifier.c b/kernel/notifier.c
91023index 4803da6..1c5eea6 100644
91024--- a/kernel/notifier.c
91025+++ b/kernel/notifier.c
91026@@ -5,6 +5,7 @@
91027 #include <linux/rcupdate.h>
91028 #include <linux/vmalloc.h>
91029 #include <linux/reboot.h>
91030+#include <linux/mm.h>
91031
91032 /*
91033 * Notifier list for kernel code which wants to be called
91034@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
91035 while ((*nl) != NULL) {
91036 if (n->priority > (*nl)->priority)
91037 break;
91038- nl = &((*nl)->next);
91039+ nl = (struct notifier_block **)&((*nl)->next);
91040 }
91041- n->next = *nl;
91042+ pax_open_kernel();
91043+ *(const void **)&n->next = *nl;
91044 rcu_assign_pointer(*nl, n);
91045+ pax_close_kernel();
91046 return 0;
91047 }
91048
91049@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
91050 return 0;
91051 if (n->priority > (*nl)->priority)
91052 break;
91053- nl = &((*nl)->next);
91054+ nl = (struct notifier_block **)&((*nl)->next);
91055 }
91056- n->next = *nl;
91057+ pax_open_kernel();
91058+ *(const void **)&n->next = *nl;
91059 rcu_assign_pointer(*nl, n);
91060+ pax_close_kernel();
91061 return 0;
91062 }
91063
91064@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
91065 {
91066 while ((*nl) != NULL) {
91067 if ((*nl) == n) {
91068+ pax_open_kernel();
91069 rcu_assign_pointer(*nl, n->next);
91070+ pax_close_kernel();
91071 return 0;
91072 }
91073- nl = &((*nl)->next);
91074+ nl = (struct notifier_block **)&((*nl)->next);
91075 }
91076 return -ENOENT;
91077 }
91078diff --git a/kernel/padata.c b/kernel/padata.c
91079index 161402f..598814c 100644
91080--- a/kernel/padata.c
91081+++ b/kernel/padata.c
91082@@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
91083 * seq_nr mod. number of cpus in use.
91084 */
91085
91086- seq_nr = atomic_inc_return(&pd->seq_nr);
91087+ seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
91088 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
91089
91090 return padata_index_to_cpu(pd, cpu_index);
91091@@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
91092 padata_init_pqueues(pd);
91093 padata_init_squeues(pd);
91094 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
91095- atomic_set(&pd->seq_nr, -1);
91096+ atomic_set_unchecked(&pd->seq_nr, -1);
91097 atomic_set(&pd->reorder_objects, 0);
91098 atomic_set(&pd->refcnt, 0);
91099 pd->pinst = pinst;
91100diff --git a/kernel/panic.c b/kernel/panic.c
91101index cf80672..f6771b2 100644
91102--- a/kernel/panic.c
91103+++ b/kernel/panic.c
91104@@ -53,7 +53,7 @@ EXPORT_SYMBOL(panic_blink);
91105 /*
91106 * Stop ourself in panic -- architecture code may override this
91107 */
91108-void __weak panic_smp_self_stop(void)
91109+void __weak __noreturn panic_smp_self_stop(void)
91110 {
91111 while (1)
91112 cpu_relax();
91113@@ -422,7 +422,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
91114 disable_trace_on_warning();
91115
91116 pr_warn("------------[ cut here ]------------\n");
91117- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
91118+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
91119 raw_smp_processor_id(), current->pid, file, line, caller);
91120
91121 if (args)
91122@@ -476,7 +476,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
91123 */
91124 __visible void __stack_chk_fail(void)
91125 {
91126- panic("stack-protector: Kernel stack is corrupted in: %p\n",
91127+ dump_stack();
91128+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
91129 __builtin_return_address(0));
91130 }
91131 EXPORT_SYMBOL(__stack_chk_fail);
91132diff --git a/kernel/pid.c b/kernel/pid.c
91133index 9b9a266..c20ef80 100644
91134--- a/kernel/pid.c
91135+++ b/kernel/pid.c
91136@@ -33,6 +33,7 @@
91137 #include <linux/rculist.h>
91138 #include <linux/bootmem.h>
91139 #include <linux/hash.h>
91140+#include <linux/security.h>
91141 #include <linux/pid_namespace.h>
91142 #include <linux/init_task.h>
91143 #include <linux/syscalls.h>
91144@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
91145
91146 int pid_max = PID_MAX_DEFAULT;
91147
91148-#define RESERVED_PIDS 300
91149+#define RESERVED_PIDS 500
91150
91151 int pid_max_min = RESERVED_PIDS + 1;
91152 int pid_max_max = PID_MAX_LIMIT;
91153@@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
91154 */
91155 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
91156 {
91157+ struct task_struct *task;
91158+
91159 rcu_lockdep_assert(rcu_read_lock_held(),
91160 "find_task_by_pid_ns() needs rcu_read_lock()"
91161 " protection");
91162- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
91163+
91164+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
91165+
91166+ if (gr_pid_is_chrooted(task))
91167+ return NULL;
91168+
91169+ return task;
91170 }
91171
91172 struct task_struct *find_task_by_vpid(pid_t vnr)
91173@@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
91174 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
91175 }
91176
91177+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
91178+{
91179+ rcu_lockdep_assert(rcu_read_lock_held(),
91180+ "find_task_by_pid_ns() needs rcu_read_lock()"
91181+ " protection");
91182+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
91183+}
91184+
91185 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
91186 {
91187 struct pid *pid;
91188diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
91189index db95d8e..a0ca23f 100644
91190--- a/kernel/pid_namespace.c
91191+++ b/kernel/pid_namespace.c
91192@@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
91193 void __user *buffer, size_t *lenp, loff_t *ppos)
91194 {
91195 struct pid_namespace *pid_ns = task_active_pid_ns(current);
91196- struct ctl_table tmp = *table;
91197+ ctl_table_no_const tmp = *table;
91198
91199 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
91200 return -EPERM;
91201diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
91202index bbef57f..5f94462 100644
91203--- a/kernel/power/Kconfig
91204+++ b/kernel/power/Kconfig
91205@@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
91206 config HIBERNATION
91207 bool "Hibernation (aka 'suspend to disk')"
91208 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
91209+ depends on !GRKERNSEC_KMEM
91210+ depends on !PAX_MEMORY_SANITIZE
91211 select HIBERNATE_CALLBACKS
91212 select LZO_COMPRESS
91213 select LZO_DECOMPRESS
91214diff --git a/kernel/power/process.c b/kernel/power/process.c
91215index 5a6ec86..3a8c884 100644
91216--- a/kernel/power/process.c
91217+++ b/kernel/power/process.c
91218@@ -35,6 +35,7 @@ static int try_to_freeze_tasks(bool user_only)
91219 unsigned int elapsed_msecs;
91220 bool wakeup = false;
91221 int sleep_usecs = USEC_PER_MSEC;
91222+ bool timedout = false;
91223
91224 do_gettimeofday(&start);
91225
91226@@ -45,13 +46,20 @@ static int try_to_freeze_tasks(bool user_only)
91227
91228 while (true) {
91229 todo = 0;
91230+ if (time_after(jiffies, end_time))
91231+ timedout = true;
91232 read_lock(&tasklist_lock);
91233 for_each_process_thread(g, p) {
91234 if (p == current || !freeze_task(p))
91235 continue;
91236
91237- if (!freezer_should_skip(p))
91238+ if (!freezer_should_skip(p)) {
91239 todo++;
91240+ if (timedout) {
91241+ printk(KERN_ERR "Task refusing to freeze:\n");
91242+ sched_show_task(p);
91243+ }
91244+ }
91245 }
91246 read_unlock(&tasklist_lock);
91247
91248@@ -60,7 +68,7 @@ static int try_to_freeze_tasks(bool user_only)
91249 todo += wq_busy;
91250 }
91251
91252- if (!todo || time_after(jiffies, end_time))
91253+ if (!todo || timedout)
91254 break;
91255
91256 if (pm_wakeup_pending()) {
91257diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
91258index ced2b84..ffc4791 100644
91259--- a/kernel/printk/printk.c
91260+++ b/kernel/printk/printk.c
91261@@ -489,6 +489,11 @@ static int check_syslog_permissions(int type, bool from_file)
91262 if (from_file && type != SYSLOG_ACTION_OPEN)
91263 return 0;
91264
91265+#ifdef CONFIG_GRKERNSEC_DMESG
91266+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
91267+ return -EPERM;
91268+#endif
91269+
91270 if (syslog_action_restricted(type)) {
91271 if (capable(CAP_SYSLOG))
91272 return 0;
91273diff --git a/kernel/profile.c b/kernel/profile.c
91274index 54bf5ba..df6e0a2 100644
91275--- a/kernel/profile.c
91276+++ b/kernel/profile.c
91277@@ -37,7 +37,7 @@ struct profile_hit {
91278 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
91279 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
91280
91281-static atomic_t *prof_buffer;
91282+static atomic_unchecked_t *prof_buffer;
91283 static unsigned long prof_len, prof_shift;
91284
91285 int prof_on __read_mostly;
91286@@ -256,7 +256,7 @@ static void profile_flip_buffers(void)
91287 hits[i].pc = 0;
91288 continue;
91289 }
91290- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
91291+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
91292 hits[i].hits = hits[i].pc = 0;
91293 }
91294 }
91295@@ -317,9 +317,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
91296 * Add the current hit(s) and flush the write-queue out
91297 * to the global buffer:
91298 */
91299- atomic_add(nr_hits, &prof_buffer[pc]);
91300+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
91301 for (i = 0; i < NR_PROFILE_HIT; ++i) {
91302- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
91303+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
91304 hits[i].pc = hits[i].hits = 0;
91305 }
91306 out:
91307@@ -394,7 +394,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
91308 {
91309 unsigned long pc;
91310 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
91311- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
91312+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
91313 }
91314 #endif /* !CONFIG_SMP */
91315
91316@@ -490,7 +490,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
91317 return -EFAULT;
91318 buf++; p++; count--; read++;
91319 }
91320- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
91321+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
91322 if (copy_to_user(buf, (void *)pnt, count))
91323 return -EFAULT;
91324 read += count;
91325@@ -521,7 +521,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
91326 }
91327 #endif
91328 profile_discard_flip_buffers();
91329- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
91330+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
91331 return count;
91332 }
91333
91334diff --git a/kernel/ptrace.c b/kernel/ptrace.c
91335index 54e7522..5b82dd6 100644
91336--- a/kernel/ptrace.c
91337+++ b/kernel/ptrace.c
91338@@ -321,7 +321,7 @@ static int ptrace_attach(struct task_struct *task, long request,
91339 if (seize)
91340 flags |= PT_SEIZED;
91341 rcu_read_lock();
91342- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
91343+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
91344 flags |= PT_PTRACE_CAP;
91345 rcu_read_unlock();
91346 task->ptrace = flags;
91347@@ -532,7 +532,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
91348 break;
91349 return -EIO;
91350 }
91351- if (copy_to_user(dst, buf, retval))
91352+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
91353 return -EFAULT;
91354 copied += retval;
91355 src += retval;
91356@@ -800,7 +800,7 @@ int ptrace_request(struct task_struct *child, long request,
91357 bool seized = child->ptrace & PT_SEIZED;
91358 int ret = -EIO;
91359 siginfo_t siginfo, *si;
91360- void __user *datavp = (void __user *) data;
91361+ void __user *datavp = (__force void __user *) data;
91362 unsigned long __user *datalp = datavp;
91363 unsigned long flags;
91364
91365@@ -1046,14 +1046,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
91366 goto out;
91367 }
91368
91369+ if (gr_handle_ptrace(child, request)) {
91370+ ret = -EPERM;
91371+ goto out_put_task_struct;
91372+ }
91373+
91374 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
91375 ret = ptrace_attach(child, request, addr, data);
91376 /*
91377 * Some architectures need to do book-keeping after
91378 * a ptrace attach.
91379 */
91380- if (!ret)
91381+ if (!ret) {
91382 arch_ptrace_attach(child);
91383+ gr_audit_ptrace(child);
91384+ }
91385 goto out_put_task_struct;
91386 }
91387
91388@@ -1081,7 +1088,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
91389 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
91390 if (copied != sizeof(tmp))
91391 return -EIO;
91392- return put_user(tmp, (unsigned long __user *)data);
91393+ return put_user(tmp, (__force unsigned long __user *)data);
91394 }
91395
91396 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
91397@@ -1175,7 +1182,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
91398 }
91399
91400 COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
91401- compat_long_t, addr, compat_long_t, data)
91402+ compat_ulong_t, addr, compat_ulong_t, data)
91403 {
91404 struct task_struct *child;
91405 long ret;
91406@@ -1191,14 +1198,21 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
91407 goto out;
91408 }
91409
91410+ if (gr_handle_ptrace(child, request)) {
91411+ ret = -EPERM;
91412+ goto out_put_task_struct;
91413+ }
91414+
91415 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
91416 ret = ptrace_attach(child, request, addr, data);
91417 /*
91418 * Some architectures need to do book-keeping after
91419 * a ptrace attach.
91420 */
91421- if (!ret)
91422+ if (!ret) {
91423 arch_ptrace_attach(child);
91424+ gr_audit_ptrace(child);
91425+ }
91426 goto out_put_task_struct;
91427 }
91428
91429diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
91430index 240fa90..5fa56bd 100644
91431--- a/kernel/rcu/rcutorture.c
91432+++ b/kernel/rcu/rcutorture.c
91433@@ -134,12 +134,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
91434 rcu_torture_count) = { 0 };
91435 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
91436 rcu_torture_batch) = { 0 };
91437-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
91438-static atomic_t n_rcu_torture_alloc;
91439-static atomic_t n_rcu_torture_alloc_fail;
91440-static atomic_t n_rcu_torture_free;
91441-static atomic_t n_rcu_torture_mberror;
91442-static atomic_t n_rcu_torture_error;
91443+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
91444+static atomic_unchecked_t n_rcu_torture_alloc;
91445+static atomic_unchecked_t n_rcu_torture_alloc_fail;
91446+static atomic_unchecked_t n_rcu_torture_free;
91447+static atomic_unchecked_t n_rcu_torture_mberror;
91448+static atomic_unchecked_t n_rcu_torture_error;
91449 static long n_rcu_torture_barrier_error;
91450 static long n_rcu_torture_boost_ktrerror;
91451 static long n_rcu_torture_boost_rterror;
91452@@ -148,7 +148,7 @@ static long n_rcu_torture_boosts;
91453 static long n_rcu_torture_timers;
91454 static long n_barrier_attempts;
91455 static long n_barrier_successes;
91456-static atomic_long_t n_cbfloods;
91457+static atomic_long_unchecked_t n_cbfloods;
91458 static struct list_head rcu_torture_removed;
91459
91460 static int rcu_torture_writer_state;
91461@@ -211,11 +211,11 @@ rcu_torture_alloc(void)
91462
91463 spin_lock_bh(&rcu_torture_lock);
91464 if (list_empty(&rcu_torture_freelist)) {
91465- atomic_inc(&n_rcu_torture_alloc_fail);
91466+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
91467 spin_unlock_bh(&rcu_torture_lock);
91468 return NULL;
91469 }
91470- atomic_inc(&n_rcu_torture_alloc);
91471+ atomic_inc_unchecked(&n_rcu_torture_alloc);
91472 p = rcu_torture_freelist.next;
91473 list_del_init(p);
91474 spin_unlock_bh(&rcu_torture_lock);
91475@@ -228,7 +228,7 @@ rcu_torture_alloc(void)
91476 static void
91477 rcu_torture_free(struct rcu_torture *p)
91478 {
91479- atomic_inc(&n_rcu_torture_free);
91480+ atomic_inc_unchecked(&n_rcu_torture_free);
91481 spin_lock_bh(&rcu_torture_lock);
91482 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
91483 spin_unlock_bh(&rcu_torture_lock);
91484@@ -312,7 +312,7 @@ rcu_torture_pipe_update_one(struct rcu_torture *rp)
91485 i = rp->rtort_pipe_count;
91486 if (i > RCU_TORTURE_PIPE_LEN)
91487 i = RCU_TORTURE_PIPE_LEN;
91488- atomic_inc(&rcu_torture_wcount[i]);
91489+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
91490 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
91491 rp->rtort_mbtest = 0;
91492 return true;
91493@@ -799,7 +799,7 @@ rcu_torture_cbflood(void *arg)
91494 VERBOSE_TOROUT_STRING("rcu_torture_cbflood task started");
91495 do {
91496 schedule_timeout_interruptible(cbflood_inter_holdoff);
91497- atomic_long_inc(&n_cbfloods);
91498+ atomic_long_inc_unchecked(&n_cbfloods);
91499 WARN_ON(signal_pending(current));
91500 for (i = 0; i < cbflood_n_burst; i++) {
91501 for (j = 0; j < cbflood_n_per_burst; j++) {
91502@@ -917,7 +917,7 @@ rcu_torture_writer(void *arg)
91503 i = old_rp->rtort_pipe_count;
91504 if (i > RCU_TORTURE_PIPE_LEN)
91505 i = RCU_TORTURE_PIPE_LEN;
91506- atomic_inc(&rcu_torture_wcount[i]);
91507+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
91508 old_rp->rtort_pipe_count++;
91509 switch (synctype[torture_random(&rand) % nsynctypes]) {
91510 case RTWS_DEF_FREE:
91511@@ -1035,7 +1035,7 @@ static void rcu_torture_timer(unsigned long unused)
91512 return;
91513 }
91514 if (p->rtort_mbtest == 0)
91515- atomic_inc(&n_rcu_torture_mberror);
91516+ atomic_inc_unchecked(&n_rcu_torture_mberror);
91517 spin_lock(&rand_lock);
91518 cur_ops->read_delay(&rand);
91519 n_rcu_torture_timers++;
91520@@ -1105,7 +1105,7 @@ rcu_torture_reader(void *arg)
91521 continue;
91522 }
91523 if (p->rtort_mbtest == 0)
91524- atomic_inc(&n_rcu_torture_mberror);
91525+ atomic_inc_unchecked(&n_rcu_torture_mberror);
91526 cur_ops->read_delay(&rand);
91527 preempt_disable();
91528 pipe_count = p->rtort_pipe_count;
91529@@ -1172,11 +1172,11 @@ rcu_torture_stats_print(void)
91530 rcu_torture_current,
91531 rcu_torture_current_version,
91532 list_empty(&rcu_torture_freelist),
91533- atomic_read(&n_rcu_torture_alloc),
91534- atomic_read(&n_rcu_torture_alloc_fail),
91535- atomic_read(&n_rcu_torture_free));
91536+ atomic_read_unchecked(&n_rcu_torture_alloc),
91537+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
91538+ atomic_read_unchecked(&n_rcu_torture_free));
91539 pr_cont("rtmbe: %d rtbke: %ld rtbre: %ld ",
91540- atomic_read(&n_rcu_torture_mberror),
91541+ atomic_read_unchecked(&n_rcu_torture_mberror),
91542 n_rcu_torture_boost_ktrerror,
91543 n_rcu_torture_boost_rterror);
91544 pr_cont("rtbf: %ld rtb: %ld nt: %ld ",
91545@@ -1188,17 +1188,17 @@ rcu_torture_stats_print(void)
91546 n_barrier_successes,
91547 n_barrier_attempts,
91548 n_rcu_torture_barrier_error);
91549- pr_cont("cbflood: %ld\n", atomic_long_read(&n_cbfloods));
91550+ pr_cont("cbflood: %ld\n", atomic_long_read_unchecked(&n_cbfloods));
91551
91552 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
91553- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
91554+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 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 i > 1) {
91560 pr_cont("%s", "!!! ");
91561- atomic_inc(&n_rcu_torture_error);
91562+ atomic_inc_unchecked(&n_rcu_torture_error);
91563 WARN_ON_ONCE(1);
91564 }
91565 pr_cont("Reader Pipe: ");
91566@@ -1215,7 +1215,7 @@ rcu_torture_stats_print(void)
91567 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
91568 pr_cont("Free-Block Circulation: ");
91569 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
91570- pr_cont(" %d", atomic_read(&rcu_torture_wcount[i]));
91571+ pr_cont(" %d", atomic_read_unchecked(&rcu_torture_wcount[i]));
91572 }
91573 pr_cont("\n");
91574
91575@@ -1559,7 +1559,7 @@ rcu_torture_cleanup(void)
91576
91577 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
91578
91579- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
91580+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
91581 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
91582 else if (torture_onoff_failures())
91583 rcu_torture_print_module_parms(cur_ops,
91584@@ -1684,18 +1684,18 @@ rcu_torture_init(void)
91585
91586 rcu_torture_current = NULL;
91587 rcu_torture_current_version = 0;
91588- atomic_set(&n_rcu_torture_alloc, 0);
91589- atomic_set(&n_rcu_torture_alloc_fail, 0);
91590- atomic_set(&n_rcu_torture_free, 0);
91591- atomic_set(&n_rcu_torture_mberror, 0);
91592- atomic_set(&n_rcu_torture_error, 0);
91593+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
91594+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
91595+ atomic_set_unchecked(&n_rcu_torture_free, 0);
91596+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
91597+ atomic_set_unchecked(&n_rcu_torture_error, 0);
91598 n_rcu_torture_barrier_error = 0;
91599 n_rcu_torture_boost_ktrerror = 0;
91600 n_rcu_torture_boost_rterror = 0;
91601 n_rcu_torture_boost_failure = 0;
91602 n_rcu_torture_boosts = 0;
91603 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
91604- atomic_set(&rcu_torture_wcount[i], 0);
91605+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
91606 for_each_possible_cpu(cpu) {
91607 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
91608 per_cpu(rcu_torture_count, cpu)[i] = 0;
91609diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
91610index c0623fc..329c091 100644
91611--- a/kernel/rcu/tiny.c
91612+++ b/kernel/rcu/tiny.c
91613@@ -42,7 +42,7 @@
91614 /* Forward declarations for tiny_plugin.h. */
91615 struct rcu_ctrlblk;
91616 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
91617-static void rcu_process_callbacks(struct softirq_action *unused);
91618+static void rcu_process_callbacks(void);
91619 static void __call_rcu(struct rcu_head *head,
91620 void (*func)(struct rcu_head *rcu),
91621 struct rcu_ctrlblk *rcp);
91622@@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
91623 false));
91624 }
91625
91626-static void rcu_process_callbacks(struct softirq_action *unused)
91627+static __latent_entropy void rcu_process_callbacks(void)
91628 {
91629 __rcu_process_callbacks(&rcu_sched_ctrlblk);
91630 __rcu_process_callbacks(&rcu_bh_ctrlblk);
91631diff --git a/kernel/rcu/tiny_plugin.h b/kernel/rcu/tiny_plugin.h
91632index 858c565..7efd915 100644
91633--- a/kernel/rcu/tiny_plugin.h
91634+++ b/kernel/rcu/tiny_plugin.h
91635@@ -152,17 +152,17 @@ static void check_cpu_stall(struct rcu_ctrlblk *rcp)
91636 dump_stack();
91637 }
91638 if (*rcp->curtail && ULONG_CMP_GE(j, js))
91639- ACCESS_ONCE(rcp->jiffies_stall) = jiffies +
91640+ ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies +
91641 3 * rcu_jiffies_till_stall_check() + 3;
91642 else if (ULONG_CMP_GE(j, js))
91643- ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91644+ ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91645 }
91646
91647 static void reset_cpu_stall_ticks(struct rcu_ctrlblk *rcp)
91648 {
91649 rcp->ticks_this_gp = 0;
91650 rcp->gp_start = jiffies;
91651- ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91652+ ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91653 }
91654
91655 static void check_cpu_stalls(void)
91656diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
91657index 9815447..2cdf92a 100644
91658--- a/kernel/rcu/tree.c
91659+++ b/kernel/rcu/tree.c
91660@@ -274,7 +274,7 @@ static void rcu_momentary_dyntick_idle(void)
91661 */
91662 rdtp = this_cpu_ptr(&rcu_dynticks);
91663 smp_mb__before_atomic(); /* Earlier stuff before QS. */
91664- atomic_add(2, &rdtp->dynticks); /* QS. */
91665+ atomic_add_unchecked(2, &rdtp->dynticks); /* QS. */
91666 smp_mb__after_atomic(); /* Later stuff after QS. */
91667 break;
91668 }
91669@@ -534,9 +534,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
91670 rcu_prepare_for_idle(smp_processor_id());
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 ordering with next sojourn. */
91676- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
91677+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
91678 rcu_dynticks_task_enter();
91679
91680 /*
91681@@ -656,10 +656,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
91682 {
91683 rcu_dynticks_task_exit();
91684 smp_mb__before_atomic(); /* Force ordering w/previous sojourn. */
91685- atomic_inc(&rdtp->dynticks);
91686+ atomic_inc_unchecked(&rdtp->dynticks);
91687 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
91688 smp_mb__after_atomic(); /* See above. */
91689- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
91690+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
91691 rcu_cleanup_after_idle(smp_processor_id());
91692 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
91693 if (!user && !is_idle_task(current)) {
91694@@ -780,14 +780,14 @@ void rcu_nmi_enter(void)
91695 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
91696
91697 if (rdtp->dynticks_nmi_nesting == 0 &&
91698- (atomic_read(&rdtp->dynticks) & 0x1))
91699+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
91700 return;
91701 rdtp->dynticks_nmi_nesting++;
91702 smp_mb__before_atomic(); /* Force delay from prior write. */
91703- atomic_inc(&rdtp->dynticks);
91704+ atomic_inc_unchecked(&rdtp->dynticks);
91705 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
91706 smp_mb__after_atomic(); /* See above. */
91707- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
91708+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
91709 }
91710
91711 /**
91712@@ -806,9 +806,9 @@ void rcu_nmi_exit(void)
91713 return;
91714 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
91715 smp_mb__before_atomic(); /* See above. */
91716- atomic_inc(&rdtp->dynticks);
91717+ atomic_inc_unchecked(&rdtp->dynticks);
91718 smp_mb__after_atomic(); /* Force delay to next write. */
91719- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
91720+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
91721 }
91722
91723 /**
91724@@ -821,7 +821,7 @@ void rcu_nmi_exit(void)
91725 */
91726 bool notrace __rcu_is_watching(void)
91727 {
91728- return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
91729+ return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
91730 }
91731
91732 /**
91733@@ -904,7 +904,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
91734 static int dyntick_save_progress_counter(struct rcu_data *rdp,
91735 bool *isidle, unsigned long *maxj)
91736 {
91737- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
91738+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
91739 rcu_sysidle_check_cpu(rdp, isidle, maxj);
91740 if ((rdp->dynticks_snap & 0x1) == 0) {
91741 trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, TPS("dti"));
91742@@ -933,7 +933,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
91743 int *rcrmp;
91744 unsigned int snap;
91745
91746- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
91747+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
91748 snap = (unsigned int)rdp->dynticks_snap;
91749
91750 /*
91751@@ -996,10 +996,10 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
91752 rdp->rsp->gp_start + jiffies_till_sched_qs) ||
91753 ULONG_CMP_GE(jiffies, rdp->rsp->jiffies_resched)) {
91754 if (!(ACCESS_ONCE(*rcrmp) & rdp->rsp->flavor_mask)) {
91755- ACCESS_ONCE(rdp->cond_resched_completed) =
91756+ ACCESS_ONCE_RW(rdp->cond_resched_completed) =
91757 ACCESS_ONCE(rdp->mynode->completed);
91758 smp_mb(); /* ->cond_resched_completed before *rcrmp. */
91759- ACCESS_ONCE(*rcrmp) =
91760+ ACCESS_ONCE_RW(*rcrmp) =
91761 ACCESS_ONCE(*rcrmp) + rdp->rsp->flavor_mask;
91762 resched_cpu(rdp->cpu); /* Force CPU into scheduler. */
91763 rdp->rsp->jiffies_resched += 5; /* Enable beating. */
91764@@ -1021,7 +1021,7 @@ static void record_gp_stall_check_time(struct rcu_state *rsp)
91765 rsp->gp_start = j;
91766 smp_wmb(); /* Record start time before stall time. */
91767 j1 = rcu_jiffies_till_stall_check();
91768- ACCESS_ONCE(rsp->jiffies_stall) = j + j1;
91769+ ACCESS_ONCE_RW(rsp->jiffies_stall) = j + j1;
91770 rsp->jiffies_resched = j + j1 / 2;
91771 }
91772
91773@@ -1062,7 +1062,7 @@ static void print_other_cpu_stall(struct rcu_state *rsp)
91774 raw_spin_unlock_irqrestore(&rnp->lock, flags);
91775 return;
91776 }
91777- ACCESS_ONCE(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
91778+ ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
91779 raw_spin_unlock_irqrestore(&rnp->lock, flags);
91780
91781 /*
91782@@ -1139,7 +1139,7 @@ static void print_cpu_stall(struct rcu_state *rsp)
91783
91784 raw_spin_lock_irqsave(&rnp->lock, flags);
91785 if (ULONG_CMP_GE(jiffies, ACCESS_ONCE(rsp->jiffies_stall)))
91786- ACCESS_ONCE(rsp->jiffies_stall) = jiffies +
91787+ ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies +
91788 3 * rcu_jiffies_till_stall_check() + 3;
91789 raw_spin_unlock_irqrestore(&rnp->lock, flags);
91790
91791@@ -1223,7 +1223,7 @@ void rcu_cpu_stall_reset(void)
91792 struct rcu_state *rsp;
91793
91794 for_each_rcu_flavor(rsp)
91795- ACCESS_ONCE(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
91796+ ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
91797 }
91798
91799 /*
91800@@ -1609,7 +1609,7 @@ static int rcu_gp_init(struct rcu_state *rsp)
91801 raw_spin_unlock_irq(&rnp->lock);
91802 return 0;
91803 }
91804- ACCESS_ONCE(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
91805+ ACCESS_ONCE_RW(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
91806
91807 if (WARN_ON_ONCE(rcu_gp_in_progress(rsp))) {
91808 /*
91809@@ -1650,9 +1650,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
91810 rdp = this_cpu_ptr(rsp->rda);
91811 rcu_preempt_check_blocked_tasks(rnp);
91812 rnp->qsmask = rnp->qsmaskinit;
91813- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
91814+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
91815 WARN_ON_ONCE(rnp->completed != rsp->completed);
91816- ACCESS_ONCE(rnp->completed) = rsp->completed;
91817+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
91818 if (rnp == rdp->mynode)
91819 (void)__note_gp_changes(rsp, rnp, rdp);
91820 rcu_preempt_boost_start_gp(rnp);
91821@@ -1697,7 +1697,7 @@ static int rcu_gp_fqs(struct rcu_state *rsp, int fqs_state_in)
91822 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
91823 raw_spin_lock_irq(&rnp->lock);
91824 smp_mb__after_unlock_lock();
91825- ACCESS_ONCE(rsp->gp_flags) =
91826+ ACCESS_ONCE_RW(rsp->gp_flags) =
91827 ACCESS_ONCE(rsp->gp_flags) & ~RCU_GP_FLAG_FQS;
91828 raw_spin_unlock_irq(&rnp->lock);
91829 }
91830@@ -1743,7 +1743,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
91831 rcu_for_each_node_breadth_first(rsp, rnp) {
91832 raw_spin_lock_irq(&rnp->lock);
91833 smp_mb__after_unlock_lock();
91834- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
91835+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
91836 rdp = this_cpu_ptr(rsp->rda);
91837 if (rnp == rdp->mynode)
91838 needgp = __note_gp_changes(rsp, rnp, rdp) || needgp;
91839@@ -1758,14 +1758,14 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
91840 rcu_nocb_gp_set(rnp, nocb);
91841
91842 /* Declare grace period done. */
91843- ACCESS_ONCE(rsp->completed) = rsp->gpnum;
91844+ ACCESS_ONCE_RW(rsp->completed) = rsp->gpnum;
91845 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
91846 rsp->fqs_state = RCU_GP_IDLE;
91847 rdp = this_cpu_ptr(rsp->rda);
91848 /* Advance CBs to reduce false positives below. */
91849 needgp = rcu_advance_cbs(rsp, rnp, rdp) || needgp;
91850 if (needgp || cpu_needs_another_gp(rsp, rdp)) {
91851- ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
91852+ ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
91853 trace_rcu_grace_period(rsp->name,
91854 ACCESS_ONCE(rsp->gpnum),
91855 TPS("newreq"));
91856@@ -1890,7 +1890,7 @@ rcu_start_gp_advanced(struct rcu_state *rsp, struct rcu_node *rnp,
91857 */
91858 return false;
91859 }
91860- ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
91861+ ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
91862 trace_rcu_grace_period(rsp->name, ACCESS_ONCE(rsp->gpnum),
91863 TPS("newreq"));
91864
91865@@ -2111,7 +2111,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
91866 rsp->qlen += rdp->qlen;
91867 rdp->n_cbs_orphaned += rdp->qlen;
91868 rdp->qlen_lazy = 0;
91869- ACCESS_ONCE(rdp->qlen) = 0;
91870+ ACCESS_ONCE_RW(rdp->qlen) = 0;
91871 }
91872
91873 /*
91874@@ -2356,7 +2356,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
91875 }
91876 smp_mb(); /* List handling before counting for rcu_barrier(). */
91877 rdp->qlen_lazy -= count_lazy;
91878- ACCESS_ONCE(rdp->qlen) = rdp->qlen - count;
91879+ ACCESS_ONCE_RW(rdp->qlen) = rdp->qlen - count;
91880 rdp->n_cbs_invoked += count;
91881
91882 /* Reinstate batch limit if we have worked down the excess. */
91883@@ -2519,7 +2519,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
91884 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
91885 return; /* Someone beat us to it. */
91886 }
91887- ACCESS_ONCE(rsp->gp_flags) =
91888+ ACCESS_ONCE_RW(rsp->gp_flags) =
91889 ACCESS_ONCE(rsp->gp_flags) | RCU_GP_FLAG_FQS;
91890 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
91891 rcu_gp_kthread_wake(rsp);
91892@@ -2565,7 +2565,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
91893 /*
91894 * Do RCU core processing for the current CPU.
91895 */
91896-static void rcu_process_callbacks(struct softirq_action *unused)
91897+static void rcu_process_callbacks(void)
91898 {
91899 struct rcu_state *rsp;
91900
91901@@ -2677,7 +2677,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
91902 WARN_ON_ONCE((unsigned long)head & 0x1); /* Misaligned rcu_head! */
91903 if (debug_rcu_head_queue(head)) {
91904 /* Probable double call_rcu(), so leak the callback. */
91905- ACCESS_ONCE(head->func) = rcu_leak_callback;
91906+ ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
91907 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
91908 return;
91909 }
91910@@ -2705,7 +2705,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
91911 local_irq_restore(flags);
91912 return;
91913 }
91914- ACCESS_ONCE(rdp->qlen) = rdp->qlen + 1;
91915+ ACCESS_ONCE_RW(rdp->qlen) = rdp->qlen + 1;
91916 if (lazy)
91917 rdp->qlen_lazy++;
91918 else
91919@@ -2975,11 +2975,11 @@ void synchronize_sched_expedited(void)
91920 * counter wrap on a 32-bit system. Quite a few more CPUs would of
91921 * course be required on a 64-bit system.
91922 */
91923- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
91924+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
91925 (ulong)atomic_long_read(&rsp->expedited_done) +
91926 ULONG_MAX / 8)) {
91927 synchronize_sched();
91928- atomic_long_inc(&rsp->expedited_wrap);
91929+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
91930 return;
91931 }
91932
91933@@ -2987,12 +2987,12 @@ void synchronize_sched_expedited(void)
91934 * Take a ticket. Note that atomic_inc_return() implies a
91935 * full memory barrier.
91936 */
91937- snap = atomic_long_inc_return(&rsp->expedited_start);
91938+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
91939 firstsnap = snap;
91940 if (!try_get_online_cpus()) {
91941 /* CPU hotplug operation in flight, fall back to normal GP. */
91942 wait_rcu_gp(call_rcu_sched);
91943- atomic_long_inc(&rsp->expedited_normal);
91944+ atomic_long_inc_unchecked(&rsp->expedited_normal);
91945 return;
91946 }
91947 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
91948@@ -3005,14 +3005,14 @@ void synchronize_sched_expedited(void)
91949 synchronize_sched_expedited_cpu_stop,
91950 NULL) == -EAGAIN) {
91951 put_online_cpus();
91952- atomic_long_inc(&rsp->expedited_tryfail);
91953+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
91954
91955 /* Check to see if someone else did our work for us. */
91956 s = atomic_long_read(&rsp->expedited_done);
91957 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
91958 /* ensure test happens before caller kfree */
91959 smp_mb__before_atomic(); /* ^^^ */
91960- atomic_long_inc(&rsp->expedited_workdone1);
91961+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
91962 return;
91963 }
91964
91965@@ -3021,7 +3021,7 @@ void synchronize_sched_expedited(void)
91966 udelay(trycount * num_online_cpus());
91967 } else {
91968 wait_rcu_gp(call_rcu_sched);
91969- atomic_long_inc(&rsp->expedited_normal);
91970+ atomic_long_inc_unchecked(&rsp->expedited_normal);
91971 return;
91972 }
91973
91974@@ -3030,7 +3030,7 @@ void synchronize_sched_expedited(void)
91975 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
91976 /* ensure test happens before caller kfree */
91977 smp_mb__before_atomic(); /* ^^^ */
91978- atomic_long_inc(&rsp->expedited_workdone2);
91979+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
91980 return;
91981 }
91982
91983@@ -3044,13 +3044,13 @@ void synchronize_sched_expedited(void)
91984 if (!try_get_online_cpus()) {
91985 /* CPU hotplug operation in flight, use normal GP. */
91986 wait_rcu_gp(call_rcu_sched);
91987- atomic_long_inc(&rsp->expedited_normal);
91988+ atomic_long_inc_unchecked(&rsp->expedited_normal);
91989 return;
91990 }
91991- snap = atomic_long_read(&rsp->expedited_start);
91992+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
91993 smp_mb(); /* ensure read is before try_stop_cpus(). */
91994 }
91995- atomic_long_inc(&rsp->expedited_stoppedcpus);
91996+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
91997
91998 /*
91999 * Everyone up to our most recent fetch is covered by our grace
92000@@ -3059,16 +3059,16 @@ void synchronize_sched_expedited(void)
92001 * than we did already did their update.
92002 */
92003 do {
92004- atomic_long_inc(&rsp->expedited_done_tries);
92005+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
92006 s = atomic_long_read(&rsp->expedited_done);
92007 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
92008 /* ensure test happens before caller kfree */
92009 smp_mb__before_atomic(); /* ^^^ */
92010- atomic_long_inc(&rsp->expedited_done_lost);
92011+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
92012 break;
92013 }
92014 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
92015- atomic_long_inc(&rsp->expedited_done_exit);
92016+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
92017
92018 put_online_cpus();
92019 }
92020@@ -3274,7 +3274,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
92021 * ACCESS_ONCE() to prevent the compiler from speculating
92022 * the increment to precede the early-exit check.
92023 */
92024- ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92025+ ACCESS_ONCE_RW(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92026 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
92027 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
92028 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
92029@@ -3329,7 +3329,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
92030
92031 /* Increment ->n_barrier_done to prevent duplicate work. */
92032 smp_mb(); /* Keep increment after above mechanism. */
92033- ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92034+ ACCESS_ONCE_RW(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92035 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
92036 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
92037 smp_mb(); /* Keep increment before caller's subsequent code. */
92038@@ -3374,10 +3374,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
92039 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
92040 init_callback_list(rdp);
92041 rdp->qlen_lazy = 0;
92042- ACCESS_ONCE(rdp->qlen) = 0;
92043+ ACCESS_ONCE_RW(rdp->qlen) = 0;
92044 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
92045 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
92046- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
92047+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
92048 rdp->cpu = cpu;
92049 rdp->rsp = rsp;
92050 rcu_boot_init_nocb_percpu_data(rdp);
92051@@ -3410,8 +3410,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp)
92052 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
92053 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
92054 rcu_sysidle_init_percpu_data(rdp->dynticks);
92055- atomic_set(&rdp->dynticks->dynticks,
92056- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
92057+ atomic_set_unchecked(&rdp->dynticks->dynticks,
92058+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
92059 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
92060
92061 /* Add CPU to rcu_node bitmasks. */
92062diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
92063index bbdc45d..c882ccb 100644
92064--- a/kernel/rcu/tree.h
92065+++ b/kernel/rcu/tree.h
92066@@ -87,11 +87,11 @@ struct rcu_dynticks {
92067 long long dynticks_nesting; /* Track irq/process nesting level. */
92068 /* Process level is worth LLONG_MAX/2. */
92069 int dynticks_nmi_nesting; /* Track NMI nesting level. */
92070- atomic_t dynticks; /* Even value for idle, else odd. */
92071+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
92072 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
92073 long long dynticks_idle_nesting;
92074 /* irq/process nesting level from idle. */
92075- atomic_t dynticks_idle; /* Even value for idle, else odd. */
92076+ atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
92077 /* "Idle" excludes userspace execution. */
92078 unsigned long dynticks_idle_jiffies;
92079 /* End of last non-NMI non-idle period. */
92080@@ -466,17 +466,17 @@ struct rcu_state {
92081 /* _rcu_barrier(). */
92082 /* End of fields guarded by barrier_mutex. */
92083
92084- atomic_long_t expedited_start; /* Starting ticket. */
92085- atomic_long_t expedited_done; /* Done ticket. */
92086- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
92087- atomic_long_t expedited_tryfail; /* # acquisition failures. */
92088- atomic_long_t expedited_workdone1; /* # done by others #1. */
92089- atomic_long_t expedited_workdone2; /* # done by others #2. */
92090- atomic_long_t expedited_normal; /* # fallbacks to normal. */
92091- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
92092- atomic_long_t expedited_done_tries; /* # tries to update _done. */
92093- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
92094- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
92095+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
92096+ atomic_long_t expedited_done; /* Done ticket. */
92097+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
92098+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
92099+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
92100+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
92101+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
92102+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
92103+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
92104+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
92105+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
92106
92107 unsigned long jiffies_force_qs; /* Time at which to invoke */
92108 /* force_quiescent_state(). */
92109diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
92110index c1d7f27..a64bf49 100644
92111--- a/kernel/rcu/tree_plugin.h
92112+++ b/kernel/rcu/tree_plugin.h
92113@@ -709,7 +709,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
92114 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
92115 {
92116 return !rcu_preempted_readers_exp(rnp) &&
92117- ACCESS_ONCE(rnp->expmask) == 0;
92118+ ACCESS_ONCE_RW(rnp->expmask) == 0;
92119 }
92120
92121 /*
92122@@ -870,7 +870,7 @@ void synchronize_rcu_expedited(void)
92123
92124 /* Clean up and exit. */
92125 smp_mb(); /* ensure expedited GP seen before counter increment. */
92126- ACCESS_ONCE(sync_rcu_preempt_exp_count) =
92127+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count) =
92128 sync_rcu_preempt_exp_count + 1;
92129 unlock_mb_ret:
92130 mutex_unlock(&sync_rcu_preempt_exp_mutex);
92131@@ -1426,7 +1426,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
92132 free_cpumask_var(cm);
92133 }
92134
92135-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
92136+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
92137 .store = &rcu_cpu_kthread_task,
92138 .thread_should_run = rcu_cpu_kthread_should_run,
92139 .thread_fn = rcu_cpu_kthread,
92140@@ -1900,7 +1900,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
92141 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
92142 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
92143 cpu, ticks_value, ticks_title,
92144- atomic_read(&rdtp->dynticks) & 0xfff,
92145+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
92146 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
92147 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
92148 fast_no_hz);
92149@@ -2044,7 +2044,7 @@ static void wake_nocb_leader(struct rcu_data *rdp, bool force)
92150 return;
92151 if (ACCESS_ONCE(rdp_leader->nocb_leader_sleep) || force) {
92152 /* Prior smp_mb__after_atomic() orders against prior enqueue. */
92153- ACCESS_ONCE(rdp_leader->nocb_leader_sleep) = false;
92154+ ACCESS_ONCE_RW(rdp_leader->nocb_leader_sleep) = false;
92155 wake_up(&rdp_leader->nocb_wq);
92156 }
92157 }
92158@@ -2096,7 +2096,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
92159
92160 /* Enqueue the callback on the nocb list and update counts. */
92161 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
92162- ACCESS_ONCE(*old_rhpp) = rhp;
92163+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
92164 atomic_long_add(rhcount, &rdp->nocb_q_count);
92165 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
92166 smp_mb__after_atomic(); /* Store *old_rhpp before _wake test. */
92167@@ -2286,7 +2286,7 @@ wait_again:
92168 continue; /* No CBs here, try next follower. */
92169
92170 /* Move callbacks to wait-for-GP list, which is empty. */
92171- ACCESS_ONCE(rdp->nocb_head) = NULL;
92172+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
92173 rdp->nocb_gp_tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
92174 rdp->nocb_gp_count = atomic_long_xchg(&rdp->nocb_q_count, 0);
92175 rdp->nocb_gp_count_lazy =
92176@@ -2413,7 +2413,7 @@ static int rcu_nocb_kthread(void *arg)
92177 list = ACCESS_ONCE(rdp->nocb_follower_head);
92178 BUG_ON(!list);
92179 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, "WokeNonEmpty");
92180- ACCESS_ONCE(rdp->nocb_follower_head) = NULL;
92181+ ACCESS_ONCE_RW(rdp->nocb_follower_head) = NULL;
92182 tail = xchg(&rdp->nocb_follower_tail, &rdp->nocb_follower_head);
92183 c = atomic_long_xchg(&rdp->nocb_follower_count, 0);
92184 cl = atomic_long_xchg(&rdp->nocb_follower_count_lazy, 0);
92185@@ -2443,8 +2443,8 @@ static int rcu_nocb_kthread(void *arg)
92186 list = next;
92187 }
92188 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
92189- ACCESS_ONCE(rdp->nocb_p_count) = rdp->nocb_p_count - c;
92190- ACCESS_ONCE(rdp->nocb_p_count_lazy) =
92191+ ACCESS_ONCE_RW(rdp->nocb_p_count) = rdp->nocb_p_count - c;
92192+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) =
92193 rdp->nocb_p_count_lazy - cl;
92194 rdp->n_nocbs_invoked += c;
92195 }
92196@@ -2465,7 +2465,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
92197 if (!rcu_nocb_need_deferred_wakeup(rdp))
92198 return;
92199 ndw = ACCESS_ONCE(rdp->nocb_defer_wakeup);
92200- ACCESS_ONCE(rdp->nocb_defer_wakeup) = RCU_NOGP_WAKE_NOT;
92201+ ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = RCU_NOGP_WAKE_NOT;
92202 wake_nocb_leader(rdp, ndw == RCU_NOGP_WAKE_FORCE);
92203 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWake"));
92204 }
92205@@ -2584,7 +2584,7 @@ static void rcu_spawn_one_nocb_kthread(struct rcu_state *rsp, int cpu)
92206 t = kthread_run(rcu_nocb_kthread, rdp_spawn,
92207 "rcuo%c/%d", rsp->abbr, cpu);
92208 BUG_ON(IS_ERR(t));
92209- ACCESS_ONCE(rdp_spawn->nocb_kthread) = t;
92210+ ACCESS_ONCE_RW(rdp_spawn->nocb_kthread) = t;
92211 }
92212
92213 /*
92214@@ -2788,11 +2788,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
92215
92216 /* Record start of fully idle period. */
92217 j = jiffies;
92218- ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
92219+ ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
92220 smp_mb__before_atomic();
92221- atomic_inc(&rdtp->dynticks_idle);
92222+ atomic_inc_unchecked(&rdtp->dynticks_idle);
92223 smp_mb__after_atomic();
92224- WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
92225+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
92226 }
92227
92228 /*
92229@@ -2861,9 +2861,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
92230
92231 /* Record end of idle period. */
92232 smp_mb__before_atomic();
92233- atomic_inc(&rdtp->dynticks_idle);
92234+ atomic_inc_unchecked(&rdtp->dynticks_idle);
92235 smp_mb__after_atomic();
92236- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
92237+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
92238
92239 /*
92240 * If we are the timekeeping CPU, we are permitted to be non-idle
92241@@ -2908,7 +2908,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
92242 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
92243
92244 /* Pick up current idle and NMI-nesting counter and check. */
92245- cur = atomic_read(&rdtp->dynticks_idle);
92246+ cur = atomic_read_unchecked(&rdtp->dynticks_idle);
92247 if (cur & 0x1) {
92248 *isidle = false; /* We are not idle! */
92249 return;
92250@@ -2957,7 +2957,7 @@ static void rcu_sysidle(unsigned long j)
92251 case RCU_SYSIDLE_NOT:
92252
92253 /* First time all are idle, so note a short idle period. */
92254- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
92255+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
92256 break;
92257
92258 case RCU_SYSIDLE_SHORT:
92259@@ -2995,7 +2995,7 @@ static void rcu_sysidle_cancel(void)
92260 {
92261 smp_mb();
92262 if (full_sysidle_state > RCU_SYSIDLE_SHORT)
92263- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
92264+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
92265 }
92266
92267 /*
92268@@ -3047,7 +3047,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
92269 smp_mb(); /* grace period precedes setting inuse. */
92270
92271 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
92272- ACCESS_ONCE(rshp->inuse) = 0;
92273+ ACCESS_ONCE_RW(rshp->inuse) = 0;
92274 }
92275
92276 /*
92277@@ -3200,7 +3200,7 @@ static void rcu_bind_gp_kthread(void)
92278 static void rcu_dynticks_task_enter(void)
92279 {
92280 #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL)
92281- ACCESS_ONCE(current->rcu_tasks_idle_cpu) = smp_processor_id();
92282+ ACCESS_ONCE_RW(current->rcu_tasks_idle_cpu) = smp_processor_id();
92283 #endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */
92284 }
92285
92286@@ -3208,6 +3208,6 @@ static void rcu_dynticks_task_enter(void)
92287 static void rcu_dynticks_task_exit(void)
92288 {
92289 #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL)
92290- ACCESS_ONCE(current->rcu_tasks_idle_cpu) = -1;
92291+ ACCESS_ONCE_RW(current->rcu_tasks_idle_cpu) = -1;
92292 #endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */
92293 }
92294diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
92295index 5cdc62e..cc52e88 100644
92296--- a/kernel/rcu/tree_trace.c
92297+++ b/kernel/rcu/tree_trace.c
92298@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
92299 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
92300 rdp->passed_quiesce, rdp->qs_pending);
92301 seq_printf(m, " dt=%d/%llx/%d df=%lu",
92302- atomic_read(&rdp->dynticks->dynticks),
92303+ atomic_read_unchecked(&rdp->dynticks->dynticks),
92304 rdp->dynticks->dynticks_nesting,
92305 rdp->dynticks->dynticks_nmi_nesting,
92306 rdp->dynticks_fqs);
92307@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
92308 struct rcu_state *rsp = (struct rcu_state *)m->private;
92309
92310 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",
92311- atomic_long_read(&rsp->expedited_start),
92312+ atomic_long_read_unchecked(&rsp->expedited_start),
92313 atomic_long_read(&rsp->expedited_done),
92314- atomic_long_read(&rsp->expedited_wrap),
92315- atomic_long_read(&rsp->expedited_tryfail),
92316- atomic_long_read(&rsp->expedited_workdone1),
92317- atomic_long_read(&rsp->expedited_workdone2),
92318- atomic_long_read(&rsp->expedited_normal),
92319- atomic_long_read(&rsp->expedited_stoppedcpus),
92320- atomic_long_read(&rsp->expedited_done_tries),
92321- atomic_long_read(&rsp->expedited_done_lost),
92322- atomic_long_read(&rsp->expedited_done_exit));
92323+ atomic_long_read_unchecked(&rsp->expedited_wrap),
92324+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
92325+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
92326+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
92327+ atomic_long_read_unchecked(&rsp->expedited_normal),
92328+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
92329+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
92330+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
92331+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
92332 return 0;
92333 }
92334
92335diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
92336index 3ef8ba5..8c5ebfb6 100644
92337--- a/kernel/rcu/update.c
92338+++ b/kernel/rcu/update.c
92339@@ -342,10 +342,10 @@ int rcu_jiffies_till_stall_check(void)
92340 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
92341 */
92342 if (till_stall_check < 3) {
92343- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
92344+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
92345 till_stall_check = 3;
92346 } else if (till_stall_check > 300) {
92347- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
92348+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
92349 till_stall_check = 300;
92350 }
92351 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
92352@@ -501,7 +501,7 @@ static void check_holdout_task(struct task_struct *t,
92353 !ACCESS_ONCE(t->on_rq) ||
92354 (IS_ENABLED(CONFIG_NO_HZ_FULL) &&
92355 !is_idle_task(t) && t->rcu_tasks_idle_cpu >= 0)) {
92356- ACCESS_ONCE(t->rcu_tasks_holdout) = false;
92357+ ACCESS_ONCE_RW(t->rcu_tasks_holdout) = false;
92358 list_del_init(&t->rcu_tasks_holdout_list);
92359 put_task_struct(t);
92360 return;
92361@@ -588,7 +588,7 @@ static int __noreturn rcu_tasks_kthread(void *arg)
92362 !is_idle_task(t)) {
92363 get_task_struct(t);
92364 t->rcu_tasks_nvcsw = ACCESS_ONCE(t->nvcsw);
92365- ACCESS_ONCE(t->rcu_tasks_holdout) = true;
92366+ ACCESS_ONCE_RW(t->rcu_tasks_holdout) = true;
92367 list_add(&t->rcu_tasks_holdout_list,
92368 &rcu_tasks_holdouts);
92369 }
92370@@ -685,7 +685,7 @@ static void rcu_spawn_tasks_kthread(void)
92371 t = kthread_run(rcu_tasks_kthread, NULL, "rcu_tasks_kthread");
92372 BUG_ON(IS_ERR(t));
92373 smp_mb(); /* Ensure others see full kthread. */
92374- ACCESS_ONCE(rcu_tasks_kthread_ptr) = t;
92375+ ACCESS_ONCE_RW(rcu_tasks_kthread_ptr) = t;
92376 mutex_unlock(&rcu_tasks_kthread_mutex);
92377 }
92378
92379diff --git a/kernel/resource.c b/kernel/resource.c
92380index 0bcebff..e7cd5b2 100644
92381--- a/kernel/resource.c
92382+++ b/kernel/resource.c
92383@@ -161,8 +161,18 @@ static const struct file_operations proc_iomem_operations = {
92384
92385 static int __init ioresources_init(void)
92386 {
92387+#ifdef CONFIG_GRKERNSEC_PROC_ADD
92388+#ifdef CONFIG_GRKERNSEC_PROC_USER
92389+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
92390+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
92391+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
92392+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
92393+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
92394+#endif
92395+#else
92396 proc_create("ioports", 0, NULL, &proc_ioports_operations);
92397 proc_create("iomem", 0, NULL, &proc_iomem_operations);
92398+#endif
92399 return 0;
92400 }
92401 __initcall(ioresources_init);
92402diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
92403index 8a2e230..6020954 100644
92404--- a/kernel/sched/auto_group.c
92405+++ b/kernel/sched/auto_group.c
92406@@ -11,7 +11,7 @@
92407
92408 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
92409 static struct autogroup autogroup_default;
92410-static atomic_t autogroup_seq_nr;
92411+static atomic_unchecked_t autogroup_seq_nr;
92412
92413 void __init autogroup_init(struct task_struct *init_task)
92414 {
92415@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
92416
92417 kref_init(&ag->kref);
92418 init_rwsem(&ag->lock);
92419- ag->id = atomic_inc_return(&autogroup_seq_nr);
92420+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
92421 ag->tg = tg;
92422 #ifdef CONFIG_RT_GROUP_SCHED
92423 /*
92424diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
92425index a63f4dc..349bbb0 100644
92426--- a/kernel/sched/completion.c
92427+++ b/kernel/sched/completion.c
92428@@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
92429 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
92430 * or number of jiffies left till timeout) if completed.
92431 */
92432-long __sched
92433+long __sched __intentional_overflow(-1)
92434 wait_for_completion_interruptible_timeout(struct completion *x,
92435 unsigned long timeout)
92436 {
92437@@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
92438 *
92439 * Return: -ERESTARTSYS if interrupted, 0 if completed.
92440 */
92441-int __sched wait_for_completion_killable(struct completion *x)
92442+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
92443 {
92444 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
92445 if (t == -ERESTARTSYS)
92446@@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
92447 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
92448 * or number of jiffies left till timeout) if completed.
92449 */
92450-long __sched
92451+long __sched __intentional_overflow(-1)
92452 wait_for_completion_killable_timeout(struct completion *x,
92453 unsigned long timeout)
92454 {
92455diff --git a/kernel/sched/core.c b/kernel/sched/core.c
92456index 89e7283..072bc26 100644
92457--- a/kernel/sched/core.c
92458+++ b/kernel/sched/core.c
92459@@ -1885,7 +1885,7 @@ void set_numabalancing_state(bool enabled)
92460 int sysctl_numa_balancing(struct ctl_table *table, int write,
92461 void __user *buffer, size_t *lenp, loff_t *ppos)
92462 {
92463- struct ctl_table t;
92464+ ctl_table_no_const t;
92465 int err;
92466 int state = numabalancing_enabled;
92467
92468@@ -2348,8 +2348,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
92469 next->active_mm = oldmm;
92470 atomic_inc(&oldmm->mm_count);
92471 enter_lazy_tlb(oldmm, next);
92472- } else
92473+ } else {
92474 switch_mm(oldmm, mm, next);
92475+ populate_stack();
92476+ }
92477
92478 if (!prev->mm) {
92479 prev->active_mm = NULL;
92480@@ -3160,6 +3162,8 @@ int can_nice(const struct task_struct *p, const int nice)
92481 /* convert nice value [19,-20] to rlimit style value [1,40] */
92482 int nice_rlim = nice_to_rlimit(nice);
92483
92484+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
92485+
92486 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
92487 capable(CAP_SYS_NICE));
92488 }
92489@@ -3186,7 +3190,8 @@ SYSCALL_DEFINE1(nice, int, increment)
92490 nice = task_nice(current) + increment;
92491
92492 nice = clamp_val(nice, MIN_NICE, MAX_NICE);
92493- if (increment < 0 && !can_nice(current, nice))
92494+ if (increment < 0 && (!can_nice(current, nice) ||
92495+ gr_handle_chroot_nice()))
92496 return -EPERM;
92497
92498 retval = security_task_setnice(current, nice);
92499@@ -3465,6 +3470,7 @@ recheck:
92500 if (policy != p->policy && !rlim_rtprio)
92501 return -EPERM;
92502
92503+ gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
92504 /* can't increase priority */
92505 if (attr->sched_priority > p->rt_priority &&
92506 attr->sched_priority > rlim_rtprio)
92507@@ -4885,6 +4891,7 @@ void idle_task_exit(void)
92508
92509 if (mm != &init_mm) {
92510 switch_mm(mm, &init_mm, current);
92511+ populate_stack();
92512 finish_arch_post_lock_switch();
92513 }
92514 mmdrop(mm);
92515@@ -4980,7 +4987,7 @@ static void migrate_tasks(unsigned int dead_cpu)
92516
92517 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
92518
92519-static struct ctl_table sd_ctl_dir[] = {
92520+static ctl_table_no_const sd_ctl_dir[] __read_only = {
92521 {
92522 .procname = "sched_domain",
92523 .mode = 0555,
92524@@ -4997,17 +5004,17 @@ static struct ctl_table sd_ctl_root[] = {
92525 {}
92526 };
92527
92528-static struct ctl_table *sd_alloc_ctl_entry(int n)
92529+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
92530 {
92531- struct ctl_table *entry =
92532+ ctl_table_no_const *entry =
92533 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
92534
92535 return entry;
92536 }
92537
92538-static void sd_free_ctl_entry(struct ctl_table **tablep)
92539+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
92540 {
92541- struct ctl_table *entry;
92542+ ctl_table_no_const *entry;
92543
92544 /*
92545 * In the intermediate directories, both the child directory and
92546@@ -5015,22 +5022,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
92547 * will always be set. In the lowest directory the names are
92548 * static strings and all have proc handlers.
92549 */
92550- for (entry = *tablep; entry->mode; entry++) {
92551- if (entry->child)
92552- sd_free_ctl_entry(&entry->child);
92553+ for (entry = tablep; entry->mode; entry++) {
92554+ if (entry->child) {
92555+ sd_free_ctl_entry(entry->child);
92556+ pax_open_kernel();
92557+ entry->child = NULL;
92558+ pax_close_kernel();
92559+ }
92560 if (entry->proc_handler == NULL)
92561 kfree(entry->procname);
92562 }
92563
92564- kfree(*tablep);
92565- *tablep = NULL;
92566+ kfree(tablep);
92567 }
92568
92569 static int min_load_idx = 0;
92570 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
92571
92572 static void
92573-set_table_entry(struct ctl_table *entry,
92574+set_table_entry(ctl_table_no_const *entry,
92575 const char *procname, void *data, int maxlen,
92576 umode_t mode, proc_handler *proc_handler,
92577 bool load_idx)
92578@@ -5050,7 +5060,7 @@ set_table_entry(struct ctl_table *entry,
92579 static struct ctl_table *
92580 sd_alloc_ctl_domain_table(struct sched_domain *sd)
92581 {
92582- struct ctl_table *table = sd_alloc_ctl_entry(14);
92583+ ctl_table_no_const *table = sd_alloc_ctl_entry(14);
92584
92585 if (table == NULL)
92586 return NULL;
92587@@ -5088,9 +5098,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
92588 return table;
92589 }
92590
92591-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
92592+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
92593 {
92594- struct ctl_table *entry, *table;
92595+ ctl_table_no_const *entry, *table;
92596 struct sched_domain *sd;
92597 int domain_num = 0, i;
92598 char buf[32];
92599@@ -5117,11 +5127,13 @@ static struct ctl_table_header *sd_sysctl_header;
92600 static void register_sched_domain_sysctl(void)
92601 {
92602 int i, cpu_num = num_possible_cpus();
92603- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
92604+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
92605 char buf[32];
92606
92607 WARN_ON(sd_ctl_dir[0].child);
92608+ pax_open_kernel();
92609 sd_ctl_dir[0].child = entry;
92610+ pax_close_kernel();
92611
92612 if (entry == NULL)
92613 return;
92614@@ -5144,8 +5156,12 @@ static void unregister_sched_domain_sysctl(void)
92615 if (sd_sysctl_header)
92616 unregister_sysctl_table(sd_sysctl_header);
92617 sd_sysctl_header = NULL;
92618- if (sd_ctl_dir[0].child)
92619- sd_free_ctl_entry(&sd_ctl_dir[0].child);
92620+ if (sd_ctl_dir[0].child) {
92621+ sd_free_ctl_entry(sd_ctl_dir[0].child);
92622+ pax_open_kernel();
92623+ sd_ctl_dir[0].child = NULL;
92624+ pax_close_kernel();
92625+ }
92626 }
92627 #else
92628 static void register_sched_domain_sysctl(void)
92629diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
92630index ef2b104..69961f6 100644
92631--- a/kernel/sched/fair.c
92632+++ b/kernel/sched/fair.c
92633@@ -1906,7 +1906,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
92634
92635 static void reset_ptenuma_scan(struct task_struct *p)
92636 {
92637- ACCESS_ONCE(p->mm->numa_scan_seq)++;
92638+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
92639 p->mm->numa_scan_offset = 0;
92640 }
92641
92642@@ -7465,7 +7465,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
92643 * run_rebalance_domains is triggered when needed from the scheduler tick.
92644 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
92645 */
92646-static void run_rebalance_domains(struct softirq_action *h)
92647+static __latent_entropy void run_rebalance_domains(void)
92648 {
92649 struct rq *this_rq = this_rq();
92650 enum cpu_idle_type idle = this_rq->idle_balance ?
92651diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
92652index 2df8ef0..aae070f 100644
92653--- a/kernel/sched/sched.h
92654+++ b/kernel/sched/sched.h
92655@@ -1140,7 +1140,7 @@ struct sched_class {
92656 #ifdef CONFIG_FAIR_GROUP_SCHED
92657 void (*task_move_group) (struct task_struct *p, int on_rq);
92658 #endif
92659-};
92660+} __do_const;
92661
92662 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
92663 {
92664diff --git a/kernel/signal.c b/kernel/signal.c
92665index 8f0876f..1153a5a 100644
92666--- a/kernel/signal.c
92667+++ b/kernel/signal.c
92668@@ -53,12 +53,12 @@ static struct kmem_cache *sigqueue_cachep;
92669
92670 int print_fatal_signals __read_mostly;
92671
92672-static void __user *sig_handler(struct task_struct *t, int sig)
92673+static __sighandler_t sig_handler(struct task_struct *t, int sig)
92674 {
92675 return t->sighand->action[sig - 1].sa.sa_handler;
92676 }
92677
92678-static int sig_handler_ignored(void __user *handler, int sig)
92679+static int sig_handler_ignored(__sighandler_t handler, int sig)
92680 {
92681 /* Is it explicitly or implicitly ignored? */
92682 return handler == SIG_IGN ||
92683@@ -67,7 +67,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
92684
92685 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
92686 {
92687- void __user *handler;
92688+ __sighandler_t handler;
92689
92690 handler = sig_handler(t, sig);
92691
92692@@ -372,6 +372,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
92693 atomic_inc(&user->sigpending);
92694 rcu_read_unlock();
92695
92696+ if (!override_rlimit)
92697+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
92698+
92699 if (override_rlimit ||
92700 atomic_read(&user->sigpending) <=
92701 task_rlimit(t, RLIMIT_SIGPENDING)) {
92702@@ -499,7 +502,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
92703
92704 int unhandled_signal(struct task_struct *tsk, int sig)
92705 {
92706- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
92707+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
92708 if (is_global_init(tsk))
92709 return 1;
92710 if (handler != SIG_IGN && handler != SIG_DFL)
92711@@ -793,6 +796,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
92712 }
92713 }
92714
92715+ /* allow glibc communication via tgkill to other threads in our
92716+ thread group */
92717+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
92718+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
92719+ && gr_handle_signal(t, sig))
92720+ return -EPERM;
92721+
92722 return security_task_kill(t, info, sig, 0);
92723 }
92724
92725@@ -1176,7 +1186,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
92726 return send_signal(sig, info, p, 1);
92727 }
92728
92729-static int
92730+int
92731 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
92732 {
92733 return send_signal(sig, info, t, 0);
92734@@ -1213,6 +1223,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
92735 unsigned long int flags;
92736 int ret, blocked, ignored;
92737 struct k_sigaction *action;
92738+ int is_unhandled = 0;
92739
92740 spin_lock_irqsave(&t->sighand->siglock, flags);
92741 action = &t->sighand->action[sig-1];
92742@@ -1227,9 +1238,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
92743 }
92744 if (action->sa.sa_handler == SIG_DFL)
92745 t->signal->flags &= ~SIGNAL_UNKILLABLE;
92746+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
92747+ is_unhandled = 1;
92748 ret = specific_send_sig_info(sig, info, t);
92749 spin_unlock_irqrestore(&t->sighand->siglock, flags);
92750
92751+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
92752+ normal operation */
92753+ if (is_unhandled) {
92754+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
92755+ gr_handle_crash(t, sig);
92756+ }
92757+
92758 return ret;
92759 }
92760
92761@@ -1300,8 +1320,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
92762 ret = check_kill_permission(sig, info, p);
92763 rcu_read_unlock();
92764
92765- if (!ret && sig)
92766+ if (!ret && sig) {
92767 ret = do_send_sig_info(sig, info, p, true);
92768+ if (!ret)
92769+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
92770+ }
92771
92772 return ret;
92773 }
92774@@ -2903,7 +2926,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
92775 int error = -ESRCH;
92776
92777 rcu_read_lock();
92778- p = find_task_by_vpid(pid);
92779+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
92780+ /* allow glibc communication via tgkill to other threads in our
92781+ thread group */
92782+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
92783+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
92784+ p = find_task_by_vpid_unrestricted(pid);
92785+ else
92786+#endif
92787+ p = find_task_by_vpid(pid);
92788 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
92789 error = check_kill_permission(sig, info, p);
92790 /*
92791@@ -3236,8 +3267,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
92792 }
92793 seg = get_fs();
92794 set_fs(KERNEL_DS);
92795- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
92796- (stack_t __force __user *) &uoss,
92797+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
92798+ (stack_t __force_user *) &uoss,
92799 compat_user_stack_pointer());
92800 set_fs(seg);
92801 if (ret >= 0 && uoss_ptr) {
92802diff --git a/kernel/smpboot.c b/kernel/smpboot.c
92803index eb89e18..a4e6792 100644
92804--- a/kernel/smpboot.c
92805+++ b/kernel/smpboot.c
92806@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
92807 }
92808 smpboot_unpark_thread(plug_thread, cpu);
92809 }
92810- list_add(&plug_thread->list, &hotplug_threads);
92811+ pax_list_add(&plug_thread->list, &hotplug_threads);
92812 out:
92813 mutex_unlock(&smpboot_threads_lock);
92814 return ret;
92815@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
92816 {
92817 get_online_cpus();
92818 mutex_lock(&smpboot_threads_lock);
92819- list_del(&plug_thread->list);
92820+ pax_list_del(&plug_thread->list);
92821 smpboot_destroy_threads(plug_thread);
92822 mutex_unlock(&smpboot_threads_lock);
92823 put_online_cpus();
92824diff --git a/kernel/softirq.c b/kernel/softirq.c
92825index 0699add..d365ad8 100644
92826--- a/kernel/softirq.c
92827+++ b/kernel/softirq.c
92828@@ -53,7 +53,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
92829 EXPORT_SYMBOL(irq_stat);
92830 #endif
92831
92832-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
92833+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
92834
92835 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
92836
92837@@ -266,7 +266,7 @@ restart:
92838 kstat_incr_softirqs_this_cpu(vec_nr);
92839
92840 trace_softirq_entry(vec_nr);
92841- h->action(h);
92842+ h->action();
92843 trace_softirq_exit(vec_nr);
92844 if (unlikely(prev_count != preempt_count())) {
92845 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
92846@@ -426,7 +426,7 @@ void __raise_softirq_irqoff(unsigned int nr)
92847 or_softirq_pending(1UL << nr);
92848 }
92849
92850-void open_softirq(int nr, void (*action)(struct softirq_action *))
92851+void __init open_softirq(int nr, void (*action)(void))
92852 {
92853 softirq_vec[nr].action = action;
92854 }
92855@@ -478,7 +478,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
92856 }
92857 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
92858
92859-static void tasklet_action(struct softirq_action *a)
92860+static void tasklet_action(void)
92861 {
92862 struct tasklet_struct *list;
92863
92864@@ -514,7 +514,7 @@ static void tasklet_action(struct softirq_action *a)
92865 }
92866 }
92867
92868-static void tasklet_hi_action(struct softirq_action *a)
92869+static __latent_entropy void tasklet_hi_action(void)
92870 {
92871 struct tasklet_struct *list;
92872
92873@@ -741,7 +741,7 @@ static struct notifier_block cpu_nfb = {
92874 .notifier_call = cpu_callback
92875 };
92876
92877-static struct smp_hotplug_thread softirq_threads = {
92878+static struct smp_hotplug_thread softirq_threads __read_only = {
92879 .store = &ksoftirqd,
92880 .thread_should_run = ksoftirqd_should_run,
92881 .thread_fn = run_ksoftirqd,
92882diff --git a/kernel/sys.c b/kernel/sys.c
92883index 1eaa2f0..d80d27c 100644
92884--- a/kernel/sys.c
92885+++ b/kernel/sys.c
92886@@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
92887 error = -EACCES;
92888 goto out;
92889 }
92890+
92891+ if (gr_handle_chroot_setpriority(p, niceval)) {
92892+ error = -EACCES;
92893+ goto out;
92894+ }
92895+
92896 no_nice = security_task_setnice(p, niceval);
92897 if (no_nice) {
92898 error = no_nice;
92899@@ -353,6 +359,20 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
92900 goto error;
92901 }
92902
92903+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
92904+ goto error;
92905+
92906+ if (!gid_eq(new->gid, old->gid)) {
92907+ /* make sure we generate a learn log for what will
92908+ end up being a role transition after a full-learning
92909+ policy is generated
92910+ CAP_SETGID is required to perform a transition
92911+ we may not log a CAP_SETGID check above, e.g.
92912+ in the case where new rgid = old egid
92913+ */
92914+ gr_learn_cap(current, new, CAP_SETGID);
92915+ }
92916+
92917 if (rgid != (gid_t) -1 ||
92918 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
92919 new->sgid = new->egid;
92920@@ -388,6 +408,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
92921 old = current_cred();
92922
92923 retval = -EPERM;
92924+
92925+ if (gr_check_group_change(kgid, kgid, kgid))
92926+ goto error;
92927+
92928 if (ns_capable(old->user_ns, CAP_SETGID))
92929 new->gid = new->egid = new->sgid = new->fsgid = kgid;
92930 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
92931@@ -405,7 +429,7 @@ error:
92932 /*
92933 * change the user struct in a credentials set to match the new UID
92934 */
92935-static int set_user(struct cred *new)
92936+int set_user(struct cred *new)
92937 {
92938 struct user_struct *new_user;
92939
92940@@ -485,7 +509,18 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
92941 goto error;
92942 }
92943
92944+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
92945+ goto error;
92946+
92947 if (!uid_eq(new->uid, old->uid)) {
92948+ /* make sure we generate a learn log for what will
92949+ end up being a role transition after a full-learning
92950+ policy is generated
92951+ CAP_SETUID is required to perform a transition
92952+ we may not log a CAP_SETUID check above, e.g.
92953+ in the case where new ruid = old euid
92954+ */
92955+ gr_learn_cap(current, new, CAP_SETUID);
92956 retval = set_user(new);
92957 if (retval < 0)
92958 goto error;
92959@@ -535,6 +570,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
92960 old = current_cred();
92961
92962 retval = -EPERM;
92963+
92964+ if (gr_check_crash_uid(kuid))
92965+ goto error;
92966+ if (gr_check_user_change(kuid, kuid, kuid))
92967+ goto error;
92968+
92969 if (ns_capable(old->user_ns, CAP_SETUID)) {
92970 new->suid = new->uid = kuid;
92971 if (!uid_eq(kuid, old->uid)) {
92972@@ -604,6 +645,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
92973 goto error;
92974 }
92975
92976+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
92977+ goto error;
92978+
92979 if (ruid != (uid_t) -1) {
92980 new->uid = kruid;
92981 if (!uid_eq(kruid, old->uid)) {
92982@@ -688,6 +732,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
92983 goto error;
92984 }
92985
92986+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
92987+ goto error;
92988+
92989 if (rgid != (gid_t) -1)
92990 new->gid = krgid;
92991 if (egid != (gid_t) -1)
92992@@ -752,12 +799,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
92993 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
92994 ns_capable(old->user_ns, CAP_SETUID)) {
92995 if (!uid_eq(kuid, old->fsuid)) {
92996+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
92997+ goto error;
92998+
92999 new->fsuid = kuid;
93000 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
93001 goto change_okay;
93002 }
93003 }
93004
93005+error:
93006 abort_creds(new);
93007 return old_fsuid;
93008
93009@@ -790,12 +841,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
93010 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
93011 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
93012 ns_capable(old->user_ns, CAP_SETGID)) {
93013+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
93014+ goto error;
93015+
93016 if (!gid_eq(kgid, old->fsgid)) {
93017 new->fsgid = kgid;
93018 goto change_okay;
93019 }
93020 }
93021
93022+error:
93023 abort_creds(new);
93024 return old_fsgid;
93025
93026@@ -1172,19 +1227,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
93027 return -EFAULT;
93028
93029 down_read(&uts_sem);
93030- error = __copy_to_user(&name->sysname, &utsname()->sysname,
93031+ error = __copy_to_user(name->sysname, &utsname()->sysname,
93032 __OLD_UTS_LEN);
93033 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
93034- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
93035+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
93036 __OLD_UTS_LEN);
93037 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
93038- error |= __copy_to_user(&name->release, &utsname()->release,
93039+ error |= __copy_to_user(name->release, &utsname()->release,
93040 __OLD_UTS_LEN);
93041 error |= __put_user(0, name->release + __OLD_UTS_LEN);
93042- error |= __copy_to_user(&name->version, &utsname()->version,
93043+ error |= __copy_to_user(name->version, &utsname()->version,
93044 __OLD_UTS_LEN);
93045 error |= __put_user(0, name->version + __OLD_UTS_LEN);
93046- error |= __copy_to_user(&name->machine, &utsname()->machine,
93047+ error |= __copy_to_user(name->machine, &utsname()->machine,
93048 __OLD_UTS_LEN);
93049 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
93050 up_read(&uts_sem);
93051@@ -1385,6 +1440,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
93052 */
93053 new_rlim->rlim_cur = 1;
93054 }
93055+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
93056+ is changed to a lower value. Since tasks can be created by the same
93057+ user in between this limit change and an execve by this task, force
93058+ a recheck only for this task by setting PF_NPROC_EXCEEDED
93059+ */
93060+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
93061+ tsk->flags |= PF_NPROC_EXCEEDED;
93062 }
93063 if (!retval) {
93064 if (old_rlim)
93065diff --git a/kernel/sysctl.c b/kernel/sysctl.c
93066index 15f2511..181b356 100644
93067--- a/kernel/sysctl.c
93068+++ b/kernel/sysctl.c
93069@@ -94,7 +94,6 @@
93070
93071
93072 #if defined(CONFIG_SYSCTL)
93073-
93074 /* External variables not in a header file. */
93075 extern int max_threads;
93076 extern int suid_dumpable;
93077@@ -115,19 +114,20 @@ extern int sysctl_nr_trim_pages;
93078
93079 /* Constants used for minimum and maximum */
93080 #ifdef CONFIG_LOCKUP_DETECTOR
93081-static int sixty = 60;
93082+static int sixty __read_only = 60;
93083 #endif
93084
93085-static int __maybe_unused neg_one = -1;
93086+static int __maybe_unused neg_one __read_only = -1;
93087
93088-static int zero;
93089-static int __maybe_unused one = 1;
93090-static int __maybe_unused two = 2;
93091-static int __maybe_unused four = 4;
93092-static unsigned long one_ul = 1;
93093-static int one_hundred = 100;
93094+static int zero __read_only = 0;
93095+static int __maybe_unused one __read_only = 1;
93096+static int __maybe_unused two __read_only = 2;
93097+static int __maybe_unused three __read_only = 3;
93098+static int __maybe_unused four __read_only = 4;
93099+static unsigned long one_ul __read_only = 1;
93100+static int one_hundred __read_only = 100;
93101 #ifdef CONFIG_PRINTK
93102-static int ten_thousand = 10000;
93103+static int ten_thousand __read_only = 10000;
93104 #endif
93105
93106 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
93107@@ -181,10 +181,8 @@ static int proc_taint(struct ctl_table *table, int write,
93108 void __user *buffer, size_t *lenp, loff_t *ppos);
93109 #endif
93110
93111-#ifdef CONFIG_PRINTK
93112 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93113 void __user *buffer, size_t *lenp, loff_t *ppos);
93114-#endif
93115
93116 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
93117 void __user *buffer, size_t *lenp, loff_t *ppos);
93118@@ -215,6 +213,8 @@ static int sysrq_sysctl_handler(struct ctl_table *table, int write,
93119
93120 #endif
93121
93122+extern struct ctl_table grsecurity_table[];
93123+
93124 static struct ctl_table kern_table[];
93125 static struct ctl_table vm_table[];
93126 static struct ctl_table fs_table[];
93127@@ -229,6 +229,20 @@ extern struct ctl_table epoll_table[];
93128 int sysctl_legacy_va_layout;
93129 #endif
93130
93131+#ifdef CONFIG_PAX_SOFTMODE
93132+static struct ctl_table pax_table[] = {
93133+ {
93134+ .procname = "softmode",
93135+ .data = &pax_softmode,
93136+ .maxlen = sizeof(unsigned int),
93137+ .mode = 0600,
93138+ .proc_handler = &proc_dointvec,
93139+ },
93140+
93141+ { }
93142+};
93143+#endif
93144+
93145 /* The default sysctl tables: */
93146
93147 static struct ctl_table sysctl_base_table[] = {
93148@@ -277,6 +291,22 @@ static int max_extfrag_threshold = 1000;
93149 #endif
93150
93151 static struct ctl_table kern_table[] = {
93152+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
93153+ {
93154+ .procname = "grsecurity",
93155+ .mode = 0500,
93156+ .child = grsecurity_table,
93157+ },
93158+#endif
93159+
93160+#ifdef CONFIG_PAX_SOFTMODE
93161+ {
93162+ .procname = "pax",
93163+ .mode = 0500,
93164+ .child = pax_table,
93165+ },
93166+#endif
93167+
93168 {
93169 .procname = "sched_child_runs_first",
93170 .data = &sysctl_sched_child_runs_first,
93171@@ -642,7 +672,7 @@ static struct ctl_table kern_table[] = {
93172 .data = &modprobe_path,
93173 .maxlen = KMOD_PATH_LEN,
93174 .mode = 0644,
93175- .proc_handler = proc_dostring,
93176+ .proc_handler = proc_dostring_modpriv,
93177 },
93178 {
93179 .procname = "modules_disabled",
93180@@ -809,16 +839,20 @@ static struct ctl_table kern_table[] = {
93181 .extra1 = &zero,
93182 .extra2 = &one,
93183 },
93184+#endif
93185 {
93186 .procname = "kptr_restrict",
93187 .data = &kptr_restrict,
93188 .maxlen = sizeof(int),
93189 .mode = 0644,
93190 .proc_handler = proc_dointvec_minmax_sysadmin,
93191+#ifdef CONFIG_GRKERNSEC_HIDESYM
93192+ .extra1 = &two,
93193+#else
93194 .extra1 = &zero,
93195+#endif
93196 .extra2 = &two,
93197 },
93198-#endif
93199 {
93200 .procname = "ngroups_max",
93201 .data = &ngroups_max,
93202@@ -1065,10 +1099,17 @@ static struct ctl_table kern_table[] = {
93203 */
93204 {
93205 .procname = "perf_event_paranoid",
93206- .data = &sysctl_perf_event_paranoid,
93207- .maxlen = sizeof(sysctl_perf_event_paranoid),
93208+ .data = &sysctl_perf_event_legitimately_concerned,
93209+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
93210 .mode = 0644,
93211- .proc_handler = proc_dointvec,
93212+ /* go ahead, be a hero */
93213+ .proc_handler = proc_dointvec_minmax_sysadmin,
93214+ .extra1 = &neg_one,
93215+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
93216+ .extra2 = &three,
93217+#else
93218+ .extra2 = &two,
93219+#endif
93220 },
93221 {
93222 .procname = "perf_event_mlock_kb",
93223@@ -1327,6 +1368,13 @@ static struct ctl_table vm_table[] = {
93224 .proc_handler = proc_dointvec_minmax,
93225 .extra1 = &zero,
93226 },
93227+ {
93228+ .procname = "heap_stack_gap",
93229+ .data = &sysctl_heap_stack_gap,
93230+ .maxlen = sizeof(sysctl_heap_stack_gap),
93231+ .mode = 0644,
93232+ .proc_handler = proc_doulongvec_minmax,
93233+ },
93234 #else
93235 {
93236 .procname = "nr_trim_pages",
93237@@ -1809,6 +1857,16 @@ int proc_dostring(struct ctl_table *table, int write,
93238 (char __user *)buffer, lenp, ppos);
93239 }
93240
93241+int proc_dostring_modpriv(struct ctl_table *table, int write,
93242+ void __user *buffer, size_t *lenp, loff_t *ppos)
93243+{
93244+ if (write && !capable(CAP_SYS_MODULE))
93245+ return -EPERM;
93246+
93247+ return _proc_do_string(table->data, table->maxlen, write,
93248+ buffer, lenp, ppos);
93249+}
93250+
93251 static size_t proc_skip_spaces(char **buf)
93252 {
93253 size_t ret;
93254@@ -1914,6 +1972,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
93255 len = strlen(tmp);
93256 if (len > *size)
93257 len = *size;
93258+ if (len > sizeof(tmp))
93259+ len = sizeof(tmp);
93260 if (copy_to_user(*buf, tmp, len))
93261 return -EFAULT;
93262 *size -= len;
93263@@ -2091,7 +2151,7 @@ int proc_dointvec(struct ctl_table *table, int write,
93264 static int proc_taint(struct ctl_table *table, int write,
93265 void __user *buffer, size_t *lenp, loff_t *ppos)
93266 {
93267- struct ctl_table t;
93268+ ctl_table_no_const t;
93269 unsigned long tmptaint = get_taint();
93270 int err;
93271
93272@@ -2119,7 +2179,6 @@ static int proc_taint(struct ctl_table *table, int write,
93273 return err;
93274 }
93275
93276-#ifdef CONFIG_PRINTK
93277 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93278 void __user *buffer, size_t *lenp, loff_t *ppos)
93279 {
93280@@ -2128,7 +2187,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93281
93282 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
93283 }
93284-#endif
93285
93286 struct do_proc_dointvec_minmax_conv_param {
93287 int *min;
93288@@ -2688,6 +2746,12 @@ int proc_dostring(struct ctl_table *table, int write,
93289 return -ENOSYS;
93290 }
93291
93292+int proc_dostring_modpriv(struct ctl_table *table, int write,
93293+ void __user *buffer, size_t *lenp, loff_t *ppos)
93294+{
93295+ return -ENOSYS;
93296+}
93297+
93298 int proc_dointvec(struct ctl_table *table, int write,
93299 void __user *buffer, size_t *lenp, loff_t *ppos)
93300 {
93301@@ -2744,5 +2808,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
93302 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
93303 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
93304 EXPORT_SYMBOL(proc_dostring);
93305+EXPORT_SYMBOL(proc_dostring_modpriv);
93306 EXPORT_SYMBOL(proc_doulongvec_minmax);
93307 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
93308diff --git a/kernel/taskstats.c b/kernel/taskstats.c
93309index b312fcc7..753d72d 100644
93310--- a/kernel/taskstats.c
93311+++ b/kernel/taskstats.c
93312@@ -28,9 +28,12 @@
93313 #include <linux/fs.h>
93314 #include <linux/file.h>
93315 #include <linux/pid_namespace.h>
93316+#include <linux/grsecurity.h>
93317 #include <net/genetlink.h>
93318 #include <linux/atomic.h>
93319
93320+extern int gr_is_taskstats_denied(int pid);
93321+
93322 /*
93323 * Maximum length of a cpumask that can be specified in
93324 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
93325@@ -576,6 +579,9 @@ err:
93326
93327 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
93328 {
93329+ if (gr_is_taskstats_denied(current->pid))
93330+ return -EACCES;
93331+
93332 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
93333 return cmd_attr_register_cpumask(info);
93334 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
93335diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
93336index a7077d3..dd48a49 100644
93337--- a/kernel/time/alarmtimer.c
93338+++ b/kernel/time/alarmtimer.c
93339@@ -823,7 +823,7 @@ static int __init alarmtimer_init(void)
93340 struct platform_device *pdev;
93341 int error = 0;
93342 int i;
93343- struct k_clock alarm_clock = {
93344+ static struct k_clock alarm_clock = {
93345 .clock_getres = alarm_clock_getres,
93346 .clock_get = alarm_clock_get,
93347 .timer_create = alarm_timer_create,
93348diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
93349index 37e50aa..57a9501 100644
93350--- a/kernel/time/hrtimer.c
93351+++ b/kernel/time/hrtimer.c
93352@@ -1399,7 +1399,7 @@ void hrtimer_peek_ahead_timers(void)
93353 local_irq_restore(flags);
93354 }
93355
93356-static void run_hrtimer_softirq(struct softirq_action *h)
93357+static __latent_entropy void run_hrtimer_softirq(void)
93358 {
93359 hrtimer_peek_ahead_timers();
93360 }
93361diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
93362index a16b678..8c5bd9d 100644
93363--- a/kernel/time/posix-cpu-timers.c
93364+++ b/kernel/time/posix-cpu-timers.c
93365@@ -1450,14 +1450,14 @@ struct k_clock clock_posix_cpu = {
93366
93367 static __init int init_posix_cpu_timers(void)
93368 {
93369- struct k_clock process = {
93370+ static struct k_clock process = {
93371 .clock_getres = process_cpu_clock_getres,
93372 .clock_get = process_cpu_clock_get,
93373 .timer_create = process_cpu_timer_create,
93374 .nsleep = process_cpu_nsleep,
93375 .nsleep_restart = process_cpu_nsleep_restart,
93376 };
93377- struct k_clock thread = {
93378+ static struct k_clock thread = {
93379 .clock_getres = thread_cpu_clock_getres,
93380 .clock_get = thread_cpu_clock_get,
93381 .timer_create = thread_cpu_timer_create,
93382diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
93383index 31ea01f..7fc61ef 100644
93384--- a/kernel/time/posix-timers.c
93385+++ b/kernel/time/posix-timers.c
93386@@ -43,6 +43,7 @@
93387 #include <linux/hash.h>
93388 #include <linux/posix-clock.h>
93389 #include <linux/posix-timers.h>
93390+#include <linux/grsecurity.h>
93391 #include <linux/syscalls.h>
93392 #include <linux/wait.h>
93393 #include <linux/workqueue.h>
93394@@ -124,7 +125,7 @@ static DEFINE_SPINLOCK(hash_lock);
93395 * which we beg off on and pass to do_sys_settimeofday().
93396 */
93397
93398-static struct k_clock posix_clocks[MAX_CLOCKS];
93399+static struct k_clock *posix_clocks[MAX_CLOCKS];
93400
93401 /*
93402 * These ones are defined below.
93403@@ -277,7 +278,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
93404 */
93405 static __init int init_posix_timers(void)
93406 {
93407- struct k_clock clock_realtime = {
93408+ static struct k_clock clock_realtime = {
93409 .clock_getres = hrtimer_get_res,
93410 .clock_get = posix_clock_realtime_get,
93411 .clock_set = posix_clock_realtime_set,
93412@@ -289,7 +290,7 @@ static __init int init_posix_timers(void)
93413 .timer_get = common_timer_get,
93414 .timer_del = common_timer_del,
93415 };
93416- struct k_clock clock_monotonic = {
93417+ static struct k_clock clock_monotonic = {
93418 .clock_getres = hrtimer_get_res,
93419 .clock_get = posix_ktime_get_ts,
93420 .nsleep = common_nsleep,
93421@@ -299,19 +300,19 @@ static __init int init_posix_timers(void)
93422 .timer_get = common_timer_get,
93423 .timer_del = common_timer_del,
93424 };
93425- struct k_clock clock_monotonic_raw = {
93426+ static struct k_clock clock_monotonic_raw = {
93427 .clock_getres = hrtimer_get_res,
93428 .clock_get = posix_get_monotonic_raw,
93429 };
93430- struct k_clock clock_realtime_coarse = {
93431+ static struct k_clock clock_realtime_coarse = {
93432 .clock_getres = posix_get_coarse_res,
93433 .clock_get = posix_get_realtime_coarse,
93434 };
93435- struct k_clock clock_monotonic_coarse = {
93436+ static struct k_clock clock_monotonic_coarse = {
93437 .clock_getres = posix_get_coarse_res,
93438 .clock_get = posix_get_monotonic_coarse,
93439 };
93440- struct k_clock clock_tai = {
93441+ static struct k_clock clock_tai = {
93442 .clock_getres = hrtimer_get_res,
93443 .clock_get = posix_get_tai,
93444 .nsleep = common_nsleep,
93445@@ -321,7 +322,7 @@ static __init int init_posix_timers(void)
93446 .timer_get = common_timer_get,
93447 .timer_del = common_timer_del,
93448 };
93449- struct k_clock clock_boottime = {
93450+ static struct k_clock clock_boottime = {
93451 .clock_getres = hrtimer_get_res,
93452 .clock_get = posix_get_boottime,
93453 .nsleep = common_nsleep,
93454@@ -533,7 +534,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
93455 return;
93456 }
93457
93458- posix_clocks[clock_id] = *new_clock;
93459+ posix_clocks[clock_id] = new_clock;
93460 }
93461 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
93462
93463@@ -579,9 +580,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
93464 return (id & CLOCKFD_MASK) == CLOCKFD ?
93465 &clock_posix_dynamic : &clock_posix_cpu;
93466
93467- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
93468+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
93469 return NULL;
93470- return &posix_clocks[id];
93471+ return posix_clocks[id];
93472 }
93473
93474 static int common_timer_create(struct k_itimer *new_timer)
93475@@ -599,7 +600,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
93476 struct k_clock *kc = clockid_to_kclock(which_clock);
93477 struct k_itimer *new_timer;
93478 int error, new_timer_id;
93479- sigevent_t event;
93480+ sigevent_t event = { };
93481 int it_id_set = IT_ID_NOT_SET;
93482
93483 if (!kc)
93484@@ -1014,6 +1015,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
93485 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
93486 return -EFAULT;
93487
93488+ /* only the CLOCK_REALTIME clock can be set, all other clocks
93489+ have their clock_set fptr set to a nosettime dummy function
93490+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
93491+ call common_clock_set, which calls do_sys_settimeofday, which
93492+ we hook
93493+ */
93494+
93495 return kc->clock_set(which_clock, &new_tp);
93496 }
93497
93498diff --git a/kernel/time/time.c b/kernel/time/time.c
93499index a9ae20f..d3fbde7 100644
93500--- a/kernel/time/time.c
93501+++ b/kernel/time/time.c
93502@@ -173,6 +173,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
93503 return error;
93504
93505 if (tz) {
93506+ /* we log in do_settimeofday called below, so don't log twice
93507+ */
93508+ if (!tv)
93509+ gr_log_timechange();
93510+
93511 sys_tz = *tz;
93512 update_vsyscall_tz();
93513 if (firsttime) {
93514diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
93515index ec1791f..6a086cd 100644
93516--- a/kernel/time/timekeeping.c
93517+++ b/kernel/time/timekeeping.c
93518@@ -15,6 +15,7 @@
93519 #include <linux/init.h>
93520 #include <linux/mm.h>
93521 #include <linux/sched.h>
93522+#include <linux/grsecurity.h>
93523 #include <linux/syscore_ops.h>
93524 #include <linux/clocksource.h>
93525 #include <linux/jiffies.h>
93526@@ -717,6 +718,8 @@ int do_settimeofday(const struct timespec *tv)
93527 if (!timespec_valid_strict(tv))
93528 return -EINVAL;
93529
93530+ gr_log_timechange();
93531+
93532 raw_spin_lock_irqsave(&timekeeper_lock, flags);
93533 write_seqcount_begin(&tk_core.seq);
93534
93535diff --git a/kernel/time/timer.c b/kernel/time/timer.c
93536index 3260ffd..c93cd5e 100644
93537--- a/kernel/time/timer.c
93538+++ b/kernel/time/timer.c
93539@@ -1394,7 +1394,7 @@ void update_process_times(int user_tick)
93540 /*
93541 * This function runs timers and the timer-tq in bottom half context.
93542 */
93543-static void run_timer_softirq(struct softirq_action *h)
93544+static __latent_entropy void run_timer_softirq(void)
93545 {
93546 struct tvec_base *base = __this_cpu_read(tvec_bases);
93547
93548@@ -1457,7 +1457,7 @@ static void process_timeout(unsigned long __data)
93549 *
93550 * In all cases the return value is guaranteed to be non-negative.
93551 */
93552-signed long __sched schedule_timeout(signed long timeout)
93553+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
93554 {
93555 struct timer_list timer;
93556 unsigned long expire;
93557diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
93558index 61ed862..3b52c65 100644
93559--- a/kernel/time/timer_list.c
93560+++ b/kernel/time/timer_list.c
93561@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
93562
93563 static void print_name_offset(struct seq_file *m, void *sym)
93564 {
93565+#ifdef CONFIG_GRKERNSEC_HIDESYM
93566+ SEQ_printf(m, "<%p>", NULL);
93567+#else
93568 char symname[KSYM_NAME_LEN];
93569
93570 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
93571 SEQ_printf(m, "<%pK>", sym);
93572 else
93573 SEQ_printf(m, "%s", symname);
93574+#endif
93575 }
93576
93577 static void
93578@@ -119,7 +123,11 @@ next_one:
93579 static void
93580 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
93581 {
93582+#ifdef CONFIG_GRKERNSEC_HIDESYM
93583+ SEQ_printf(m, " .base: %p\n", NULL);
93584+#else
93585 SEQ_printf(m, " .base: %pK\n", base);
93586+#endif
93587 SEQ_printf(m, " .index: %d\n",
93588 base->index);
93589 SEQ_printf(m, " .resolution: %Lu nsecs\n",
93590@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
93591 {
93592 struct proc_dir_entry *pe;
93593
93594+#ifdef CONFIG_GRKERNSEC_PROC_ADD
93595+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
93596+#else
93597 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
93598+#endif
93599 if (!pe)
93600 return -ENOMEM;
93601 return 0;
93602diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
93603index 1fb08f2..ca4bb1e 100644
93604--- a/kernel/time/timer_stats.c
93605+++ b/kernel/time/timer_stats.c
93606@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
93607 static unsigned long nr_entries;
93608 static struct entry entries[MAX_ENTRIES];
93609
93610-static atomic_t overflow_count;
93611+static atomic_unchecked_t overflow_count;
93612
93613 /*
93614 * The entries are in a hash-table, for fast lookup:
93615@@ -140,7 +140,7 @@ static void reset_entries(void)
93616 nr_entries = 0;
93617 memset(entries, 0, sizeof(entries));
93618 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
93619- atomic_set(&overflow_count, 0);
93620+ atomic_set_unchecked(&overflow_count, 0);
93621 }
93622
93623 static struct entry *alloc_entry(void)
93624@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
93625 if (likely(entry))
93626 entry->count++;
93627 else
93628- atomic_inc(&overflow_count);
93629+ atomic_inc_unchecked(&overflow_count);
93630
93631 out_unlock:
93632 raw_spin_unlock_irqrestore(lock, flags);
93633@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
93634
93635 static void print_name_offset(struct seq_file *m, unsigned long addr)
93636 {
93637+#ifdef CONFIG_GRKERNSEC_HIDESYM
93638+ seq_printf(m, "<%p>", NULL);
93639+#else
93640 char symname[KSYM_NAME_LEN];
93641
93642 if (lookup_symbol_name(addr, symname) < 0)
93643- seq_printf(m, "<%p>", (void *)addr);
93644+ seq_printf(m, "<%pK>", (void *)addr);
93645 else
93646 seq_printf(m, "%s", symname);
93647+#endif
93648 }
93649
93650 static int tstats_show(struct seq_file *m, void *v)
93651@@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
93652
93653 seq_puts(m, "Timer Stats Version: v0.3\n");
93654 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
93655- if (atomic_read(&overflow_count))
93656- seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
93657+ if (atomic_read_unchecked(&overflow_count))
93658+ seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
93659 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
93660
93661 for (i = 0; i < nr_entries; i++) {
93662@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
93663 {
93664 struct proc_dir_entry *pe;
93665
93666+#ifdef CONFIG_GRKERNSEC_PROC_ADD
93667+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
93668+#else
93669 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
93670+#endif
93671 if (!pe)
93672 return -ENOMEM;
93673 return 0;
93674diff --git a/kernel/torture.c b/kernel/torture.c
93675index dd70993..0bf694b 100644
93676--- a/kernel/torture.c
93677+++ b/kernel/torture.c
93678@@ -482,7 +482,7 @@ static int torture_shutdown_notify(struct notifier_block *unused1,
93679 mutex_lock(&fullstop_mutex);
93680 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
93681 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
93682- ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN;
93683+ ACCESS_ONCE_RW(fullstop) = FULLSTOP_SHUTDOWN;
93684 } else {
93685 pr_warn("Concurrent rmmod and shutdown illegal!\n");
93686 }
93687@@ -549,14 +549,14 @@ static int torture_stutter(void *arg)
93688 if (!torture_must_stop()) {
93689 if (stutter > 1) {
93690 schedule_timeout_interruptible(stutter - 1);
93691- ACCESS_ONCE(stutter_pause_test) = 2;
93692+ ACCESS_ONCE_RW(stutter_pause_test) = 2;
93693 }
93694 schedule_timeout_interruptible(1);
93695- ACCESS_ONCE(stutter_pause_test) = 1;
93696+ ACCESS_ONCE_RW(stutter_pause_test) = 1;
93697 }
93698 if (!torture_must_stop())
93699 schedule_timeout_interruptible(stutter);
93700- ACCESS_ONCE(stutter_pause_test) = 0;
93701+ ACCESS_ONCE_RW(stutter_pause_test) = 0;
93702 torture_shutdown_absorb("torture_stutter");
93703 } while (!torture_must_stop());
93704 torture_kthread_stopping("torture_stutter");
93705@@ -648,7 +648,7 @@ bool torture_cleanup_begin(void)
93706 schedule_timeout_uninterruptible(10);
93707 return true;
93708 }
93709- ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD;
93710+ ACCESS_ONCE_RW(fullstop) = FULLSTOP_RMMOD;
93711 mutex_unlock(&fullstop_mutex);
93712 torture_shutdown_cleanup();
93713 torture_shuffle_cleanup();
93714diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
93715index c1bd4ad..4b861dc 100644
93716--- a/kernel/trace/blktrace.c
93717+++ b/kernel/trace/blktrace.c
93718@@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
93719 struct blk_trace *bt = filp->private_data;
93720 char buf[16];
93721
93722- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
93723+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
93724
93725 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
93726 }
93727@@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
93728 return 1;
93729
93730 bt = buf->chan->private_data;
93731- atomic_inc(&bt->dropped);
93732+ atomic_inc_unchecked(&bt->dropped);
93733 return 0;
93734 }
93735
93736@@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
93737
93738 bt->dir = dir;
93739 bt->dev = dev;
93740- atomic_set(&bt->dropped, 0);
93741+ atomic_set_unchecked(&bt->dropped, 0);
93742 INIT_LIST_HEAD(&bt->running_list);
93743
93744 ret = -EIO;
93745diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
93746index 31c90fe..051ce98 100644
93747--- a/kernel/trace/ftrace.c
93748+++ b/kernel/trace/ftrace.c
93749@@ -2183,12 +2183,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
93750 if (unlikely(ftrace_disabled))
93751 return 0;
93752
93753+ ret = ftrace_arch_code_modify_prepare();
93754+ FTRACE_WARN_ON(ret);
93755+ if (ret)
93756+ return 0;
93757+
93758 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
93759+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
93760 if (ret) {
93761 ftrace_bug(ret, ip);
93762- return 0;
93763 }
93764- return 1;
93765+ return ret ? 0 : 1;
93766 }
93767
93768 /*
93769@@ -4492,8 +4497,10 @@ static int ftrace_process_locs(struct module *mod,
93770 if (!count)
93771 return 0;
93772
93773+ pax_open_kernel();
93774 sort(start, count, sizeof(*start),
93775 ftrace_cmp_ips, ftrace_swap_ips);
93776+ pax_close_kernel();
93777
93778 start_pg = ftrace_allocate_pages(count);
93779 if (!start_pg)
93780@@ -5340,7 +5347,7 @@ static int alloc_retstack_tasklist(struct ftrace_ret_stack **ret_stack_list)
93781
93782 if (t->ret_stack == NULL) {
93783 atomic_set(&t->tracing_graph_pause, 0);
93784- atomic_set(&t->trace_overrun, 0);
93785+ atomic_set_unchecked(&t->trace_overrun, 0);
93786 t->curr_ret_stack = -1;
93787 /* Make sure the tasks see the -1 first: */
93788 smp_wmb();
93789@@ -5553,7 +5560,7 @@ static void
93790 graph_init_task(struct task_struct *t, struct ftrace_ret_stack *ret_stack)
93791 {
93792 atomic_set(&t->tracing_graph_pause, 0);
93793- atomic_set(&t->trace_overrun, 0);
93794+ atomic_set_unchecked(&t->trace_overrun, 0);
93795 t->ftrace_timestamp = 0;
93796 /* make curr_ret_stack visible before we add the ret_stack */
93797 smp_wmb();
93798diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
93799index a56e07c..d46f0ba 100644
93800--- a/kernel/trace/ring_buffer.c
93801+++ b/kernel/trace/ring_buffer.c
93802@@ -352,9 +352,9 @@ struct buffer_data_page {
93803 */
93804 struct buffer_page {
93805 struct list_head list; /* list of buffer pages */
93806- local_t write; /* index for next write */
93807+ local_unchecked_t write; /* index for next write */
93808 unsigned read; /* index for next read */
93809- local_t entries; /* entries on this page */
93810+ local_unchecked_t entries; /* entries on this page */
93811 unsigned long real_end; /* real end of data */
93812 struct buffer_data_page *page; /* Actual data page */
93813 };
93814@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
93815 unsigned long last_overrun;
93816 local_t entries_bytes;
93817 local_t entries;
93818- local_t overrun;
93819- local_t commit_overrun;
93820+ local_unchecked_t overrun;
93821+ local_unchecked_t commit_overrun;
93822 local_t dropped_events;
93823 local_t committing;
93824 local_t commits;
93825@@ -1032,8 +1032,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
93826 *
93827 * We add a counter to the write field to denote this.
93828 */
93829- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
93830- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
93831+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
93832+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
93833
93834 /*
93835 * Just make sure we have seen our old_write and synchronize
93836@@ -1061,8 +1061,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
93837 * cmpxchg to only update if an interrupt did not already
93838 * do it for us. If the cmpxchg fails, we don't care.
93839 */
93840- (void)local_cmpxchg(&next_page->write, old_write, val);
93841- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
93842+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
93843+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
93844
93845 /*
93846 * No need to worry about races with clearing out the commit.
93847@@ -1429,12 +1429,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
93848
93849 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
93850 {
93851- return local_read(&bpage->entries) & RB_WRITE_MASK;
93852+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
93853 }
93854
93855 static inline unsigned long rb_page_write(struct buffer_page *bpage)
93856 {
93857- return local_read(&bpage->write) & RB_WRITE_MASK;
93858+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
93859 }
93860
93861 static int
93862@@ -1529,7 +1529,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
93863 * bytes consumed in ring buffer from here.
93864 * Increment overrun to account for the lost events.
93865 */
93866- local_add(page_entries, &cpu_buffer->overrun);
93867+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
93868 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
93869 }
93870
93871@@ -2091,7 +2091,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
93872 * it is our responsibility to update
93873 * the counters.
93874 */
93875- local_add(entries, &cpu_buffer->overrun);
93876+ local_add_unchecked(entries, &cpu_buffer->overrun);
93877 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
93878
93879 /*
93880@@ -2241,7 +2241,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
93881 if (tail == BUF_PAGE_SIZE)
93882 tail_page->real_end = 0;
93883
93884- local_sub(length, &tail_page->write);
93885+ local_sub_unchecked(length, &tail_page->write);
93886 return;
93887 }
93888
93889@@ -2276,7 +2276,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
93890 rb_event_set_padding(event);
93891
93892 /* Set the write back to the previous setting */
93893- local_sub(length, &tail_page->write);
93894+ local_sub_unchecked(length, &tail_page->write);
93895 return;
93896 }
93897
93898@@ -2288,7 +2288,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
93899
93900 /* Set write to end of buffer */
93901 length = (tail + length) - BUF_PAGE_SIZE;
93902- local_sub(length, &tail_page->write);
93903+ local_sub_unchecked(length, &tail_page->write);
93904 }
93905
93906 /*
93907@@ -2314,7 +2314,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
93908 * about it.
93909 */
93910 if (unlikely(next_page == commit_page)) {
93911- local_inc(&cpu_buffer->commit_overrun);
93912+ local_inc_unchecked(&cpu_buffer->commit_overrun);
93913 goto out_reset;
93914 }
93915
93916@@ -2370,7 +2370,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
93917 cpu_buffer->tail_page) &&
93918 (cpu_buffer->commit_page ==
93919 cpu_buffer->reader_page))) {
93920- local_inc(&cpu_buffer->commit_overrun);
93921+ local_inc_unchecked(&cpu_buffer->commit_overrun);
93922 goto out_reset;
93923 }
93924 }
93925@@ -2418,7 +2418,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
93926 length += RB_LEN_TIME_EXTEND;
93927
93928 tail_page = cpu_buffer->tail_page;
93929- write = local_add_return(length, &tail_page->write);
93930+ write = local_add_return_unchecked(length, &tail_page->write);
93931
93932 /* set write to only the index of the write */
93933 write &= RB_WRITE_MASK;
93934@@ -2442,7 +2442,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
93935 kmemcheck_annotate_bitfield(event, bitfield);
93936 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
93937
93938- local_inc(&tail_page->entries);
93939+ local_inc_unchecked(&tail_page->entries);
93940
93941 /*
93942 * If this is the first commit on the page, then update
93943@@ -2475,7 +2475,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
93944
93945 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
93946 unsigned long write_mask =
93947- local_read(&bpage->write) & ~RB_WRITE_MASK;
93948+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
93949 unsigned long event_length = rb_event_length(event);
93950 /*
93951 * This is on the tail page. It is possible that
93952@@ -2485,7 +2485,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
93953 */
93954 old_index += write_mask;
93955 new_index += write_mask;
93956- index = local_cmpxchg(&bpage->write, old_index, new_index);
93957+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
93958 if (index == old_index) {
93959 /* update counters */
93960 local_sub(event_length, &cpu_buffer->entries_bytes);
93961@@ -2877,7 +2877,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
93962
93963 /* Do the likely case first */
93964 if (likely(bpage->page == (void *)addr)) {
93965- local_dec(&bpage->entries);
93966+ local_dec_unchecked(&bpage->entries);
93967 return;
93968 }
93969
93970@@ -2889,7 +2889,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
93971 start = bpage;
93972 do {
93973 if (bpage->page == (void *)addr) {
93974- local_dec(&bpage->entries);
93975+ local_dec_unchecked(&bpage->entries);
93976 return;
93977 }
93978 rb_inc_page(cpu_buffer, &bpage);
93979@@ -3173,7 +3173,7 @@ static inline unsigned long
93980 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
93981 {
93982 return local_read(&cpu_buffer->entries) -
93983- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
93984+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
93985 }
93986
93987 /**
93988@@ -3262,7 +3262,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
93989 return 0;
93990
93991 cpu_buffer = buffer->buffers[cpu];
93992- ret = local_read(&cpu_buffer->overrun);
93993+ ret = local_read_unchecked(&cpu_buffer->overrun);
93994
93995 return ret;
93996 }
93997@@ -3285,7 +3285,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
93998 return 0;
93999
94000 cpu_buffer = buffer->buffers[cpu];
94001- ret = local_read(&cpu_buffer->commit_overrun);
94002+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
94003
94004 return ret;
94005 }
94006@@ -3370,7 +3370,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
94007 /* if you care about this being correct, lock the buffer */
94008 for_each_buffer_cpu(buffer, cpu) {
94009 cpu_buffer = buffer->buffers[cpu];
94010- overruns += local_read(&cpu_buffer->overrun);
94011+ overruns += local_read_unchecked(&cpu_buffer->overrun);
94012 }
94013
94014 return overruns;
94015@@ -3541,8 +3541,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
94016 /*
94017 * Reset the reader page to size zero.
94018 */
94019- local_set(&cpu_buffer->reader_page->write, 0);
94020- local_set(&cpu_buffer->reader_page->entries, 0);
94021+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
94022+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
94023 local_set(&cpu_buffer->reader_page->page->commit, 0);
94024 cpu_buffer->reader_page->real_end = 0;
94025
94026@@ -3576,7 +3576,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
94027 * want to compare with the last_overrun.
94028 */
94029 smp_mb();
94030- overwrite = local_read(&(cpu_buffer->overrun));
94031+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
94032
94033 /*
94034 * Here's the tricky part.
94035@@ -4148,8 +4148,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
94036
94037 cpu_buffer->head_page
94038 = list_entry(cpu_buffer->pages, struct buffer_page, list);
94039- local_set(&cpu_buffer->head_page->write, 0);
94040- local_set(&cpu_buffer->head_page->entries, 0);
94041+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
94042+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
94043 local_set(&cpu_buffer->head_page->page->commit, 0);
94044
94045 cpu_buffer->head_page->read = 0;
94046@@ -4159,14 +4159,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
94047
94048 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
94049 INIT_LIST_HEAD(&cpu_buffer->new_pages);
94050- local_set(&cpu_buffer->reader_page->write, 0);
94051- local_set(&cpu_buffer->reader_page->entries, 0);
94052+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
94053+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
94054 local_set(&cpu_buffer->reader_page->page->commit, 0);
94055 cpu_buffer->reader_page->read = 0;
94056
94057 local_set(&cpu_buffer->entries_bytes, 0);
94058- local_set(&cpu_buffer->overrun, 0);
94059- local_set(&cpu_buffer->commit_overrun, 0);
94060+ local_set_unchecked(&cpu_buffer->overrun, 0);
94061+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
94062 local_set(&cpu_buffer->dropped_events, 0);
94063 local_set(&cpu_buffer->entries, 0);
94064 local_set(&cpu_buffer->committing, 0);
94065@@ -4571,8 +4571,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
94066 rb_init_page(bpage);
94067 bpage = reader->page;
94068 reader->page = *data_page;
94069- local_set(&reader->write, 0);
94070- local_set(&reader->entries, 0);
94071+ local_set_unchecked(&reader->write, 0);
94072+ local_set_unchecked(&reader->entries, 0);
94073 reader->read = 0;
94074 *data_page = bpage;
94075
94076diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
94077index 426962b..e8e2d9a 100644
94078--- a/kernel/trace/trace.c
94079+++ b/kernel/trace/trace.c
94080@@ -3488,7 +3488,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
94081 return 0;
94082 }
94083
94084-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
94085+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
94086 {
94087 /* do nothing if flag is already set */
94088 if (!!(trace_flags & mask) == !!enabled)
94089diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
94090index 385391f..8d2250f 100644
94091--- a/kernel/trace/trace.h
94092+++ b/kernel/trace/trace.h
94093@@ -1280,7 +1280,7 @@ extern const char *__stop___tracepoint_str[];
94094 void trace_printk_init_buffers(void);
94095 void trace_printk_start_comm(void);
94096 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
94097-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
94098+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
94099
94100 /*
94101 * Normal trace_printk() and friends allocates special buffers
94102diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
94103index 57b67b1..66082a9 100644
94104--- a/kernel/trace/trace_clock.c
94105+++ b/kernel/trace/trace_clock.c
94106@@ -124,7 +124,7 @@ u64 notrace trace_clock_global(void)
94107 return now;
94108 }
94109
94110-static atomic64_t trace_counter;
94111+static atomic64_unchecked_t trace_counter;
94112
94113 /*
94114 * trace_clock_counter(): simply an atomic counter.
94115@@ -133,5 +133,5 @@ static atomic64_t trace_counter;
94116 */
94117 u64 notrace trace_clock_counter(void)
94118 {
94119- return atomic64_add_return(1, &trace_counter);
94120+ return atomic64_inc_return_unchecked(&trace_counter);
94121 }
94122diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
94123index 1b0df1e..4ebb965 100644
94124--- a/kernel/trace/trace_events.c
94125+++ b/kernel/trace/trace_events.c
94126@@ -1720,7 +1720,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
94127 return 0;
94128 }
94129
94130-struct ftrace_module_file_ops;
94131 static void __add_event_to_tracers(struct ftrace_event_call *call);
94132
94133 /* Add an additional event_call dynamically */
94134diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c
94135index f0a0c98..3692dc8 100644
94136--- a/kernel/trace/trace_functions_graph.c
94137+++ b/kernel/trace/trace_functions_graph.c
94138@@ -133,7 +133,7 @@ ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
94139
94140 /* The return trace stack is full */
94141 if (current->curr_ret_stack == FTRACE_RETFUNC_DEPTH - 1) {
94142- atomic_inc(&current->trace_overrun);
94143+ atomic_inc_unchecked(&current->trace_overrun);
94144 return -EBUSY;
94145 }
94146
94147@@ -230,7 +230,7 @@ ftrace_pop_return_trace(struct ftrace_graph_ret *trace, unsigned long *ret,
94148 *ret = current->ret_stack[index].ret;
94149 trace->func = current->ret_stack[index].func;
94150 trace->calltime = current->ret_stack[index].calltime;
94151- trace->overrun = atomic_read(&current->trace_overrun);
94152+ trace->overrun = atomic_read_unchecked(&current->trace_overrun);
94153 trace->depth = index;
94154 }
94155
94156diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
94157index 0abd9b8..6a663a2 100644
94158--- a/kernel/trace/trace_mmiotrace.c
94159+++ b/kernel/trace/trace_mmiotrace.c
94160@@ -24,7 +24,7 @@ struct header_iter {
94161 static struct trace_array *mmio_trace_array;
94162 static bool overrun_detected;
94163 static unsigned long prev_overruns;
94164-static atomic_t dropped_count;
94165+static atomic_unchecked_t dropped_count;
94166
94167 static void mmio_reset_data(struct trace_array *tr)
94168 {
94169@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
94170
94171 static unsigned long count_overruns(struct trace_iterator *iter)
94172 {
94173- unsigned long cnt = atomic_xchg(&dropped_count, 0);
94174+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
94175 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
94176
94177 if (over > prev_overruns)
94178@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
94179 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
94180 sizeof(*entry), 0, pc);
94181 if (!event) {
94182- atomic_inc(&dropped_count);
94183+ atomic_inc_unchecked(&dropped_count);
94184 return;
94185 }
94186 entry = ring_buffer_event_data(event);
94187@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
94188 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
94189 sizeof(*entry), 0, pc);
94190 if (!event) {
94191- atomic_inc(&dropped_count);
94192+ atomic_inc_unchecked(&dropped_count);
94193 return;
94194 }
94195 entry = ring_buffer_event_data(event);
94196diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
94197index c6977d5..d243785 100644
94198--- a/kernel/trace/trace_output.c
94199+++ b/kernel/trace/trace_output.c
94200@@ -712,14 +712,16 @@ int register_ftrace_event(struct trace_event *event)
94201 goto out;
94202 }
94203
94204+ pax_open_kernel();
94205 if (event->funcs->trace == NULL)
94206- event->funcs->trace = trace_nop_print;
94207+ *(void **)&event->funcs->trace = trace_nop_print;
94208 if (event->funcs->raw == NULL)
94209- event->funcs->raw = trace_nop_print;
94210+ *(void **)&event->funcs->raw = trace_nop_print;
94211 if (event->funcs->hex == NULL)
94212- event->funcs->hex = trace_nop_print;
94213+ *(void **)&event->funcs->hex = trace_nop_print;
94214 if (event->funcs->binary == NULL)
94215- event->funcs->binary = trace_nop_print;
94216+ *(void **)&event->funcs->binary = trace_nop_print;
94217+ pax_close_kernel();
94218
94219 key = event->type & (EVENT_HASHSIZE - 1);
94220
94221diff --git a/kernel/trace/trace_seq.c b/kernel/trace/trace_seq.c
94222index 1f24ed9..10407ec 100644
94223--- a/kernel/trace/trace_seq.c
94224+++ b/kernel/trace/trace_seq.c
94225@@ -367,7 +367,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
94226
94227 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
94228 if (!IS_ERR(p)) {
94229- p = mangle_path(s->buffer + s->len, p, "\n");
94230+ p = mangle_path(s->buffer + s->len, p, "\n\\");
94231 if (p) {
94232 s->len = p - s->buffer;
94233 return 1;
94234diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
94235index 16eddb3..758b308 100644
94236--- a/kernel/trace/trace_stack.c
94237+++ b/kernel/trace/trace_stack.c
94238@@ -90,7 +90,7 @@ check_stack(unsigned long ip, unsigned long *stack)
94239 return;
94240
94241 /* we do not handle interrupt stacks yet */
94242- if (!object_is_on_stack(stack))
94243+ if (!object_starts_on_stack(stack))
94244 return;
94245
94246 local_irq_save(flags);
94247diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c
94248index 29228c4..301bc8c 100644
94249--- a/kernel/trace/trace_syscalls.c
94250+++ b/kernel/trace/trace_syscalls.c
94251@@ -602,6 +602,8 @@ static int perf_sysenter_enable(struct ftrace_event_call *call)
94252 int num;
94253
94254 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94255+ if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94256+ return -EINVAL;
94257
94258 mutex_lock(&syscall_trace_lock);
94259 if (!sys_perf_refcount_enter)
94260@@ -622,6 +624,8 @@ static void perf_sysenter_disable(struct ftrace_event_call *call)
94261 int num;
94262
94263 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94264+ if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94265+ return;
94266
94267 mutex_lock(&syscall_trace_lock);
94268 sys_perf_refcount_enter--;
94269@@ -674,6 +678,8 @@ static int perf_sysexit_enable(struct ftrace_event_call *call)
94270 int num;
94271
94272 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94273+ if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94274+ return -EINVAL;
94275
94276 mutex_lock(&syscall_trace_lock);
94277 if (!sys_perf_refcount_exit)
94278@@ -694,6 +700,8 @@ static void perf_sysexit_disable(struct ftrace_event_call *call)
94279 int num;
94280
94281 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94282+ if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94283+ return;
94284
94285 mutex_lock(&syscall_trace_lock);
94286 sys_perf_refcount_exit--;
94287diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
94288index aa312b0..395f343 100644
94289--- a/kernel/user_namespace.c
94290+++ b/kernel/user_namespace.c
94291@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
94292 !kgid_has_mapping(parent_ns, group))
94293 return -EPERM;
94294
94295+#ifdef CONFIG_GRKERNSEC
94296+ /*
94297+ * This doesn't really inspire confidence:
94298+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
94299+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
94300+ * Increases kernel attack surface in areas developers
94301+ * previously cared little about ("low importance due
94302+ * to requiring "root" capability")
94303+ * To be removed when this code receives *proper* review
94304+ */
94305+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
94306+ !capable(CAP_SETGID))
94307+ return -EPERM;
94308+#endif
94309+
94310 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
94311 if (!ns)
94312 return -ENOMEM;
94313@@ -872,7 +887,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
94314 if (atomic_read(&current->mm->mm_users) > 1)
94315 return -EINVAL;
94316
94317- if (current->fs->users != 1)
94318+ if (atomic_read(&current->fs->users) != 1)
94319 return -EINVAL;
94320
94321 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
94322diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
94323index c8eac43..4b5f08f 100644
94324--- a/kernel/utsname_sysctl.c
94325+++ b/kernel/utsname_sysctl.c
94326@@ -47,7 +47,7 @@ static void put_uts(struct ctl_table *table, int write, void *which)
94327 static int proc_do_uts_string(struct ctl_table *table, int write,
94328 void __user *buffer, size_t *lenp, loff_t *ppos)
94329 {
94330- struct ctl_table uts_table;
94331+ ctl_table_no_const uts_table;
94332 int r;
94333 memcpy(&uts_table, table, sizeof(uts_table));
94334 uts_table.data = get_uts(table, write);
94335diff --git a/kernel/watchdog.c b/kernel/watchdog.c
94336index 70bf118..4be3c37 100644
94337--- a/kernel/watchdog.c
94338+++ b/kernel/watchdog.c
94339@@ -572,7 +572,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
94340 static void watchdog_nmi_disable(unsigned int cpu) { return; }
94341 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
94342
94343-static struct smp_hotplug_thread watchdog_threads = {
94344+static struct smp_hotplug_thread watchdog_threads __read_only = {
94345 .store = &softlockup_watchdog,
94346 .thread_should_run = watchdog_should_run,
94347 .thread_fn = watchdog,
94348diff --git a/kernel/workqueue.c b/kernel/workqueue.c
94349index 09b685d..d3565e3 100644
94350--- a/kernel/workqueue.c
94351+++ b/kernel/workqueue.c
94352@@ -4508,7 +4508,7 @@ static void rebind_workers(struct worker_pool *pool)
94353 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
94354 worker_flags |= WORKER_REBOUND;
94355 worker_flags &= ~WORKER_UNBOUND;
94356- ACCESS_ONCE(worker->flags) = worker_flags;
94357+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
94358 }
94359
94360 spin_unlock_irq(&pool->lock);
94361diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
94362index 4e35a5d..8a1f3f0 100644
94363--- a/lib/Kconfig.debug
94364+++ b/lib/Kconfig.debug
94365@@ -894,7 +894,7 @@ config DEBUG_MUTEXES
94366
94367 config DEBUG_WW_MUTEX_SLOWPATH
94368 bool "Wait/wound mutex debugging: Slowpath testing"
94369- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94370+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94371 select DEBUG_LOCK_ALLOC
94372 select DEBUG_SPINLOCK
94373 select DEBUG_MUTEXES
94374@@ -911,7 +911,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
94375
94376 config DEBUG_LOCK_ALLOC
94377 bool "Lock debugging: detect incorrect freeing of live locks"
94378- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94379+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94380 select DEBUG_SPINLOCK
94381 select DEBUG_MUTEXES
94382 select LOCKDEP
94383@@ -925,7 +925,7 @@ config DEBUG_LOCK_ALLOC
94384
94385 config PROVE_LOCKING
94386 bool "Lock debugging: prove locking correctness"
94387- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94388+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94389 select LOCKDEP
94390 select DEBUG_SPINLOCK
94391 select DEBUG_MUTEXES
94392@@ -976,7 +976,7 @@ config LOCKDEP
94393
94394 config LOCK_STAT
94395 bool "Lock usage statistics"
94396- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94397+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94398 select LOCKDEP
94399 select DEBUG_SPINLOCK
94400 select DEBUG_MUTEXES
94401@@ -1449,6 +1449,7 @@ config LATENCYTOP
94402 depends on DEBUG_KERNEL
94403 depends on STACKTRACE_SUPPORT
94404 depends on PROC_FS
94405+ depends on !GRKERNSEC_HIDESYM
94406 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
94407 select KALLSYMS
94408 select KALLSYMS_ALL
94409@@ -1465,7 +1466,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
94410 config DEBUG_STRICT_USER_COPY_CHECKS
94411 bool "Strict user copy size checks"
94412 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
94413- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
94414+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
94415 help
94416 Enabling this option turns a certain set of sanity checks for user
94417 copy operations into compile time failures.
94418@@ -1593,7 +1594,7 @@ endmenu # runtime tests
94419
94420 config PROVIDE_OHCI1394_DMA_INIT
94421 bool "Remote debugging over FireWire early on boot"
94422- depends on PCI && X86
94423+ depends on PCI && X86 && !GRKERNSEC
94424 help
94425 If you want to debug problems which hang or crash the kernel early
94426 on boot and the crashing machine has a FireWire port, you can use
94427diff --git a/lib/Makefile b/lib/Makefile
94428index 0211d2b..93f5cc3 100644
94429--- a/lib/Makefile
94430+++ b/lib/Makefile
94431@@ -55,7 +55,7 @@ obj-$(CONFIG_BTREE) += btree.o
94432 obj-$(CONFIG_INTERVAL_TREE) += interval_tree.o
94433 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
94434 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
94435-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
94436+obj-y += list_debug.o
94437 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
94438
94439 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
94440diff --git a/lib/average.c b/lib/average.c
94441index 114d1be..ab0350c 100644
94442--- a/lib/average.c
94443+++ b/lib/average.c
94444@@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
94445 {
94446 unsigned long internal = ACCESS_ONCE(avg->internal);
94447
94448- ACCESS_ONCE(avg->internal) = internal ?
94449+ ACCESS_ONCE_RW(avg->internal) = internal ?
94450 (((internal << avg->weight) - internal) +
94451 (val << avg->factor)) >> avg->weight :
94452 (val << avg->factor);
94453diff --git a/lib/bitmap.c b/lib/bitmap.c
94454index b499ab6..fbdb76c 100644
94455--- a/lib/bitmap.c
94456+++ b/lib/bitmap.c
94457@@ -433,7 +433,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
94458 {
94459 int c, old_c, totaldigits, ndigits, nchunks, nbits;
94460 u32 chunk;
94461- const char __user __force *ubuf = (const char __user __force *)buf;
94462+ const char __user *ubuf = (const char __force_user *)buf;
94463
94464 bitmap_zero(maskp, nmaskbits);
94465
94466@@ -518,7 +518,7 @@ int bitmap_parse_user(const char __user *ubuf,
94467 {
94468 if (!access_ok(VERIFY_READ, ubuf, ulen))
94469 return -EFAULT;
94470- return __bitmap_parse((const char __force *)ubuf,
94471+ return __bitmap_parse((const char __force_kernel *)ubuf,
94472 ulen, 1, maskp, nmaskbits);
94473
94474 }
94475@@ -609,7 +609,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
94476 {
94477 unsigned a, b;
94478 int c, old_c, totaldigits;
94479- const char __user __force *ubuf = (const char __user __force *)buf;
94480+ const char __user *ubuf = (const char __force_user *)buf;
94481 int exp_digit, in_range;
94482
94483 totaldigits = c = 0;
94484@@ -704,7 +704,7 @@ int bitmap_parselist_user(const char __user *ubuf,
94485 {
94486 if (!access_ok(VERIFY_READ, ubuf, ulen))
94487 return -EFAULT;
94488- return __bitmap_parselist((const char __force *)ubuf,
94489+ return __bitmap_parselist((const char __force_kernel *)ubuf,
94490 ulen, 1, maskp, nmaskbits);
94491 }
94492 EXPORT_SYMBOL(bitmap_parselist_user);
94493diff --git a/lib/bug.c b/lib/bug.c
94494index d1d7c78..b354235 100644
94495--- a/lib/bug.c
94496+++ b/lib/bug.c
94497@@ -137,6 +137,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
94498 return BUG_TRAP_TYPE_NONE;
94499
94500 bug = find_bug(bugaddr);
94501+ if (!bug)
94502+ return BUG_TRAP_TYPE_NONE;
94503
94504 file = NULL;
94505 line = 0;
94506diff --git a/lib/debugobjects.c b/lib/debugobjects.c
94507index 547f7f9..a6d4ba0 100644
94508--- a/lib/debugobjects.c
94509+++ b/lib/debugobjects.c
94510@@ -289,7 +289,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
94511 if (limit > 4)
94512 return;
94513
94514- is_on_stack = object_is_on_stack(addr);
94515+ is_on_stack = object_starts_on_stack(addr);
94516 if (is_on_stack == onstack)
94517 return;
94518
94519diff --git a/lib/div64.c b/lib/div64.c
94520index 4382ad7..08aa558 100644
94521--- a/lib/div64.c
94522+++ b/lib/div64.c
94523@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
94524 EXPORT_SYMBOL(__div64_32);
94525
94526 #ifndef div_s64_rem
94527-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
94528+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
94529 {
94530 u64 quotient;
94531
94532@@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
94533 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
94534 */
94535 #ifndef div64_u64
94536-u64 div64_u64(u64 dividend, u64 divisor)
94537+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
94538 {
94539 u32 high = divisor >> 32;
94540 u64 quot;
94541diff --git a/lib/dma-debug.c b/lib/dma-debug.c
94542index add80cc..0d27550 100644
94543--- a/lib/dma-debug.c
94544+++ b/lib/dma-debug.c
94545@@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
94546
94547 void dma_debug_add_bus(struct bus_type *bus)
94548 {
94549- struct notifier_block *nb;
94550+ notifier_block_no_const *nb;
94551
94552 if (global_disable)
94553 return;
94554@@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
94555
94556 static void check_for_stack(struct device *dev, void *addr)
94557 {
94558- if (object_is_on_stack(addr))
94559+ if (object_starts_on_stack(addr))
94560 err_printk(dev, NULL, "DMA-API: device driver maps memory from "
94561 "stack [addr=%p]\n", addr);
94562 }
94563diff --git a/lib/hash.c b/lib/hash.c
94564index fea973f..386626f 100644
94565--- a/lib/hash.c
94566+++ b/lib/hash.c
94567@@ -14,7 +14,7 @@
94568 #include <linux/hash.h>
94569 #include <linux/cache.h>
94570
94571-static struct fast_hash_ops arch_hash_ops __read_mostly = {
94572+static struct fast_hash_ops arch_hash_ops __read_only = {
94573 .hash = jhash,
94574 .hash2 = jhash2,
94575 };
94576diff --git a/lib/inflate.c b/lib/inflate.c
94577index 013a761..c28f3fc 100644
94578--- a/lib/inflate.c
94579+++ b/lib/inflate.c
94580@@ -269,7 +269,7 @@ static void free(void *where)
94581 malloc_ptr = free_mem_ptr;
94582 }
94583 #else
94584-#define malloc(a) kmalloc(a, GFP_KERNEL)
94585+#define malloc(a) kmalloc((a), GFP_KERNEL)
94586 #define free(a) kfree(a)
94587 #endif
94588
94589diff --git a/lib/ioremap.c b/lib/ioremap.c
94590index 0c9216c..863bd89 100644
94591--- a/lib/ioremap.c
94592+++ b/lib/ioremap.c
94593@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
94594 unsigned long next;
94595
94596 phys_addr -= addr;
94597- pmd = pmd_alloc(&init_mm, pud, addr);
94598+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
94599 if (!pmd)
94600 return -ENOMEM;
94601 do {
94602@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
94603 unsigned long next;
94604
94605 phys_addr -= addr;
94606- pud = pud_alloc(&init_mm, pgd, addr);
94607+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
94608 if (!pud)
94609 return -ENOMEM;
94610 do {
94611diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
94612index bd2bea9..6b3c95e 100644
94613--- a/lib/is_single_threaded.c
94614+++ b/lib/is_single_threaded.c
94615@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
94616 struct task_struct *p, *t;
94617 bool ret;
94618
94619+ if (!mm)
94620+ return true;
94621+
94622 if (atomic_read(&task->signal->live) != 1)
94623 return false;
94624
94625diff --git a/lib/kobject.c b/lib/kobject.c
94626index 58751bb..93a1853 100644
94627--- a/lib/kobject.c
94628+++ b/lib/kobject.c
94629@@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
94630
94631
94632 static DEFINE_SPINLOCK(kobj_ns_type_lock);
94633-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
94634+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
94635
94636-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
94637+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
94638 {
94639 enum kobj_ns_type type = ops->type;
94640 int error;
94641diff --git a/lib/list_debug.c b/lib/list_debug.c
94642index c24c2f7..f0296f4 100644
94643--- a/lib/list_debug.c
94644+++ b/lib/list_debug.c
94645@@ -11,7 +11,9 @@
94646 #include <linux/bug.h>
94647 #include <linux/kernel.h>
94648 #include <linux/rculist.h>
94649+#include <linux/mm.h>
94650
94651+#ifdef CONFIG_DEBUG_LIST
94652 /*
94653 * Insert a new entry between two known consecutive entries.
94654 *
94655@@ -19,21 +21,40 @@
94656 * the prev/next entries already!
94657 */
94658
94659+static bool __list_add_debug(struct list_head *new,
94660+ struct list_head *prev,
94661+ struct list_head *next)
94662+{
94663+ if (unlikely(next->prev != prev)) {
94664+ printk(KERN_ERR "list_add corruption. next->prev should be "
94665+ "prev (%p), but was %p. (next=%p).\n",
94666+ prev, next->prev, next);
94667+ BUG();
94668+ return false;
94669+ }
94670+ if (unlikely(prev->next != next)) {
94671+ printk(KERN_ERR "list_add corruption. prev->next should be "
94672+ "next (%p), but was %p. (prev=%p).\n",
94673+ next, prev->next, prev);
94674+ BUG();
94675+ return false;
94676+ }
94677+ if (unlikely(new == prev || new == next)) {
94678+ printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
94679+ new, prev, next);
94680+ BUG();
94681+ return false;
94682+ }
94683+ return true;
94684+}
94685+
94686 void __list_add(struct list_head *new,
94687- struct list_head *prev,
94688- struct list_head *next)
94689+ struct list_head *prev,
94690+ struct list_head *next)
94691 {
94692- WARN(next->prev != prev,
94693- "list_add corruption. next->prev should be "
94694- "prev (%p), but was %p. (next=%p).\n",
94695- prev, next->prev, next);
94696- WARN(prev->next != next,
94697- "list_add corruption. prev->next should be "
94698- "next (%p), but was %p. (prev=%p).\n",
94699- next, prev->next, prev);
94700- WARN(new == prev || new == next,
94701- "list_add double add: new=%p, prev=%p, next=%p.\n",
94702- new, prev, next);
94703+ if (!__list_add_debug(new, prev, next))
94704+ return;
94705+
94706 next->prev = new;
94707 new->next = next;
94708 new->prev = prev;
94709@@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
94710 }
94711 EXPORT_SYMBOL(__list_add);
94712
94713-void __list_del_entry(struct list_head *entry)
94714+static bool __list_del_entry_debug(struct list_head *entry)
94715 {
94716 struct list_head *prev, *next;
94717
94718 prev = entry->prev;
94719 next = entry->next;
94720
94721- if (WARN(next == LIST_POISON1,
94722- "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
94723- entry, LIST_POISON1) ||
94724- WARN(prev == LIST_POISON2,
94725- "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
94726- entry, LIST_POISON2) ||
94727- WARN(prev->next != entry,
94728- "list_del corruption. prev->next should be %p, "
94729- "but was %p\n", entry, prev->next) ||
94730- WARN(next->prev != entry,
94731- "list_del corruption. next->prev should be %p, "
94732- "but was %p\n", entry, next->prev))
94733+ if (unlikely(next == LIST_POISON1)) {
94734+ printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
94735+ entry, LIST_POISON1);
94736+ BUG();
94737+ return false;
94738+ }
94739+ if (unlikely(prev == LIST_POISON2)) {
94740+ printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
94741+ entry, LIST_POISON2);
94742+ BUG();
94743+ return false;
94744+ }
94745+ if (unlikely(entry->prev->next != entry)) {
94746+ printk(KERN_ERR "list_del corruption. prev->next should be %p, "
94747+ "but was %p\n", entry, prev->next);
94748+ BUG();
94749+ return false;
94750+ }
94751+ if (unlikely(entry->next->prev != entry)) {
94752+ printk(KERN_ERR "list_del corruption. next->prev should be %p, "
94753+ "but was %p\n", entry, next->prev);
94754+ BUG();
94755+ return false;
94756+ }
94757+ return true;
94758+}
94759+
94760+void __list_del_entry(struct list_head *entry)
94761+{
94762+ if (!__list_del_entry_debug(entry))
94763 return;
94764
94765- __list_del(prev, next);
94766+ __list_del(entry->prev, entry->next);
94767 }
94768 EXPORT_SYMBOL(__list_del_entry);
94769
94770@@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
94771 void __list_add_rcu(struct list_head *new,
94772 struct list_head *prev, struct list_head *next)
94773 {
94774- WARN(next->prev != prev,
94775- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
94776- prev, next->prev, next);
94777- WARN(prev->next != next,
94778- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
94779- next, prev->next, prev);
94780+ if (!__list_add_debug(new, prev, next))
94781+ return;
94782+
94783 new->next = next;
94784 new->prev = prev;
94785 rcu_assign_pointer(list_next_rcu(prev), new);
94786 next->prev = new;
94787 }
94788 EXPORT_SYMBOL(__list_add_rcu);
94789+#endif
94790+
94791+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
94792+{
94793+#ifdef CONFIG_DEBUG_LIST
94794+ if (!__list_add_debug(new, prev, next))
94795+ return;
94796+#endif
94797+
94798+ pax_open_kernel();
94799+ next->prev = new;
94800+ new->next = next;
94801+ new->prev = prev;
94802+ prev->next = new;
94803+ pax_close_kernel();
94804+}
94805+EXPORT_SYMBOL(__pax_list_add);
94806+
94807+void pax_list_del(struct list_head *entry)
94808+{
94809+#ifdef CONFIG_DEBUG_LIST
94810+ if (!__list_del_entry_debug(entry))
94811+ return;
94812+#endif
94813+
94814+ pax_open_kernel();
94815+ __list_del(entry->prev, entry->next);
94816+ entry->next = LIST_POISON1;
94817+ entry->prev = LIST_POISON2;
94818+ pax_close_kernel();
94819+}
94820+EXPORT_SYMBOL(pax_list_del);
94821+
94822+void pax_list_del_init(struct list_head *entry)
94823+{
94824+ pax_open_kernel();
94825+ __list_del(entry->prev, entry->next);
94826+ INIT_LIST_HEAD(entry);
94827+ pax_close_kernel();
94828+}
94829+EXPORT_SYMBOL(pax_list_del_init);
94830+
94831+void __pax_list_add_rcu(struct list_head *new,
94832+ struct list_head *prev, struct list_head *next)
94833+{
94834+#ifdef CONFIG_DEBUG_LIST
94835+ if (!__list_add_debug(new, prev, next))
94836+ return;
94837+#endif
94838+
94839+ pax_open_kernel();
94840+ new->next = next;
94841+ new->prev = prev;
94842+ rcu_assign_pointer(list_next_rcu(prev), new);
94843+ next->prev = new;
94844+ pax_close_kernel();
94845+}
94846+EXPORT_SYMBOL(__pax_list_add_rcu);
94847+
94848+void pax_list_del_rcu(struct list_head *entry)
94849+{
94850+#ifdef CONFIG_DEBUG_LIST
94851+ if (!__list_del_entry_debug(entry))
94852+ return;
94853+#endif
94854+
94855+ pax_open_kernel();
94856+ __list_del(entry->prev, entry->next);
94857+ entry->next = LIST_POISON1;
94858+ entry->prev = LIST_POISON2;
94859+ pax_close_kernel();
94860+}
94861+EXPORT_SYMBOL(pax_list_del_rcu);
94862diff --git a/lib/lockref.c b/lib/lockref.c
94863index d2233de..fa1a2f6 100644
94864--- a/lib/lockref.c
94865+++ b/lib/lockref.c
94866@@ -48,13 +48,13 @@
94867 void lockref_get(struct lockref *lockref)
94868 {
94869 CMPXCHG_LOOP(
94870- new.count++;
94871+ __lockref_inc(&new);
94872 ,
94873 return;
94874 );
94875
94876 spin_lock(&lockref->lock);
94877- lockref->count++;
94878+ __lockref_inc(lockref);
94879 spin_unlock(&lockref->lock);
94880 }
94881 EXPORT_SYMBOL(lockref_get);
94882@@ -69,7 +69,7 @@ int lockref_get_not_zero(struct lockref *lockref)
94883 int retval;
94884
94885 CMPXCHG_LOOP(
94886- new.count++;
94887+ __lockref_inc(&new);
94888 if (!old.count)
94889 return 0;
94890 ,
94891@@ -79,7 +79,7 @@ int lockref_get_not_zero(struct lockref *lockref)
94892 spin_lock(&lockref->lock);
94893 retval = 0;
94894 if (lockref->count) {
94895- lockref->count++;
94896+ __lockref_inc(lockref);
94897 retval = 1;
94898 }
94899 spin_unlock(&lockref->lock);
94900@@ -96,7 +96,7 @@ EXPORT_SYMBOL(lockref_get_not_zero);
94901 int lockref_get_or_lock(struct lockref *lockref)
94902 {
94903 CMPXCHG_LOOP(
94904- new.count++;
94905+ __lockref_inc(&new);
94906 if (!old.count)
94907 break;
94908 ,
94909@@ -106,7 +106,7 @@ int lockref_get_or_lock(struct lockref *lockref)
94910 spin_lock(&lockref->lock);
94911 if (!lockref->count)
94912 return 0;
94913- lockref->count++;
94914+ __lockref_inc(lockref);
94915 spin_unlock(&lockref->lock);
94916 return 1;
94917 }
94918@@ -120,7 +120,7 @@ EXPORT_SYMBOL(lockref_get_or_lock);
94919 int lockref_put_or_lock(struct lockref *lockref)
94920 {
94921 CMPXCHG_LOOP(
94922- new.count--;
94923+ __lockref_dec(&new);
94924 if (old.count <= 1)
94925 break;
94926 ,
94927@@ -130,7 +130,7 @@ int lockref_put_or_lock(struct lockref *lockref)
94928 spin_lock(&lockref->lock);
94929 if (lockref->count <= 1)
94930 return 0;
94931- lockref->count--;
94932+ __lockref_dec(lockref);
94933 spin_unlock(&lockref->lock);
94934 return 1;
94935 }
94936@@ -157,7 +157,7 @@ int lockref_get_not_dead(struct lockref *lockref)
94937 int retval;
94938
94939 CMPXCHG_LOOP(
94940- new.count++;
94941+ __lockref_inc(&new);
94942 if ((int)old.count < 0)
94943 return 0;
94944 ,
94945@@ -167,7 +167,7 @@ int lockref_get_not_dead(struct lockref *lockref)
94946 spin_lock(&lockref->lock);
94947 retval = 0;
94948 if ((int) lockref->count >= 0) {
94949- lockref->count++;
94950+ __lockref_inc(lockref);
94951 retval = 1;
94952 }
94953 spin_unlock(&lockref->lock);
94954diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
94955index 6111bcb..02e816b 100644
94956--- a/lib/percpu-refcount.c
94957+++ b/lib/percpu-refcount.c
94958@@ -31,7 +31,7 @@
94959 * atomic_long_t can't hit 0 before we've added up all the percpu refs.
94960 */
94961
94962-#define PERCPU_COUNT_BIAS (1LU << (BITS_PER_LONG - 1))
94963+#define PERCPU_COUNT_BIAS (1LU << (BITS_PER_LONG - 2))
94964
94965 static DECLARE_WAIT_QUEUE_HEAD(percpu_ref_switch_waitq);
94966
94967diff --git a/lib/radix-tree.c b/lib/radix-tree.c
94968index 3291a8e..346a91e 100644
94969--- a/lib/radix-tree.c
94970+++ b/lib/radix-tree.c
94971@@ -67,7 +67,7 @@ struct radix_tree_preload {
94972 int nr;
94973 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
94974 };
94975-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
94976+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
94977
94978 static inline void *ptr_to_indirect(void *ptr)
94979 {
94980diff --git a/lib/random32.c b/lib/random32.c
94981index 0bee183..526f12f 100644
94982--- a/lib/random32.c
94983+++ b/lib/random32.c
94984@@ -47,7 +47,7 @@ static inline void prandom_state_selftest(void)
94985 }
94986 #endif
94987
94988-static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
94989+static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
94990
94991 /**
94992 * prandom_u32_state - seeded pseudo-random number generator.
94993diff --git a/lib/rbtree.c b/lib/rbtree.c
94994index c16c81a..4dcbda1 100644
94995--- a/lib/rbtree.c
94996+++ b/lib/rbtree.c
94997@@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
94998 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
94999
95000 static const struct rb_augment_callbacks dummy_callbacks = {
95001- dummy_propagate, dummy_copy, dummy_rotate
95002+ .propagate = dummy_propagate,
95003+ .copy = dummy_copy,
95004+ .rotate = dummy_rotate
95005 };
95006
95007 void rb_insert_color(struct rb_node *node, struct rb_root *root)
95008diff --git a/lib/show_mem.c b/lib/show_mem.c
95009index 5e25627..3ed9d7f 100644
95010--- a/lib/show_mem.c
95011+++ b/lib/show_mem.c
95012@@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
95013 quicklist_total_size());
95014 #endif
95015 #ifdef CONFIG_MEMORY_FAILURE
95016- printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
95017+ printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
95018 #endif
95019 }
95020diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
95021index bb2b201..46abaf9 100644
95022--- a/lib/strncpy_from_user.c
95023+++ b/lib/strncpy_from_user.c
95024@@ -21,7 +21,7 @@
95025 */
95026 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
95027 {
95028- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95029+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95030 long res = 0;
95031
95032 /*
95033diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
95034index a28df52..3d55877 100644
95035--- a/lib/strnlen_user.c
95036+++ b/lib/strnlen_user.c
95037@@ -26,7 +26,7 @@
95038 */
95039 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
95040 {
95041- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95042+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95043 long align, res = 0;
95044 unsigned long c;
95045
95046diff --git a/lib/swiotlb.c b/lib/swiotlb.c
95047index 4abda07..b9d3765 100644
95048--- a/lib/swiotlb.c
95049+++ b/lib/swiotlb.c
95050@@ -682,7 +682,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
95051
95052 void
95053 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
95054- dma_addr_t dev_addr)
95055+ dma_addr_t dev_addr, struct dma_attrs *attrs)
95056 {
95057 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
95058
95059diff --git a/lib/usercopy.c b/lib/usercopy.c
95060index 4f5b1dd..7cab418 100644
95061--- a/lib/usercopy.c
95062+++ b/lib/usercopy.c
95063@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
95064 WARN(1, "Buffer overflow detected!\n");
95065 }
95066 EXPORT_SYMBOL(copy_from_user_overflow);
95067+
95068+void copy_to_user_overflow(void)
95069+{
95070+ WARN(1, "Buffer overflow detected!\n");
95071+}
95072+EXPORT_SYMBOL(copy_to_user_overflow);
95073diff --git a/lib/vsprintf.c b/lib/vsprintf.c
95074index ec337f6..8484eb2 100644
95075--- a/lib/vsprintf.c
95076+++ b/lib/vsprintf.c
95077@@ -16,6 +16,9 @@
95078 * - scnprintf and vscnprintf
95079 */
95080
95081+#ifdef CONFIG_GRKERNSEC_HIDESYM
95082+#define __INCLUDED_BY_HIDESYM 1
95083+#endif
95084 #include <stdarg.h>
95085 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
95086 #include <linux/types.h>
95087@@ -625,7 +628,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
95088 #ifdef CONFIG_KALLSYMS
95089 if (*fmt == 'B')
95090 sprint_backtrace(sym, value);
95091- else if (*fmt != 'f' && *fmt != 's')
95092+ else if (*fmt != 'f' && *fmt != 's' && *fmt != 'X')
95093 sprint_symbol(sym, value);
95094 else
95095 sprint_symbol_no_offset(sym, value);
95096@@ -1240,7 +1243,11 @@ char *address_val(char *buf, char *end, const void *addr,
95097 return number(buf, end, num, spec);
95098 }
95099
95100+#ifdef CONFIG_GRKERNSEC_HIDESYM
95101+int kptr_restrict __read_mostly = 2;
95102+#else
95103 int kptr_restrict __read_mostly;
95104+#endif
95105
95106 /*
95107 * Show a '%p' thing. A kernel extension is that the '%p' is followed
95108@@ -1251,8 +1258,10 @@ int kptr_restrict __read_mostly;
95109 *
95110 * - 'F' For symbolic function descriptor pointers with offset
95111 * - 'f' For simple symbolic function names without offset
95112+ * - 'X' For simple symbolic function names without offset approved for use with GRKERNSEC_HIDESYM
95113 * - 'S' For symbolic direct pointers with offset
95114 * - 's' For symbolic direct pointers without offset
95115+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
95116 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
95117 * - 'B' For backtraced symbolic direct pointers with offset
95118 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
95119@@ -1331,12 +1340,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95120
95121 if (!ptr && *fmt != 'K') {
95122 /*
95123- * Print (null) with the same width as a pointer so it makes
95124+ * Print (nil) with the same width as a pointer so it makes
95125 * tabular output look nice.
95126 */
95127 if (spec.field_width == -1)
95128 spec.field_width = default_width;
95129- return string(buf, end, "(null)", spec);
95130+ return string(buf, end, "(nil)", spec);
95131 }
95132
95133 switch (*fmt) {
95134@@ -1346,6 +1355,14 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95135 /* Fallthrough */
95136 case 'S':
95137 case 's':
95138+#ifdef CONFIG_GRKERNSEC_HIDESYM
95139+ break;
95140+#else
95141+ return symbol_string(buf, end, ptr, spec, fmt);
95142+#endif
95143+ case 'X':
95144+ ptr = dereference_function_descriptor(ptr);
95145+ case 'A':
95146 case 'B':
95147 return symbol_string(buf, end, ptr, spec, fmt);
95148 case 'R':
95149@@ -1403,6 +1420,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95150 va_end(va);
95151 return buf;
95152 }
95153+ case 'P':
95154+ break;
95155 case 'K':
95156 /*
95157 * %pK cannot be used in IRQ context because its test
95158@@ -1460,6 +1479,22 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95159 ((const struct file *)ptr)->f_path.dentry,
95160 spec, fmt);
95161 }
95162+
95163+#ifdef CONFIG_GRKERNSEC_HIDESYM
95164+ /* 'P' = approved pointers to copy to userland,
95165+ as in the /proc/kallsyms case, as we make it display nothing
95166+ for non-root users, and the real contents for root users
95167+ 'X' = approved simple symbols
95168+ Also ignore 'K' pointers, since we force their NULLing for non-root users
95169+ above
95170+ */
95171+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'X' && *fmt != 'K' && is_usercopy_object(buf)) {
95172+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
95173+ dump_stack();
95174+ ptr = NULL;
95175+ }
95176+#endif
95177+
95178 spec.flags |= SMALL;
95179 if (spec.field_width == -1) {
95180 spec.field_width = default_width;
95181@@ -2160,11 +2195,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
95182 typeof(type) value; \
95183 if (sizeof(type) == 8) { \
95184 args = PTR_ALIGN(args, sizeof(u32)); \
95185- *(u32 *)&value = *(u32 *)args; \
95186- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
95187+ *(u32 *)&value = *(const u32 *)args; \
95188+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
95189 } else { \
95190 args = PTR_ALIGN(args, sizeof(type)); \
95191- value = *(typeof(type) *)args; \
95192+ value = *(const typeof(type) *)args; \
95193 } \
95194 args += sizeof(type); \
95195 value; \
95196@@ -2227,7 +2262,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
95197 case FORMAT_TYPE_STR: {
95198 const char *str_arg = args;
95199 args += strlen(str_arg) + 1;
95200- str = string(str, end, (char *)str_arg, spec);
95201+ str = string(str, end, str_arg, spec);
95202 break;
95203 }
95204
95205diff --git a/localversion-grsec b/localversion-grsec
95206new file mode 100644
95207index 0000000..7cd6065
95208--- /dev/null
95209+++ b/localversion-grsec
95210@@ -0,0 +1 @@
95211+-grsec
95212diff --git a/mm/Kconfig b/mm/Kconfig
95213index 1d1ae6b..0f05885 100644
95214--- a/mm/Kconfig
95215+++ b/mm/Kconfig
95216@@ -341,10 +341,11 @@ config KSM
95217 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
95218
95219 config DEFAULT_MMAP_MIN_ADDR
95220- int "Low address space to protect from user allocation"
95221+ int "Low address space to protect from user allocation"
95222 depends on MMU
95223- default 4096
95224- help
95225+ default 32768 if ALPHA || ARM || PARISC || SPARC32
95226+ default 65536
95227+ help
95228 This is the portion of low virtual memory which should be protected
95229 from userspace allocation. Keeping a user from writing to low pages
95230 can help reduce the impact of kernel NULL pointer bugs.
95231@@ -375,7 +376,7 @@ config MEMORY_FAILURE
95232
95233 config HWPOISON_INJECT
95234 tristate "HWPoison pages injector"
95235- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
95236+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
95237 select PROC_PAGE_MONITOR
95238
95239 config NOMMU_INITIAL_TRIM_EXCESS
95240diff --git a/mm/backing-dev.c b/mm/backing-dev.c
95241index 0ae0df5..82ac56b 100644
95242--- a/mm/backing-dev.c
95243+++ b/mm/backing-dev.c
95244@@ -12,7 +12,7 @@
95245 #include <linux/device.h>
95246 #include <trace/events/writeback.h>
95247
95248-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
95249+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
95250
95251 struct backing_dev_info default_backing_dev_info = {
95252 .name = "default",
95253@@ -525,7 +525,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
95254 return err;
95255
95256 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
95257- atomic_long_inc_return(&bdi_seq));
95258+ atomic_long_inc_return_unchecked(&bdi_seq));
95259 if (err) {
95260 bdi_destroy(bdi);
95261 return err;
95262diff --git a/mm/filemap.c b/mm/filemap.c
95263index 14b4642..d71ba82 100644
95264--- a/mm/filemap.c
95265+++ b/mm/filemap.c
95266@@ -2101,7 +2101,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
95267 struct address_space *mapping = file->f_mapping;
95268
95269 if (!mapping->a_ops->readpage)
95270- return -ENOEXEC;
95271+ return -ENODEV;
95272 file_accessed(file);
95273 vma->vm_ops = &generic_file_vm_ops;
95274 return 0;
95275@@ -2279,6 +2279,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
95276 *pos = i_size_read(inode);
95277
95278 if (limit != RLIM_INFINITY) {
95279+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
95280 if (*pos >= limit) {
95281 send_sig(SIGXFSZ, current, 0);
95282 return -EFBIG;
95283diff --git a/mm/fremap.c b/mm/fremap.c
95284index 72b8fa3..c5b39f1 100644
95285--- a/mm/fremap.c
95286+++ b/mm/fremap.c
95287@@ -180,6 +180,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
95288 retry:
95289 vma = find_vma(mm, start);
95290
95291+#ifdef CONFIG_PAX_SEGMEXEC
95292+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
95293+ goto out;
95294+#endif
95295+
95296 /*
95297 * Make sure the vma is shared, that it supports prefaulting,
95298 * and that the remapped range is valid and fully within
95299diff --git a/mm/gup.c b/mm/gup.c
95300index cd62c8c..3bb2053 100644
95301--- a/mm/gup.c
95302+++ b/mm/gup.c
95303@@ -274,11 +274,6 @@ static int faultin_page(struct task_struct *tsk, struct vm_area_struct *vma,
95304 unsigned int fault_flags = 0;
95305 int ret;
95306
95307- /* For mlock, just skip the stack guard page. */
95308- if ((*flags & FOLL_MLOCK) &&
95309- (stack_guard_page_start(vma, address) ||
95310- stack_guard_page_end(vma, address + PAGE_SIZE)))
95311- return -ENOENT;
95312 if (*flags & FOLL_WRITE)
95313 fault_flags |= FAULT_FLAG_WRITE;
95314 if (nonblocking)
95315@@ -444,14 +439,14 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
95316 if (!(gup_flags & FOLL_FORCE))
95317 gup_flags |= FOLL_NUMA;
95318
95319- do {
95320+ while (nr_pages) {
95321 struct page *page;
95322 unsigned int foll_flags = gup_flags;
95323 unsigned int page_increm;
95324
95325 /* first iteration or cross vma bound */
95326 if (!vma || start >= vma->vm_end) {
95327- vma = find_extend_vma(mm, start);
95328+ vma = find_vma(mm, start);
95329 if (!vma && in_gate_area(mm, start)) {
95330 int ret;
95331 ret = get_gate_page(mm, start & PAGE_MASK,
95332@@ -463,7 +458,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
95333 goto next_page;
95334 }
95335
95336- if (!vma || check_vma_flags(vma, gup_flags))
95337+ if (!vma || start < vma->vm_start || check_vma_flags(vma, gup_flags))
95338 return i ? : -EFAULT;
95339 if (is_vm_hugetlb_page(vma)) {
95340 i = follow_hugetlb_page(mm, vma, pages, vmas,
95341@@ -518,7 +513,7 @@ next_page:
95342 i += page_increm;
95343 start += page_increm * PAGE_SIZE;
95344 nr_pages -= page_increm;
95345- } while (nr_pages);
95346+ }
95347 return i;
95348 }
95349 EXPORT_SYMBOL(__get_user_pages);
95350diff --git a/mm/highmem.c b/mm/highmem.c
95351index 123bcd3..0de52ba 100644
95352--- a/mm/highmem.c
95353+++ b/mm/highmem.c
95354@@ -195,8 +195,9 @@ static void flush_all_zero_pkmaps(void)
95355 * So no dangers, even with speculative execution.
95356 */
95357 page = pte_page(pkmap_page_table[i]);
95358+ pax_open_kernel();
95359 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
95360-
95361+ pax_close_kernel();
95362 set_page_address(page, NULL);
95363 need_flush = 1;
95364 }
95365@@ -259,9 +260,11 @@ start:
95366 }
95367 }
95368 vaddr = PKMAP_ADDR(last_pkmap_nr);
95369+
95370+ pax_open_kernel();
95371 set_pte_at(&init_mm, vaddr,
95372 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
95373-
95374+ pax_close_kernel();
95375 pkmap_count[last_pkmap_nr] = 1;
95376 set_page_address(page, (void *)vaddr);
95377
95378diff --git a/mm/hugetlb.c b/mm/hugetlb.c
95379index 9fd7227..5628939 100644
95380--- a/mm/hugetlb.c
95381+++ b/mm/hugetlb.c
95382@@ -2258,6 +2258,7 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
95383 struct ctl_table *table, int write,
95384 void __user *buffer, size_t *length, loff_t *ppos)
95385 {
95386+ ctl_table_no_const t;
95387 struct hstate *h = &default_hstate;
95388 unsigned long tmp = h->max_huge_pages;
95389 int ret;
95390@@ -2265,9 +2266,10 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
95391 if (!hugepages_supported())
95392 return -ENOTSUPP;
95393
95394- table->data = &tmp;
95395- table->maxlen = sizeof(unsigned long);
95396- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
95397+ t = *table;
95398+ t.data = &tmp;
95399+ t.maxlen = sizeof(unsigned long);
95400+ ret = proc_doulongvec_minmax(&t, write, buffer, length, ppos);
95401 if (ret)
95402 goto out;
95403
95404@@ -2302,6 +2304,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
95405 struct hstate *h = &default_hstate;
95406 unsigned long tmp;
95407 int ret;
95408+ ctl_table_no_const hugetlb_table;
95409
95410 if (!hugepages_supported())
95411 return -ENOTSUPP;
95412@@ -2311,9 +2314,10 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
95413 if (write && hstate_is_gigantic(h))
95414 return -EINVAL;
95415
95416- table->data = &tmp;
95417- table->maxlen = sizeof(unsigned long);
95418- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
95419+ hugetlb_table = *table;
95420+ hugetlb_table.data = &tmp;
95421+ hugetlb_table.maxlen = sizeof(unsigned long);
95422+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
95423 if (ret)
95424 goto out;
95425
95426@@ -2792,6 +2796,27 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
95427 mutex_unlock(&mapping->i_mmap_mutex);
95428 }
95429
95430+#ifdef CONFIG_PAX_SEGMEXEC
95431+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
95432+{
95433+ struct mm_struct *mm = vma->vm_mm;
95434+ struct vm_area_struct *vma_m;
95435+ unsigned long address_m;
95436+ pte_t *ptep_m;
95437+
95438+ vma_m = pax_find_mirror_vma(vma);
95439+ if (!vma_m)
95440+ return;
95441+
95442+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
95443+ address_m = address + SEGMEXEC_TASK_SIZE;
95444+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
95445+ get_page(page_m);
95446+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
95447+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
95448+}
95449+#endif
95450+
95451 /*
95452 * Hugetlb_cow() should be called with page lock of the original hugepage held.
95453 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
95454@@ -2903,6 +2928,11 @@ retry_avoidcopy:
95455 make_huge_pte(vma, new_page, 1));
95456 page_remove_rmap(old_page);
95457 hugepage_add_new_anon_rmap(new_page, vma, address);
95458+
95459+#ifdef CONFIG_PAX_SEGMEXEC
95460+ pax_mirror_huge_pte(vma, address, new_page);
95461+#endif
95462+
95463 /* Make the old page be freed below */
95464 new_page = old_page;
95465 }
95466@@ -3063,6 +3093,10 @@ retry:
95467 && (vma->vm_flags & VM_SHARED)));
95468 set_huge_pte_at(mm, address, ptep, new_pte);
95469
95470+#ifdef CONFIG_PAX_SEGMEXEC
95471+ pax_mirror_huge_pte(vma, address, page);
95472+#endif
95473+
95474 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
95475 /* Optimization, do the COW without a second fault */
95476 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
95477@@ -3129,6 +3163,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95478 struct hstate *h = hstate_vma(vma);
95479 struct address_space *mapping;
95480
95481+#ifdef CONFIG_PAX_SEGMEXEC
95482+ struct vm_area_struct *vma_m;
95483+#endif
95484+
95485 address &= huge_page_mask(h);
95486
95487 ptep = huge_pte_offset(mm, address);
95488@@ -3142,6 +3180,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95489 VM_FAULT_SET_HINDEX(hstate_index(h));
95490 }
95491
95492+#ifdef CONFIG_PAX_SEGMEXEC
95493+ vma_m = pax_find_mirror_vma(vma);
95494+ if (vma_m) {
95495+ unsigned long address_m;
95496+
95497+ if (vma->vm_start > vma_m->vm_start) {
95498+ address_m = address;
95499+ address -= SEGMEXEC_TASK_SIZE;
95500+ vma = vma_m;
95501+ h = hstate_vma(vma);
95502+ } else
95503+ address_m = address + SEGMEXEC_TASK_SIZE;
95504+
95505+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
95506+ return VM_FAULT_OOM;
95507+ address_m &= HPAGE_MASK;
95508+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
95509+ }
95510+#endif
95511+
95512 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
95513 if (!ptep)
95514 return VM_FAULT_OOM;
95515diff --git a/mm/internal.h b/mm/internal.h
95516index a4f90ba..fbdc32b 100644
95517--- a/mm/internal.h
95518+++ b/mm/internal.h
95519@@ -134,6 +134,7 @@ __find_buddy_index(unsigned long page_idx, unsigned int order)
95520
95521 extern int __isolate_free_page(struct page *page, unsigned int order);
95522 extern void __free_pages_bootmem(struct page *page, unsigned int order);
95523+extern void free_compound_page(struct page *page);
95524 extern void prep_compound_page(struct page *page, unsigned long order);
95525 #ifdef CONFIG_MEMORY_FAILURE
95526 extern bool is_free_buddy_page(struct page *page);
95527@@ -390,7 +391,7 @@ extern u32 hwpoison_filter_enable;
95528
95529 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
95530 unsigned long, unsigned long,
95531- unsigned long, unsigned long);
95532+ unsigned long, unsigned long) __intentional_overflow(-1);
95533
95534 extern void set_pageblock_order(void);
95535 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
95536diff --git a/mm/iov_iter.c b/mm/iov_iter.c
95537index e34a3cb..a810efe 100644
95538--- a/mm/iov_iter.c
95539+++ b/mm/iov_iter.c
95540@@ -307,7 +307,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
95541
95542 while (bytes) {
95543 char __user *buf = iov->iov_base + base;
95544- int copy = min(bytes, iov->iov_len - base);
95545+ size_t copy = min(bytes, iov->iov_len - base);
95546
95547 base = 0;
95548 left = __copy_from_user_inatomic(vaddr, buf, copy);
95549@@ -335,7 +335,7 @@ static size_t copy_from_user_atomic_iovec(struct page *page,
95550
95551 kaddr = kmap_atomic(page);
95552 if (likely(i->nr_segs == 1)) {
95553- int left;
95554+ size_t left;
95555 char __user *buf = i->iov->iov_base + i->iov_offset;
95556 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
95557 copied = bytes - left;
95558@@ -365,7 +365,7 @@ static void advance_iovec(struct iov_iter *i, size_t bytes)
95559 * zero-length segments (without overruning the iovec).
95560 */
95561 while (bytes || unlikely(i->count && !iov->iov_len)) {
95562- int copy;
95563+ size_t copy;
95564
95565 copy = min(bytes, iov->iov_len - base);
95566 BUG_ON(!i->count || i->count < copy);
95567diff --git a/mm/kmemleak.c b/mm/kmemleak.c
95568index 3cda50c..032ba634 100644
95569--- a/mm/kmemleak.c
95570+++ b/mm/kmemleak.c
95571@@ -364,7 +364,7 @@ static void print_unreferenced(struct seq_file *seq,
95572
95573 for (i = 0; i < object->trace_len; i++) {
95574 void *ptr = (void *)object->trace[i];
95575- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
95576+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
95577 }
95578 }
95579
95580@@ -1905,7 +1905,7 @@ static int __init kmemleak_late_init(void)
95581 return -ENOMEM;
95582 }
95583
95584- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
95585+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
95586 &kmemleak_fops);
95587 if (!dentry)
95588 pr_warning("Failed to create the debugfs kmemleak file\n");
95589diff --git a/mm/maccess.c b/mm/maccess.c
95590index d53adf9..03a24bf 100644
95591--- a/mm/maccess.c
95592+++ b/mm/maccess.c
95593@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
95594 set_fs(KERNEL_DS);
95595 pagefault_disable();
95596 ret = __copy_from_user_inatomic(dst,
95597- (__force const void __user *)src, size);
95598+ (const void __force_user *)src, size);
95599 pagefault_enable();
95600 set_fs(old_fs);
95601
95602@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
95603
95604 set_fs(KERNEL_DS);
95605 pagefault_disable();
95606- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
95607+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
95608 pagefault_enable();
95609 set_fs(old_fs);
95610
95611diff --git a/mm/madvise.c b/mm/madvise.c
95612index 0938b30..199abe8 100644
95613--- a/mm/madvise.c
95614+++ b/mm/madvise.c
95615@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
95616 pgoff_t pgoff;
95617 unsigned long new_flags = vma->vm_flags;
95618
95619+#ifdef CONFIG_PAX_SEGMEXEC
95620+ struct vm_area_struct *vma_m;
95621+#endif
95622+
95623 switch (behavior) {
95624 case MADV_NORMAL:
95625 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
95626@@ -126,6 +130,13 @@ success:
95627 /*
95628 * vm_flags is protected by the mmap_sem held in write mode.
95629 */
95630+
95631+#ifdef CONFIG_PAX_SEGMEXEC
95632+ vma_m = pax_find_mirror_vma(vma);
95633+ if (vma_m)
95634+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
95635+#endif
95636+
95637 vma->vm_flags = new_flags;
95638
95639 out:
95640@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
95641 struct vm_area_struct **prev,
95642 unsigned long start, unsigned long end)
95643 {
95644+
95645+#ifdef CONFIG_PAX_SEGMEXEC
95646+ struct vm_area_struct *vma_m;
95647+#endif
95648+
95649 *prev = vma;
95650 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
95651 return -EINVAL;
95652@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
95653 zap_page_range(vma, start, end - start, &details);
95654 } else
95655 zap_page_range(vma, start, end - start, NULL);
95656+
95657+#ifdef CONFIG_PAX_SEGMEXEC
95658+ vma_m = pax_find_mirror_vma(vma);
95659+ if (vma_m) {
95660+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
95661+ struct zap_details details = {
95662+ .nonlinear_vma = vma_m,
95663+ .last_index = ULONG_MAX,
95664+ };
95665+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
95666+ } else
95667+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
95668+ }
95669+#endif
95670+
95671 return 0;
95672 }
95673
95674@@ -488,6 +519,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
95675 if (end < start)
95676 return error;
95677
95678+#ifdef CONFIG_PAX_SEGMEXEC
95679+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
95680+ if (end > SEGMEXEC_TASK_SIZE)
95681+ return error;
95682+ } else
95683+#endif
95684+
95685+ if (end > TASK_SIZE)
95686+ return error;
95687+
95688 error = 0;
95689 if (end == start)
95690 return error;
95691diff --git a/mm/memory-failure.c b/mm/memory-failure.c
95692index 8639f6b..b623882a 100644
95693--- a/mm/memory-failure.c
95694+++ b/mm/memory-failure.c
95695@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
95696
95697 int sysctl_memory_failure_recovery __read_mostly = 1;
95698
95699-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
95700+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
95701
95702 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
95703
95704@@ -198,7 +198,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
95705 pfn, t->comm, t->pid);
95706 si.si_signo = SIGBUS;
95707 si.si_errno = 0;
95708- si.si_addr = (void *)addr;
95709+ si.si_addr = (void __user *)addr;
95710 #ifdef __ARCH_SI_TRAPNO
95711 si.si_trapno = trapno;
95712 #endif
95713@@ -791,7 +791,7 @@ static struct page_state {
95714 unsigned long res;
95715 char *msg;
95716 int (*action)(struct page *p, unsigned long pfn);
95717-} error_states[] = {
95718+} __do_const error_states[] = {
95719 { reserved, reserved, "reserved kernel", me_kernel },
95720 /*
95721 * free pages are specially detected outside this table:
95722@@ -1099,7 +1099,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
95723 nr_pages = 1 << compound_order(hpage);
95724 else /* normal page or thp */
95725 nr_pages = 1;
95726- atomic_long_add(nr_pages, &num_poisoned_pages);
95727+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
95728
95729 /*
95730 * We need/can do nothing about count=0 pages.
95731@@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
95732 if (PageHWPoison(hpage)) {
95733 if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
95734 || (p != hpage && TestSetPageHWPoison(hpage))) {
95735- atomic_long_sub(nr_pages, &num_poisoned_pages);
95736+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
95737 unlock_page(hpage);
95738 return 0;
95739 }
95740@@ -1196,14 +1196,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
95741 */
95742 if (!PageHWPoison(p)) {
95743 printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
95744- atomic_long_sub(nr_pages, &num_poisoned_pages);
95745+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
95746 put_page(hpage);
95747 res = 0;
95748 goto out;
95749 }
95750 if (hwpoison_filter(p)) {
95751 if (TestClearPageHWPoison(p))
95752- atomic_long_sub(nr_pages, &num_poisoned_pages);
95753+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
95754 unlock_page(hpage);
95755 put_page(hpage);
95756 return 0;
95757@@ -1433,7 +1433,7 @@ int unpoison_memory(unsigned long pfn)
95758 return 0;
95759 }
95760 if (TestClearPageHWPoison(p))
95761- atomic_long_dec(&num_poisoned_pages);
95762+ atomic_long_dec_unchecked(&num_poisoned_pages);
95763 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
95764 return 0;
95765 }
95766@@ -1447,7 +1447,7 @@ int unpoison_memory(unsigned long pfn)
95767 */
95768 if (TestClearPageHWPoison(page)) {
95769 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
95770- atomic_long_sub(nr_pages, &num_poisoned_pages);
95771+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
95772 freeit = 1;
95773 if (PageHuge(page))
95774 clear_page_hwpoison_huge_page(page);
95775@@ -1572,11 +1572,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
95776 if (PageHuge(page)) {
95777 set_page_hwpoison_huge_page(hpage);
95778 dequeue_hwpoisoned_huge_page(hpage);
95779- atomic_long_add(1 << compound_order(hpage),
95780+ atomic_long_add_unchecked(1 << compound_order(hpage),
95781 &num_poisoned_pages);
95782 } else {
95783 SetPageHWPoison(page);
95784- atomic_long_inc(&num_poisoned_pages);
95785+ atomic_long_inc_unchecked(&num_poisoned_pages);
95786 }
95787 }
95788 return ret;
95789@@ -1615,7 +1615,7 @@ static int __soft_offline_page(struct page *page, int flags)
95790 put_page(page);
95791 pr_info("soft_offline: %#lx: invalidated\n", pfn);
95792 SetPageHWPoison(page);
95793- atomic_long_inc(&num_poisoned_pages);
95794+ atomic_long_inc_unchecked(&num_poisoned_pages);
95795 return 0;
95796 }
95797
95798@@ -1666,7 +1666,7 @@ static int __soft_offline_page(struct page *page, int flags)
95799 if (!is_free_buddy_page(page))
95800 pr_info("soft offline: %#lx: page leaked\n",
95801 pfn);
95802- atomic_long_inc(&num_poisoned_pages);
95803+ atomic_long_inc_unchecked(&num_poisoned_pages);
95804 }
95805 } else {
95806 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
95807@@ -1736,11 +1736,11 @@ int soft_offline_page(struct page *page, int flags)
95808 if (PageHuge(page)) {
95809 set_page_hwpoison_huge_page(hpage);
95810 dequeue_hwpoisoned_huge_page(hpage);
95811- atomic_long_add(1 << compound_order(hpage),
95812+ atomic_long_add_unchecked(1 << compound_order(hpage),
95813 &num_poisoned_pages);
95814 } else {
95815 SetPageHWPoison(page);
95816- atomic_long_inc(&num_poisoned_pages);
95817+ atomic_long_inc_unchecked(&num_poisoned_pages);
95818 }
95819 }
95820 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
95821diff --git a/mm/memory.c b/mm/memory.c
95822index d5f2ae9..4d678b2 100644
95823--- a/mm/memory.c
95824+++ b/mm/memory.c
95825@@ -415,6 +415,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
95826 free_pte_range(tlb, pmd, addr);
95827 } while (pmd++, addr = next, addr != end);
95828
95829+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
95830 start &= PUD_MASK;
95831 if (start < floor)
95832 return;
95833@@ -429,6 +430,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
95834 pmd = pmd_offset(pud, start);
95835 pud_clear(pud);
95836 pmd_free_tlb(tlb, pmd, start);
95837+#endif
95838+
95839 }
95840
95841 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
95842@@ -448,6 +451,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
95843 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
95844 } while (pud++, addr = next, addr != end);
95845
95846+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
95847 start &= PGDIR_MASK;
95848 if (start < floor)
95849 return;
95850@@ -462,6 +466,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
95851 pud = pud_offset(pgd, start);
95852 pgd_clear(pgd);
95853 pud_free_tlb(tlb, pud, start);
95854+#endif
95855+
95856 }
95857
95858 /*
95859@@ -691,10 +697,10 @@ static void print_bad_pte(struct vm_area_struct *vma, unsigned long addr,
95860 * Choose text because data symbols depend on CONFIG_KALLSYMS_ALL=y
95861 */
95862 if (vma->vm_ops)
95863- printk(KERN_ALERT "vma->vm_ops->fault: %pSR\n",
95864+ printk(KERN_ALERT "vma->vm_ops->fault: %pAR\n",
95865 vma->vm_ops->fault);
95866 if (vma->vm_file)
95867- printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pSR\n",
95868+ printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pAR\n",
95869 vma->vm_file->f_op->mmap);
95870 dump_stack();
95871 add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
95872@@ -1501,6 +1507,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
95873 page_add_file_rmap(page);
95874 set_pte_at(mm, addr, pte, mk_pte(page, prot));
95875
95876+#ifdef CONFIG_PAX_SEGMEXEC
95877+ pax_mirror_file_pte(vma, addr, page, ptl);
95878+#endif
95879+
95880 retval = 0;
95881 pte_unmap_unlock(pte, ptl);
95882 return retval;
95883@@ -1545,9 +1555,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
95884 if (!page_count(page))
95885 return -EINVAL;
95886 if (!(vma->vm_flags & VM_MIXEDMAP)) {
95887+
95888+#ifdef CONFIG_PAX_SEGMEXEC
95889+ struct vm_area_struct *vma_m;
95890+#endif
95891+
95892 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
95893 BUG_ON(vma->vm_flags & VM_PFNMAP);
95894 vma->vm_flags |= VM_MIXEDMAP;
95895+
95896+#ifdef CONFIG_PAX_SEGMEXEC
95897+ vma_m = pax_find_mirror_vma(vma);
95898+ if (vma_m)
95899+ vma_m->vm_flags |= VM_MIXEDMAP;
95900+#endif
95901+
95902 }
95903 return insert_page(vma, addr, page, vma->vm_page_prot);
95904 }
95905@@ -1630,6 +1652,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
95906 unsigned long pfn)
95907 {
95908 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
95909+ BUG_ON(vma->vm_mirror);
95910
95911 if (addr < vma->vm_start || addr >= vma->vm_end)
95912 return -EFAULT;
95913@@ -1877,7 +1900,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
95914
95915 BUG_ON(pud_huge(*pud));
95916
95917- pmd = pmd_alloc(mm, pud, addr);
95918+ pmd = (mm == &init_mm) ?
95919+ pmd_alloc_kernel(mm, pud, addr) :
95920+ pmd_alloc(mm, pud, addr);
95921 if (!pmd)
95922 return -ENOMEM;
95923 do {
95924@@ -1897,7 +1922,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
95925 unsigned long next;
95926 int err;
95927
95928- pud = pud_alloc(mm, pgd, addr);
95929+ pud = (mm == &init_mm) ?
95930+ pud_alloc_kernel(mm, pgd, addr) :
95931+ pud_alloc(mm, pgd, addr);
95932 if (!pud)
95933 return -ENOMEM;
95934 do {
95935@@ -2019,6 +2046,186 @@ static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
95936 return ret;
95937 }
95938
95939+#ifdef CONFIG_PAX_SEGMEXEC
95940+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
95941+{
95942+ struct mm_struct *mm = vma->vm_mm;
95943+ spinlock_t *ptl;
95944+ pte_t *pte, entry;
95945+
95946+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
95947+ entry = *pte;
95948+ if (!pte_present(entry)) {
95949+ if (!pte_none(entry)) {
95950+ BUG_ON(pte_file(entry));
95951+ free_swap_and_cache(pte_to_swp_entry(entry));
95952+ pte_clear_not_present_full(mm, address, pte, 0);
95953+ }
95954+ } else {
95955+ struct page *page;
95956+
95957+ flush_cache_page(vma, address, pte_pfn(entry));
95958+ entry = ptep_clear_flush(vma, address, pte);
95959+ BUG_ON(pte_dirty(entry));
95960+ page = vm_normal_page(vma, address, entry);
95961+ if (page) {
95962+ update_hiwater_rss(mm);
95963+ if (PageAnon(page))
95964+ dec_mm_counter_fast(mm, MM_ANONPAGES);
95965+ else
95966+ dec_mm_counter_fast(mm, MM_FILEPAGES);
95967+ page_remove_rmap(page);
95968+ page_cache_release(page);
95969+ }
95970+ }
95971+ pte_unmap_unlock(pte, ptl);
95972+}
95973+
95974+/* PaX: if vma is mirrored, synchronize the mirror's PTE
95975+ *
95976+ * the ptl of the lower mapped page is held on entry and is not released on exit
95977+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
95978+ */
95979+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
95980+{
95981+ struct mm_struct *mm = vma->vm_mm;
95982+ unsigned long address_m;
95983+ spinlock_t *ptl_m;
95984+ struct vm_area_struct *vma_m;
95985+ pmd_t *pmd_m;
95986+ pte_t *pte_m, entry_m;
95987+
95988+ BUG_ON(!page_m || !PageAnon(page_m));
95989+
95990+ vma_m = pax_find_mirror_vma(vma);
95991+ if (!vma_m)
95992+ return;
95993+
95994+ BUG_ON(!PageLocked(page_m));
95995+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
95996+ address_m = address + SEGMEXEC_TASK_SIZE;
95997+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
95998+ pte_m = pte_offset_map(pmd_m, address_m);
95999+ ptl_m = pte_lockptr(mm, pmd_m);
96000+ if (ptl != ptl_m) {
96001+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96002+ if (!pte_none(*pte_m))
96003+ goto out;
96004+ }
96005+
96006+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
96007+ page_cache_get(page_m);
96008+ page_add_anon_rmap(page_m, vma_m, address_m);
96009+ inc_mm_counter_fast(mm, MM_ANONPAGES);
96010+ set_pte_at(mm, address_m, pte_m, entry_m);
96011+ update_mmu_cache(vma_m, address_m, pte_m);
96012+out:
96013+ if (ptl != ptl_m)
96014+ spin_unlock(ptl_m);
96015+ pte_unmap(pte_m);
96016+ unlock_page(page_m);
96017+}
96018+
96019+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
96020+{
96021+ struct mm_struct *mm = vma->vm_mm;
96022+ unsigned long address_m;
96023+ spinlock_t *ptl_m;
96024+ struct vm_area_struct *vma_m;
96025+ pmd_t *pmd_m;
96026+ pte_t *pte_m, entry_m;
96027+
96028+ BUG_ON(!page_m || PageAnon(page_m));
96029+
96030+ vma_m = pax_find_mirror_vma(vma);
96031+ if (!vma_m)
96032+ return;
96033+
96034+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96035+ address_m = address + SEGMEXEC_TASK_SIZE;
96036+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96037+ pte_m = pte_offset_map(pmd_m, address_m);
96038+ ptl_m = pte_lockptr(mm, pmd_m);
96039+ if (ptl != ptl_m) {
96040+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96041+ if (!pte_none(*pte_m))
96042+ goto out;
96043+ }
96044+
96045+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
96046+ page_cache_get(page_m);
96047+ page_add_file_rmap(page_m);
96048+ inc_mm_counter_fast(mm, MM_FILEPAGES);
96049+ set_pte_at(mm, address_m, pte_m, entry_m);
96050+ update_mmu_cache(vma_m, address_m, pte_m);
96051+out:
96052+ if (ptl != ptl_m)
96053+ spin_unlock(ptl_m);
96054+ pte_unmap(pte_m);
96055+}
96056+
96057+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
96058+{
96059+ struct mm_struct *mm = vma->vm_mm;
96060+ unsigned long address_m;
96061+ spinlock_t *ptl_m;
96062+ struct vm_area_struct *vma_m;
96063+ pmd_t *pmd_m;
96064+ pte_t *pte_m, entry_m;
96065+
96066+ vma_m = pax_find_mirror_vma(vma);
96067+ if (!vma_m)
96068+ return;
96069+
96070+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96071+ address_m = address + SEGMEXEC_TASK_SIZE;
96072+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96073+ pte_m = pte_offset_map(pmd_m, address_m);
96074+ ptl_m = pte_lockptr(mm, pmd_m);
96075+ if (ptl != ptl_m) {
96076+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96077+ if (!pte_none(*pte_m))
96078+ goto out;
96079+ }
96080+
96081+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
96082+ set_pte_at(mm, address_m, pte_m, entry_m);
96083+out:
96084+ if (ptl != ptl_m)
96085+ spin_unlock(ptl_m);
96086+ pte_unmap(pte_m);
96087+}
96088+
96089+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
96090+{
96091+ struct page *page_m;
96092+ pte_t entry;
96093+
96094+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
96095+ goto out;
96096+
96097+ entry = *pte;
96098+ page_m = vm_normal_page(vma, address, entry);
96099+ if (!page_m)
96100+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
96101+ else if (PageAnon(page_m)) {
96102+ if (pax_find_mirror_vma(vma)) {
96103+ pte_unmap_unlock(pte, ptl);
96104+ lock_page(page_m);
96105+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
96106+ if (pte_same(entry, *pte))
96107+ pax_mirror_anon_pte(vma, address, page_m, ptl);
96108+ else
96109+ unlock_page(page_m);
96110+ }
96111+ } else
96112+ pax_mirror_file_pte(vma, address, page_m, ptl);
96113+
96114+out:
96115+ pte_unmap_unlock(pte, ptl);
96116+}
96117+#endif
96118+
96119 /*
96120 * This routine handles present pages, when users try to write
96121 * to a shared page. It is done by copying the page to a new address
96122@@ -2218,6 +2425,12 @@ gotten:
96123 */
96124 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
96125 if (likely(pte_same(*page_table, orig_pte))) {
96126+
96127+#ifdef CONFIG_PAX_SEGMEXEC
96128+ if (pax_find_mirror_vma(vma))
96129+ BUG_ON(!trylock_page(new_page));
96130+#endif
96131+
96132 if (old_page) {
96133 if (!PageAnon(old_page)) {
96134 dec_mm_counter_fast(mm, MM_FILEPAGES);
96135@@ -2271,6 +2484,10 @@ gotten:
96136 page_remove_rmap(old_page);
96137 }
96138
96139+#ifdef CONFIG_PAX_SEGMEXEC
96140+ pax_mirror_anon_pte(vma, address, new_page, ptl);
96141+#endif
96142+
96143 /* Free the old page.. */
96144 new_page = old_page;
96145 ret |= VM_FAULT_WRITE;
96146@@ -2545,6 +2762,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
96147 swap_free(entry);
96148 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
96149 try_to_free_swap(page);
96150+
96151+#ifdef CONFIG_PAX_SEGMEXEC
96152+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
96153+#endif
96154+
96155 unlock_page(page);
96156 if (page != swapcache) {
96157 /*
96158@@ -2568,6 +2790,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
96159
96160 /* No need to invalidate - it was non-present before */
96161 update_mmu_cache(vma, address, page_table);
96162+
96163+#ifdef CONFIG_PAX_SEGMEXEC
96164+ pax_mirror_anon_pte(vma, address, page, ptl);
96165+#endif
96166+
96167 unlock:
96168 pte_unmap_unlock(page_table, ptl);
96169 out:
96170@@ -2587,40 +2814,6 @@ out_release:
96171 }
96172
96173 /*
96174- * This is like a special single-page "expand_{down|up}wards()",
96175- * except we must first make sure that 'address{-|+}PAGE_SIZE'
96176- * doesn't hit another vma.
96177- */
96178-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
96179-{
96180- address &= PAGE_MASK;
96181- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
96182- struct vm_area_struct *prev = vma->vm_prev;
96183-
96184- /*
96185- * Is there a mapping abutting this one below?
96186- *
96187- * That's only ok if it's the same stack mapping
96188- * that has gotten split..
96189- */
96190- if (prev && prev->vm_end == address)
96191- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
96192-
96193- expand_downwards(vma, address - PAGE_SIZE);
96194- }
96195- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
96196- struct vm_area_struct *next = vma->vm_next;
96197-
96198- /* As VM_GROWSDOWN but s/below/above/ */
96199- if (next && next->vm_start == address + PAGE_SIZE)
96200- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
96201-
96202- expand_upwards(vma, address + PAGE_SIZE);
96203- }
96204- return 0;
96205-}
96206-
96207-/*
96208 * We enter with non-exclusive mmap_sem (to exclude vma changes,
96209 * but allow concurrent faults), and pte mapped but not yet locked.
96210 * We return with mmap_sem still held, but pte unmapped and unlocked.
96211@@ -2630,27 +2823,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
96212 unsigned int flags)
96213 {
96214 struct mem_cgroup *memcg;
96215- struct page *page;
96216+ struct page *page = NULL;
96217 spinlock_t *ptl;
96218 pte_t entry;
96219
96220- pte_unmap(page_table);
96221-
96222- /* Check if we need to add a guard page to the stack */
96223- if (check_stack_guard_page(vma, address) < 0)
96224- return VM_FAULT_SIGBUS;
96225-
96226- /* Use the zero-page for reads */
96227 if (!(flags & FAULT_FLAG_WRITE)) {
96228 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
96229 vma->vm_page_prot));
96230- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
96231+ ptl = pte_lockptr(mm, pmd);
96232+ spin_lock(ptl);
96233 if (!pte_none(*page_table))
96234 goto unlock;
96235 goto setpte;
96236 }
96237
96238 /* Allocate our own private page. */
96239+ pte_unmap(page_table);
96240+
96241 if (unlikely(anon_vma_prepare(vma)))
96242 goto oom;
96243 page = alloc_zeroed_user_highpage_movable(vma, address);
96244@@ -2674,6 +2863,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
96245 if (!pte_none(*page_table))
96246 goto release;
96247
96248+#ifdef CONFIG_PAX_SEGMEXEC
96249+ if (pax_find_mirror_vma(vma))
96250+ BUG_ON(!trylock_page(page));
96251+#endif
96252+
96253 inc_mm_counter_fast(mm, MM_ANONPAGES);
96254 page_add_new_anon_rmap(page, vma, address);
96255 mem_cgroup_commit_charge(page, memcg, false);
96256@@ -2683,6 +2877,12 @@ setpte:
96257
96258 /* No need to invalidate - it was non-present before */
96259 update_mmu_cache(vma, address, page_table);
96260+
96261+#ifdef CONFIG_PAX_SEGMEXEC
96262+ if (page)
96263+ pax_mirror_anon_pte(vma, address, page, ptl);
96264+#endif
96265+
96266 unlock:
96267 pte_unmap_unlock(page_table, ptl);
96268 return 0;
96269@@ -2913,6 +3113,11 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96270 return ret;
96271 }
96272 do_set_pte(vma, address, fault_page, pte, false, false);
96273+
96274+#ifdef CONFIG_PAX_SEGMEXEC
96275+ pax_mirror_file_pte(vma, address, fault_page, ptl);
96276+#endif
96277+
96278 unlock_page(fault_page);
96279 unlock_out:
96280 pte_unmap_unlock(pte, ptl);
96281@@ -2955,7 +3160,18 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96282 page_cache_release(fault_page);
96283 goto uncharge_out;
96284 }
96285+
96286+#ifdef CONFIG_PAX_SEGMEXEC
96287+ if (pax_find_mirror_vma(vma))
96288+ BUG_ON(!trylock_page(new_page));
96289+#endif
96290+
96291 do_set_pte(vma, address, new_page, pte, true, true);
96292+
96293+#ifdef CONFIG_PAX_SEGMEXEC
96294+ pax_mirror_anon_pte(vma, address, new_page, ptl);
96295+#endif
96296+
96297 mem_cgroup_commit_charge(new_page, memcg, false);
96298 lru_cache_add_active_or_unevictable(new_page, vma);
96299 pte_unmap_unlock(pte, ptl);
96300@@ -3005,6 +3221,11 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96301 return ret;
96302 }
96303 do_set_pte(vma, address, fault_page, pte, true, false);
96304+
96305+#ifdef CONFIG_PAX_SEGMEXEC
96306+ pax_mirror_file_pte(vma, address, fault_page, ptl);
96307+#endif
96308+
96309 pte_unmap_unlock(pte, ptl);
96310
96311 if (set_page_dirty(fault_page))
96312@@ -3246,6 +3467,12 @@ static int handle_pte_fault(struct mm_struct *mm,
96313 if (flags & FAULT_FLAG_WRITE)
96314 flush_tlb_fix_spurious_fault(vma, address);
96315 }
96316+
96317+#ifdef CONFIG_PAX_SEGMEXEC
96318+ pax_mirror_pte(vma, address, pte, pmd, ptl);
96319+ return 0;
96320+#endif
96321+
96322 unlock:
96323 pte_unmap_unlock(pte, ptl);
96324 return 0;
96325@@ -3265,9 +3492,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96326 pmd_t *pmd;
96327 pte_t *pte;
96328
96329+#ifdef CONFIG_PAX_SEGMEXEC
96330+ struct vm_area_struct *vma_m;
96331+#endif
96332+
96333 if (unlikely(is_vm_hugetlb_page(vma)))
96334 return hugetlb_fault(mm, vma, address, flags);
96335
96336+#ifdef CONFIG_PAX_SEGMEXEC
96337+ vma_m = pax_find_mirror_vma(vma);
96338+ if (vma_m) {
96339+ unsigned long address_m;
96340+ pgd_t *pgd_m;
96341+ pud_t *pud_m;
96342+ pmd_t *pmd_m;
96343+
96344+ if (vma->vm_start > vma_m->vm_start) {
96345+ address_m = address;
96346+ address -= SEGMEXEC_TASK_SIZE;
96347+ vma = vma_m;
96348+ } else
96349+ address_m = address + SEGMEXEC_TASK_SIZE;
96350+
96351+ pgd_m = pgd_offset(mm, address_m);
96352+ pud_m = pud_alloc(mm, pgd_m, address_m);
96353+ if (!pud_m)
96354+ return VM_FAULT_OOM;
96355+ pmd_m = pmd_alloc(mm, pud_m, address_m);
96356+ if (!pmd_m)
96357+ return VM_FAULT_OOM;
96358+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
96359+ return VM_FAULT_OOM;
96360+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
96361+ }
96362+#endif
96363+
96364 pgd = pgd_offset(mm, address);
96365 pud = pud_alloc(mm, pgd, address);
96366 if (!pud)
96367@@ -3401,6 +3660,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
96368 spin_unlock(&mm->page_table_lock);
96369 return 0;
96370 }
96371+
96372+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
96373+{
96374+ pud_t *new = pud_alloc_one(mm, address);
96375+ if (!new)
96376+ return -ENOMEM;
96377+
96378+ smp_wmb(); /* See comment in __pte_alloc */
96379+
96380+ spin_lock(&mm->page_table_lock);
96381+ if (pgd_present(*pgd)) /* Another has populated it */
96382+ pud_free(mm, new);
96383+ else
96384+ pgd_populate_kernel(mm, pgd, new);
96385+ spin_unlock(&mm->page_table_lock);
96386+ return 0;
96387+}
96388 #endif /* __PAGETABLE_PUD_FOLDED */
96389
96390 #ifndef __PAGETABLE_PMD_FOLDED
96391@@ -3431,6 +3707,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
96392 spin_unlock(&mm->page_table_lock);
96393 return 0;
96394 }
96395+
96396+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
96397+{
96398+ pmd_t *new = pmd_alloc_one(mm, address);
96399+ if (!new)
96400+ return -ENOMEM;
96401+
96402+ smp_wmb(); /* See comment in __pte_alloc */
96403+
96404+ spin_lock(&mm->page_table_lock);
96405+#ifndef __ARCH_HAS_4LEVEL_HACK
96406+ if (pud_present(*pud)) /* Another has populated it */
96407+ pmd_free(mm, new);
96408+ else
96409+ pud_populate_kernel(mm, pud, new);
96410+#else
96411+ if (pgd_present(*pud)) /* Another has populated it */
96412+ pmd_free(mm, new);
96413+ else
96414+ pgd_populate_kernel(mm, pud, new);
96415+#endif /* __ARCH_HAS_4LEVEL_HACK */
96416+ spin_unlock(&mm->page_table_lock);
96417+ return 0;
96418+}
96419 #endif /* __PAGETABLE_PMD_FOLDED */
96420
96421 static int __follow_pte(struct mm_struct *mm, unsigned long address,
96422@@ -3540,8 +3840,8 @@ out:
96423 return ret;
96424 }
96425
96426-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
96427- void *buf, int len, int write)
96428+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
96429+ void *buf, size_t len, int write)
96430 {
96431 resource_size_t phys_addr;
96432 unsigned long prot = 0;
96433@@ -3567,8 +3867,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
96434 * Access another process' address space as given in mm. If non-NULL, use the
96435 * given task for page fault accounting.
96436 */
96437-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96438- unsigned long addr, void *buf, int len, int write)
96439+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96440+ unsigned long addr, void *buf, size_t len, int write)
96441 {
96442 struct vm_area_struct *vma;
96443 void *old_buf = buf;
96444@@ -3576,7 +3876,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96445 down_read(&mm->mmap_sem);
96446 /* ignore errors, just check how much was successfully transferred */
96447 while (len) {
96448- int bytes, ret, offset;
96449+ ssize_t bytes, ret, offset;
96450 void *maddr;
96451 struct page *page = NULL;
96452
96453@@ -3637,8 +3937,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96454 *
96455 * The caller must hold a reference on @mm.
96456 */
96457-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
96458- void *buf, int len, int write)
96459+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
96460+ void *buf, size_t len, int write)
96461 {
96462 return __access_remote_vm(NULL, mm, addr, buf, len, write);
96463 }
96464@@ -3648,11 +3948,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
96465 * Source/target buffer must be kernel space,
96466 * Do not walk the page table directly, use get_user_pages
96467 */
96468-int access_process_vm(struct task_struct *tsk, unsigned long addr,
96469- void *buf, int len, int write)
96470+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
96471+ void *buf, size_t len, int write)
96472 {
96473 struct mm_struct *mm;
96474- int ret;
96475+ ssize_t ret;
96476
96477 mm = get_task_mm(tsk);
96478 if (!mm)
96479diff --git a/mm/mempolicy.c b/mm/mempolicy.c
96480index e58725a..e0be017 100644
96481--- a/mm/mempolicy.c
96482+++ b/mm/mempolicy.c
96483@@ -750,6 +750,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
96484 unsigned long vmstart;
96485 unsigned long vmend;
96486
96487+#ifdef CONFIG_PAX_SEGMEXEC
96488+ struct vm_area_struct *vma_m;
96489+#endif
96490+
96491 vma = find_vma(mm, start);
96492 if (!vma || vma->vm_start > start)
96493 return -EFAULT;
96494@@ -793,6 +797,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
96495 err = vma_replace_policy(vma, new_pol);
96496 if (err)
96497 goto out;
96498+
96499+#ifdef CONFIG_PAX_SEGMEXEC
96500+ vma_m = pax_find_mirror_vma(vma);
96501+ if (vma_m) {
96502+ err = vma_replace_policy(vma_m, new_pol);
96503+ if (err)
96504+ goto out;
96505+ }
96506+#endif
96507+
96508 }
96509
96510 out:
96511@@ -1212,6 +1226,17 @@ static long do_mbind(unsigned long start, unsigned long len,
96512
96513 if (end < start)
96514 return -EINVAL;
96515+
96516+#ifdef CONFIG_PAX_SEGMEXEC
96517+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
96518+ if (end > SEGMEXEC_TASK_SIZE)
96519+ return -EINVAL;
96520+ } else
96521+#endif
96522+
96523+ if (end > TASK_SIZE)
96524+ return -EINVAL;
96525+
96526 if (end == start)
96527 return 0;
96528
96529@@ -1437,8 +1462,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
96530 */
96531 tcred = __task_cred(task);
96532 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
96533- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
96534- !capable(CAP_SYS_NICE)) {
96535+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
96536 rcu_read_unlock();
96537 err = -EPERM;
96538 goto out_put;
96539@@ -1469,6 +1493,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
96540 goto out;
96541 }
96542
96543+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
96544+ if (mm != current->mm &&
96545+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
96546+ mmput(mm);
96547+ err = -EPERM;
96548+ goto out;
96549+ }
96550+#endif
96551+
96552 err = do_migrate_pages(mm, old, new,
96553 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
96554
96555diff --git a/mm/migrate.c b/mm/migrate.c
96556index 0143995..b294728 100644
96557--- a/mm/migrate.c
96558+++ b/mm/migrate.c
96559@@ -1495,8 +1495,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
96560 */
96561 tcred = __task_cred(task);
96562 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
96563- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
96564- !capable(CAP_SYS_NICE)) {
96565+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
96566 rcu_read_unlock();
96567 err = -EPERM;
96568 goto out;
96569diff --git a/mm/mlock.c b/mm/mlock.c
96570index 73cf098..ab547c7 100644
96571--- a/mm/mlock.c
96572+++ b/mm/mlock.c
96573@@ -14,6 +14,7 @@
96574 #include <linux/pagevec.h>
96575 #include <linux/mempolicy.h>
96576 #include <linux/syscalls.h>
96577+#include <linux/security.h>
96578 #include <linux/sched.h>
96579 #include <linux/export.h>
96580 #include <linux/rmap.h>
96581@@ -613,7 +614,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
96582 {
96583 unsigned long nstart, end, tmp;
96584 struct vm_area_struct * vma, * prev;
96585- int error;
96586+ int error = 0;
96587
96588 VM_BUG_ON(start & ~PAGE_MASK);
96589 VM_BUG_ON(len != PAGE_ALIGN(len));
96590@@ -622,6 +623,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
96591 return -EINVAL;
96592 if (end == start)
96593 return 0;
96594+ if (end > TASK_SIZE)
96595+ return -EINVAL;
96596+
96597 vma = find_vma(current->mm, start);
96598 if (!vma || vma->vm_start > start)
96599 return -ENOMEM;
96600@@ -633,6 +637,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
96601 for (nstart = start ; ; ) {
96602 vm_flags_t newflags;
96603
96604+#ifdef CONFIG_PAX_SEGMEXEC
96605+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
96606+ break;
96607+#endif
96608+
96609 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
96610
96611 newflags = vma->vm_flags & ~VM_LOCKED;
96612@@ -746,6 +755,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
96613 locked += current->mm->locked_vm;
96614
96615 /* check against resource limits */
96616+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
96617 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
96618 error = do_mlock(start, len, 1);
96619
96620@@ -783,6 +793,11 @@ static int do_mlockall(int flags)
96621 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
96622 vm_flags_t newflags;
96623
96624+#ifdef CONFIG_PAX_SEGMEXEC
96625+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
96626+ break;
96627+#endif
96628+
96629 newflags = vma->vm_flags & ~VM_LOCKED;
96630 if (flags & MCL_CURRENT)
96631 newflags |= VM_LOCKED;
96632@@ -814,8 +829,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
96633 lock_limit >>= PAGE_SHIFT;
96634
96635 ret = -ENOMEM;
96636+
96637+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
96638+
96639 down_write(&current->mm->mmap_sem);
96640-
96641 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
96642 capable(CAP_IPC_LOCK))
96643 ret = do_mlockall(flags);
96644diff --git a/mm/mmap.c b/mm/mmap.c
96645index ae91989..d8308c7 100644
96646--- a/mm/mmap.c
96647+++ b/mm/mmap.c
96648@@ -41,6 +41,7 @@
96649 #include <linux/notifier.h>
96650 #include <linux/memory.h>
96651 #include <linux/printk.h>
96652+#include <linux/random.h>
96653
96654 #include <asm/uaccess.h>
96655 #include <asm/cacheflush.h>
96656@@ -57,6 +58,16 @@
96657 #define arch_rebalance_pgtables(addr, len) (addr)
96658 #endif
96659
96660+static inline void verify_mm_writelocked(struct mm_struct *mm)
96661+{
96662+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
96663+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
96664+ up_read(&mm->mmap_sem);
96665+ BUG();
96666+ }
96667+#endif
96668+}
96669+
96670 static void unmap_region(struct mm_struct *mm,
96671 struct vm_area_struct *vma, struct vm_area_struct *prev,
96672 unsigned long start, unsigned long end);
96673@@ -76,16 +87,25 @@ static void unmap_region(struct mm_struct *mm,
96674 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
96675 *
96676 */
96677-pgprot_t protection_map[16] = {
96678+pgprot_t protection_map[16] __read_only = {
96679 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
96680 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
96681 };
96682
96683-pgprot_t vm_get_page_prot(unsigned long vm_flags)
96684+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
96685 {
96686- return __pgprot(pgprot_val(protection_map[vm_flags &
96687+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
96688 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
96689 pgprot_val(arch_vm_get_page_prot(vm_flags)));
96690+
96691+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
96692+ if (!(__supported_pte_mask & _PAGE_NX) &&
96693+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
96694+ (vm_flags & (VM_READ | VM_WRITE)))
96695+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
96696+#endif
96697+
96698+ return prot;
96699 }
96700 EXPORT_SYMBOL(vm_get_page_prot);
96701
96702@@ -114,6 +134,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
96703 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
96704 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
96705 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
96706+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
96707 /*
96708 * Make sure vm_committed_as in one cacheline and not cacheline shared with
96709 * other variables. It can be updated by several CPUs frequently.
96710@@ -274,6 +295,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
96711 struct vm_area_struct *next = vma->vm_next;
96712
96713 might_sleep();
96714+ BUG_ON(vma->vm_mirror);
96715 if (vma->vm_ops && vma->vm_ops->close)
96716 vma->vm_ops->close(vma);
96717 if (vma->vm_file)
96718@@ -287,6 +309,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len);
96719
96720 SYSCALL_DEFINE1(brk, unsigned long, brk)
96721 {
96722+ unsigned long rlim;
96723 unsigned long retval;
96724 unsigned long newbrk, oldbrk;
96725 struct mm_struct *mm = current->mm;
96726@@ -317,7 +340,13 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
96727 * segment grow beyond its set limit the in case where the limit is
96728 * not page aligned -Ram Gupta
96729 */
96730- if (check_data_rlimit(rlimit(RLIMIT_DATA), brk, mm->start_brk,
96731+ rlim = rlimit(RLIMIT_DATA);
96732+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
96733+ /* force a minimum 16MB brk heap on setuid/setgid binaries */
96734+ if (rlim < PAGE_SIZE && (get_dumpable(mm) != SUID_DUMP_USER) && gr_is_global_nonroot(current_uid()))
96735+ rlim = 4096 * PAGE_SIZE;
96736+#endif
96737+ if (check_data_rlimit(rlim, brk, mm->start_brk,
96738 mm->end_data, mm->start_data))
96739 goto out;
96740
96741@@ -976,6 +1005,12 @@ static int
96742 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
96743 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
96744 {
96745+
96746+#ifdef CONFIG_PAX_SEGMEXEC
96747+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
96748+ return 0;
96749+#endif
96750+
96751 if (is_mergeable_vma(vma, file, vm_flags) &&
96752 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
96753 if (vma->vm_pgoff == vm_pgoff)
96754@@ -995,6 +1030,12 @@ static int
96755 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
96756 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
96757 {
96758+
96759+#ifdef CONFIG_PAX_SEGMEXEC
96760+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
96761+ return 0;
96762+#endif
96763+
96764 if (is_mergeable_vma(vma, file, vm_flags) &&
96765 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
96766 pgoff_t vm_pglen;
96767@@ -1044,6 +1085,13 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
96768 struct vm_area_struct *area, *next;
96769 int err;
96770
96771+#ifdef CONFIG_PAX_SEGMEXEC
96772+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
96773+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
96774+
96775+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
96776+#endif
96777+
96778 /*
96779 * We later require that vma->vm_flags == vm_flags,
96780 * so this tests vma->vm_flags & VM_SPECIAL, too.
96781@@ -1059,6 +1107,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
96782 if (next && next->vm_end == end) /* cases 6, 7, 8 */
96783 next = next->vm_next;
96784
96785+#ifdef CONFIG_PAX_SEGMEXEC
96786+ if (prev)
96787+ prev_m = pax_find_mirror_vma(prev);
96788+ if (area)
96789+ area_m = pax_find_mirror_vma(area);
96790+ if (next)
96791+ next_m = pax_find_mirror_vma(next);
96792+#endif
96793+
96794 /*
96795 * Can it merge with the predecessor?
96796 */
96797@@ -1078,9 +1135,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
96798 /* cases 1, 6 */
96799 err = vma_adjust(prev, prev->vm_start,
96800 next->vm_end, prev->vm_pgoff, NULL);
96801- } else /* cases 2, 5, 7 */
96802+
96803+#ifdef CONFIG_PAX_SEGMEXEC
96804+ if (!err && prev_m)
96805+ err = vma_adjust(prev_m, prev_m->vm_start,
96806+ next_m->vm_end, prev_m->vm_pgoff, NULL);
96807+#endif
96808+
96809+ } else { /* cases 2, 5, 7 */
96810 err = vma_adjust(prev, prev->vm_start,
96811 end, prev->vm_pgoff, NULL);
96812+
96813+#ifdef CONFIG_PAX_SEGMEXEC
96814+ if (!err && prev_m)
96815+ err = vma_adjust(prev_m, prev_m->vm_start,
96816+ end_m, prev_m->vm_pgoff, NULL);
96817+#endif
96818+
96819+ }
96820 if (err)
96821 return NULL;
96822 khugepaged_enter_vma_merge(prev, vm_flags);
96823@@ -1094,12 +1166,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
96824 mpol_equal(policy, vma_policy(next)) &&
96825 can_vma_merge_before(next, vm_flags,
96826 anon_vma, file, pgoff+pglen)) {
96827- if (prev && addr < prev->vm_end) /* case 4 */
96828+ if (prev && addr < prev->vm_end) { /* case 4 */
96829 err = vma_adjust(prev, prev->vm_start,
96830 addr, prev->vm_pgoff, NULL);
96831- else /* cases 3, 8 */
96832+
96833+#ifdef CONFIG_PAX_SEGMEXEC
96834+ if (!err && prev_m)
96835+ err = vma_adjust(prev_m, prev_m->vm_start,
96836+ addr_m, prev_m->vm_pgoff, NULL);
96837+#endif
96838+
96839+ } else { /* cases 3, 8 */
96840 err = vma_adjust(area, addr, next->vm_end,
96841 next->vm_pgoff - pglen, NULL);
96842+
96843+#ifdef CONFIG_PAX_SEGMEXEC
96844+ if (!err && area_m)
96845+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
96846+ next_m->vm_pgoff - pglen, NULL);
96847+#endif
96848+
96849+ }
96850 if (err)
96851 return NULL;
96852 khugepaged_enter_vma_merge(area, vm_flags);
96853@@ -1208,8 +1295,10 @@ none:
96854 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
96855 struct file *file, long pages)
96856 {
96857- const unsigned long stack_flags
96858- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
96859+
96860+#ifdef CONFIG_PAX_RANDMMAP
96861+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
96862+#endif
96863
96864 mm->total_vm += pages;
96865
96866@@ -1217,7 +1306,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
96867 mm->shared_vm += pages;
96868 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
96869 mm->exec_vm += pages;
96870- } else if (flags & stack_flags)
96871+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
96872 mm->stack_vm += pages;
96873 }
96874 #endif /* CONFIG_PROC_FS */
96875@@ -1247,6 +1336,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
96876 locked += mm->locked_vm;
96877 lock_limit = rlimit(RLIMIT_MEMLOCK);
96878 lock_limit >>= PAGE_SHIFT;
96879+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
96880 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
96881 return -EAGAIN;
96882 }
96883@@ -1273,7 +1363,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
96884 * (the exception is when the underlying filesystem is noexec
96885 * mounted, in which case we dont add PROT_EXEC.)
96886 */
96887- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
96888+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
96889 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
96890 prot |= PROT_EXEC;
96891
96892@@ -1299,7 +1389,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
96893 /* Obtain the address to map to. we verify (or select) it and ensure
96894 * that it represents a valid section of the address space.
96895 */
96896- addr = get_unmapped_area(file, addr, len, pgoff, flags);
96897+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
96898 if (addr & ~PAGE_MASK)
96899 return addr;
96900
96901@@ -1310,6 +1400,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
96902 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
96903 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
96904
96905+#ifdef CONFIG_PAX_MPROTECT
96906+ if (mm->pax_flags & MF_PAX_MPROTECT) {
96907+
96908+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
96909+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
96910+ mm->binfmt->handle_mmap)
96911+ mm->binfmt->handle_mmap(file);
96912+#endif
96913+
96914+#ifndef CONFIG_PAX_MPROTECT_COMPAT
96915+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
96916+ gr_log_rwxmmap(file);
96917+
96918+#ifdef CONFIG_PAX_EMUPLT
96919+ vm_flags &= ~VM_EXEC;
96920+#else
96921+ return -EPERM;
96922+#endif
96923+
96924+ }
96925+
96926+ if (!(vm_flags & VM_EXEC))
96927+ vm_flags &= ~VM_MAYEXEC;
96928+#else
96929+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
96930+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
96931+#endif
96932+ else
96933+ vm_flags &= ~VM_MAYWRITE;
96934+ }
96935+#endif
96936+
96937+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
96938+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
96939+ vm_flags &= ~VM_PAGEEXEC;
96940+#endif
96941+
96942 if (flags & MAP_LOCKED)
96943 if (!can_do_mlock())
96944 return -EPERM;
96945@@ -1397,6 +1524,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
96946 vm_flags |= VM_NORESERVE;
96947 }
96948
96949+ if (!gr_acl_handle_mmap(file, prot))
96950+ return -EACCES;
96951+
96952 addr = mmap_region(file, addr, len, vm_flags, pgoff);
96953 if (!IS_ERR_VALUE(addr) &&
96954 ((vm_flags & VM_LOCKED) ||
96955@@ -1490,7 +1620,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
96956 vm_flags_t vm_flags = vma->vm_flags;
96957
96958 /* If it was private or non-writable, the write bit is already clear */
96959- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
96960+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
96961 return 0;
96962
96963 /* The backer wishes to know when pages are first written to? */
96964@@ -1541,7 +1671,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
96965 struct rb_node **rb_link, *rb_parent;
96966 unsigned long charged = 0;
96967
96968+#ifdef CONFIG_PAX_SEGMEXEC
96969+ struct vm_area_struct *vma_m = NULL;
96970+#endif
96971+
96972+ /*
96973+ * mm->mmap_sem is required to protect against another thread
96974+ * changing the mappings in case we sleep.
96975+ */
96976+ verify_mm_writelocked(mm);
96977+
96978 /* Check against address space limit. */
96979+
96980+#ifdef CONFIG_PAX_RANDMMAP
96981+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
96982+#endif
96983+
96984 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
96985 unsigned long nr_pages;
96986
96987@@ -1560,11 +1705,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
96988
96989 /* Clear old maps */
96990 error = -ENOMEM;
96991-munmap_back:
96992 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
96993 if (do_munmap(mm, addr, len))
96994 return -ENOMEM;
96995- goto munmap_back;
96996+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
96997 }
96998
96999 /*
97000@@ -1595,6 +1739,16 @@ munmap_back:
97001 goto unacct_error;
97002 }
97003
97004+#ifdef CONFIG_PAX_SEGMEXEC
97005+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
97006+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
97007+ if (!vma_m) {
97008+ error = -ENOMEM;
97009+ goto free_vma;
97010+ }
97011+ }
97012+#endif
97013+
97014 vma->vm_mm = mm;
97015 vma->vm_start = addr;
97016 vma->vm_end = addr + len;
97017@@ -1625,6 +1779,13 @@ munmap_back:
97018 if (error)
97019 goto unmap_and_free_vma;
97020
97021+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
97022+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
97023+ vma->vm_flags |= VM_PAGEEXEC;
97024+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
97025+ }
97026+#endif
97027+
97028 /* Can addr have changed??
97029 *
97030 * Answer: Yes, several device drivers can do it in their
97031@@ -1643,6 +1804,12 @@ munmap_back:
97032 }
97033
97034 vma_link(mm, vma, prev, rb_link, rb_parent);
97035+
97036+#ifdef CONFIG_PAX_SEGMEXEC
97037+ if (vma_m)
97038+ BUG_ON(pax_mirror_vma(vma_m, vma));
97039+#endif
97040+
97041 /* Once vma denies write, undo our temporary denial count */
97042 if (file) {
97043 if (vm_flags & VM_SHARED)
97044@@ -1655,6 +1822,7 @@ out:
97045 perf_event_mmap(vma);
97046
97047 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
97048+ track_exec_limit(mm, addr, addr + len, vm_flags);
97049 if (vm_flags & VM_LOCKED) {
97050 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
97051 vma == get_gate_vma(current->mm)))
97052@@ -1692,6 +1860,12 @@ allow_write_and_free_vma:
97053 if (vm_flags & VM_DENYWRITE)
97054 allow_write_access(file);
97055 free_vma:
97056+
97057+#ifdef CONFIG_PAX_SEGMEXEC
97058+ if (vma_m)
97059+ kmem_cache_free(vm_area_cachep, vma_m);
97060+#endif
97061+
97062 kmem_cache_free(vm_area_cachep, vma);
97063 unacct_error:
97064 if (charged)
97065@@ -1699,7 +1873,63 @@ unacct_error:
97066 return error;
97067 }
97068
97069-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
97070+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
97071+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
97072+{
97073+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
97074+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
97075+
97076+ return 0;
97077+}
97078+#endif
97079+
97080+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
97081+{
97082+ if (!vma) {
97083+#ifdef CONFIG_STACK_GROWSUP
97084+ if (addr > sysctl_heap_stack_gap)
97085+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
97086+ else
97087+ vma = find_vma(current->mm, 0);
97088+ if (vma && (vma->vm_flags & VM_GROWSUP))
97089+ return false;
97090+#endif
97091+ return true;
97092+ }
97093+
97094+ if (addr + len > vma->vm_start)
97095+ return false;
97096+
97097+ if (vma->vm_flags & VM_GROWSDOWN)
97098+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
97099+#ifdef CONFIG_STACK_GROWSUP
97100+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
97101+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
97102+#endif
97103+ else if (offset)
97104+ return offset <= vma->vm_start - addr - len;
97105+
97106+ return true;
97107+}
97108+
97109+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
97110+{
97111+ if (vma->vm_start < len)
97112+ return -ENOMEM;
97113+
97114+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
97115+ if (offset <= vma->vm_start - len)
97116+ return vma->vm_start - len - offset;
97117+ else
97118+ return -ENOMEM;
97119+ }
97120+
97121+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
97122+ return vma->vm_start - len - sysctl_heap_stack_gap;
97123+ return -ENOMEM;
97124+}
97125+
97126+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
97127 {
97128 /*
97129 * We implement the search by looking for an rbtree node that
97130@@ -1747,11 +1977,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
97131 }
97132 }
97133
97134- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
97135+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
97136 check_current:
97137 /* Check if current node has a suitable gap */
97138 if (gap_start > high_limit)
97139 return -ENOMEM;
97140+
97141+ if (gap_end - gap_start > info->threadstack_offset)
97142+ gap_start += info->threadstack_offset;
97143+ else
97144+ gap_start = gap_end;
97145+
97146+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
97147+ if (gap_end - gap_start > sysctl_heap_stack_gap)
97148+ gap_start += sysctl_heap_stack_gap;
97149+ else
97150+ gap_start = gap_end;
97151+ }
97152+ if (vma->vm_flags & VM_GROWSDOWN) {
97153+ if (gap_end - gap_start > sysctl_heap_stack_gap)
97154+ gap_end -= sysctl_heap_stack_gap;
97155+ else
97156+ gap_end = gap_start;
97157+ }
97158 if (gap_end >= low_limit && gap_end - gap_start >= length)
97159 goto found;
97160
97161@@ -1801,7 +2049,7 @@ found:
97162 return gap_start;
97163 }
97164
97165-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
97166+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
97167 {
97168 struct mm_struct *mm = current->mm;
97169 struct vm_area_struct *vma;
97170@@ -1855,6 +2103,24 @@ check_current:
97171 gap_end = vma->vm_start;
97172 if (gap_end < low_limit)
97173 return -ENOMEM;
97174+
97175+ if (gap_end - gap_start > info->threadstack_offset)
97176+ gap_end -= info->threadstack_offset;
97177+ else
97178+ gap_end = gap_start;
97179+
97180+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
97181+ if (gap_end - gap_start > sysctl_heap_stack_gap)
97182+ gap_start += sysctl_heap_stack_gap;
97183+ else
97184+ gap_start = gap_end;
97185+ }
97186+ if (vma->vm_flags & VM_GROWSDOWN) {
97187+ if (gap_end - gap_start > sysctl_heap_stack_gap)
97188+ gap_end -= sysctl_heap_stack_gap;
97189+ else
97190+ gap_end = gap_start;
97191+ }
97192 if (gap_start <= high_limit && gap_end - gap_start >= length)
97193 goto found;
97194
97195@@ -1918,6 +2184,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97196 struct mm_struct *mm = current->mm;
97197 struct vm_area_struct *vma;
97198 struct vm_unmapped_area_info info;
97199+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
97200
97201 if (len > TASK_SIZE - mmap_min_addr)
97202 return -ENOMEM;
97203@@ -1925,11 +2192,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97204 if (flags & MAP_FIXED)
97205 return addr;
97206
97207+#ifdef CONFIG_PAX_RANDMMAP
97208+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
97209+#endif
97210+
97211 if (addr) {
97212 addr = PAGE_ALIGN(addr);
97213 vma = find_vma(mm, addr);
97214 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
97215- (!vma || addr + len <= vma->vm_start))
97216+ check_heap_stack_gap(vma, addr, len, offset))
97217 return addr;
97218 }
97219
97220@@ -1938,6 +2209,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97221 info.low_limit = mm->mmap_base;
97222 info.high_limit = TASK_SIZE;
97223 info.align_mask = 0;
97224+ info.threadstack_offset = offset;
97225 return vm_unmapped_area(&info);
97226 }
97227 #endif
97228@@ -1956,6 +2228,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97229 struct mm_struct *mm = current->mm;
97230 unsigned long addr = addr0;
97231 struct vm_unmapped_area_info info;
97232+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
97233
97234 /* requested length too big for entire address space */
97235 if (len > TASK_SIZE - mmap_min_addr)
97236@@ -1964,12 +2237,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97237 if (flags & MAP_FIXED)
97238 return addr;
97239
97240+#ifdef CONFIG_PAX_RANDMMAP
97241+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
97242+#endif
97243+
97244 /* requesting a specific address */
97245 if (addr) {
97246 addr = PAGE_ALIGN(addr);
97247 vma = find_vma(mm, addr);
97248 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
97249- (!vma || addr + len <= vma->vm_start))
97250+ check_heap_stack_gap(vma, addr, len, offset))
97251 return addr;
97252 }
97253
97254@@ -1978,6 +2255,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97255 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
97256 info.high_limit = mm->mmap_base;
97257 info.align_mask = 0;
97258+ info.threadstack_offset = offset;
97259 addr = vm_unmapped_area(&info);
97260
97261 /*
97262@@ -1990,6 +2268,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97263 VM_BUG_ON(addr != -ENOMEM);
97264 info.flags = 0;
97265 info.low_limit = TASK_UNMAPPED_BASE;
97266+
97267+#ifdef CONFIG_PAX_RANDMMAP
97268+ if (mm->pax_flags & MF_PAX_RANDMMAP)
97269+ info.low_limit += mm->delta_mmap;
97270+#endif
97271+
97272 info.high_limit = TASK_SIZE;
97273 addr = vm_unmapped_area(&info);
97274 }
97275@@ -2090,6 +2374,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
97276 return vma;
97277 }
97278
97279+#ifdef CONFIG_PAX_SEGMEXEC
97280+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
97281+{
97282+ struct vm_area_struct *vma_m;
97283+
97284+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
97285+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
97286+ BUG_ON(vma->vm_mirror);
97287+ return NULL;
97288+ }
97289+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
97290+ vma_m = vma->vm_mirror;
97291+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
97292+ BUG_ON(vma->vm_file != vma_m->vm_file);
97293+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
97294+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
97295+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
97296+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
97297+ return vma_m;
97298+}
97299+#endif
97300+
97301 /*
97302 * Verify that the stack growth is acceptable and
97303 * update accounting. This is shared with both the
97304@@ -2106,6 +2412,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97305 return -ENOMEM;
97306
97307 /* Stack limit test */
97308+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
97309 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
97310 return -ENOMEM;
97311
97312@@ -2116,6 +2423,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97313 locked = mm->locked_vm + grow;
97314 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
97315 limit >>= PAGE_SHIFT;
97316+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
97317 if (locked > limit && !capable(CAP_IPC_LOCK))
97318 return -ENOMEM;
97319 }
97320@@ -2145,37 +2453,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97321 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
97322 * vma is the last one with address > vma->vm_end. Have to extend vma.
97323 */
97324+#ifndef CONFIG_IA64
97325+static
97326+#endif
97327 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
97328 {
97329 int error;
97330+ bool locknext;
97331
97332 if (!(vma->vm_flags & VM_GROWSUP))
97333 return -EFAULT;
97334
97335+ /* Also guard against wrapping around to address 0. */
97336+ if (address < PAGE_ALIGN(address+1))
97337+ address = PAGE_ALIGN(address+1);
97338+ else
97339+ return -ENOMEM;
97340+
97341 /*
97342 * We must make sure the anon_vma is allocated
97343 * so that the anon_vma locking is not a noop.
97344 */
97345 if (unlikely(anon_vma_prepare(vma)))
97346 return -ENOMEM;
97347+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
97348+ if (locknext && anon_vma_prepare(vma->vm_next))
97349+ return -ENOMEM;
97350 vma_lock_anon_vma(vma);
97351+ if (locknext)
97352+ vma_lock_anon_vma(vma->vm_next);
97353
97354 /*
97355 * vma->vm_start/vm_end cannot change under us because the caller
97356 * is required to hold the mmap_sem in read mode. We need the
97357- * anon_vma lock to serialize against concurrent expand_stacks.
97358- * Also guard against wrapping around to address 0.
97359+ * anon_vma locks to serialize against concurrent expand_stacks
97360+ * and expand_upwards.
97361 */
97362- if (address < PAGE_ALIGN(address+4))
97363- address = PAGE_ALIGN(address+4);
97364- else {
97365- vma_unlock_anon_vma(vma);
97366- return -ENOMEM;
97367- }
97368 error = 0;
97369
97370 /* Somebody else might have raced and expanded it already */
97371- if (address > vma->vm_end) {
97372+ 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)
97373+ error = -ENOMEM;
97374+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
97375 unsigned long size, grow;
97376
97377 size = address - vma->vm_start;
97378@@ -2210,6 +2529,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
97379 }
97380 }
97381 }
97382+ if (locknext)
97383+ vma_unlock_anon_vma(vma->vm_next);
97384 vma_unlock_anon_vma(vma);
97385 khugepaged_enter_vma_merge(vma, vma->vm_flags);
97386 validate_mm(vma->vm_mm);
97387@@ -2224,6 +2545,8 @@ int expand_downwards(struct vm_area_struct *vma,
97388 unsigned long address)
97389 {
97390 int error;
97391+ bool lockprev = false;
97392+ struct vm_area_struct *prev;
97393
97394 /*
97395 * We must make sure the anon_vma is allocated
97396@@ -2237,6 +2560,15 @@ int expand_downwards(struct vm_area_struct *vma,
97397 if (error)
97398 return error;
97399
97400+ prev = vma->vm_prev;
97401+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
97402+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
97403+#endif
97404+ if (lockprev && anon_vma_prepare(prev))
97405+ return -ENOMEM;
97406+ if (lockprev)
97407+ vma_lock_anon_vma(prev);
97408+
97409 vma_lock_anon_vma(vma);
97410
97411 /*
97412@@ -2246,9 +2578,17 @@ int expand_downwards(struct vm_area_struct *vma,
97413 */
97414
97415 /* Somebody else might have raced and expanded it already */
97416- if (address < vma->vm_start) {
97417+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
97418+ error = -ENOMEM;
97419+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
97420 unsigned long size, grow;
97421
97422+#ifdef CONFIG_PAX_SEGMEXEC
97423+ struct vm_area_struct *vma_m;
97424+
97425+ vma_m = pax_find_mirror_vma(vma);
97426+#endif
97427+
97428 size = vma->vm_end - address;
97429 grow = (vma->vm_start - address) >> PAGE_SHIFT;
97430
97431@@ -2273,13 +2613,27 @@ int expand_downwards(struct vm_area_struct *vma,
97432 vma->vm_pgoff -= grow;
97433 anon_vma_interval_tree_post_update_vma(vma);
97434 vma_gap_update(vma);
97435+
97436+#ifdef CONFIG_PAX_SEGMEXEC
97437+ if (vma_m) {
97438+ anon_vma_interval_tree_pre_update_vma(vma_m);
97439+ vma_m->vm_start -= grow << PAGE_SHIFT;
97440+ vma_m->vm_pgoff -= grow;
97441+ anon_vma_interval_tree_post_update_vma(vma_m);
97442+ vma_gap_update(vma_m);
97443+ }
97444+#endif
97445+
97446 spin_unlock(&vma->vm_mm->page_table_lock);
97447
97448+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
97449 perf_event_mmap(vma);
97450 }
97451 }
97452 }
97453 vma_unlock_anon_vma(vma);
97454+ if (lockprev)
97455+ vma_unlock_anon_vma(prev);
97456 khugepaged_enter_vma_merge(vma, vma->vm_flags);
97457 validate_mm(vma->vm_mm);
97458 return error;
97459@@ -2377,6 +2731,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
97460 do {
97461 long nrpages = vma_pages(vma);
97462
97463+#ifdef CONFIG_PAX_SEGMEXEC
97464+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
97465+ vma = remove_vma(vma);
97466+ continue;
97467+ }
97468+#endif
97469+
97470 if (vma->vm_flags & VM_ACCOUNT)
97471 nr_accounted += nrpages;
97472 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
97473@@ -2421,6 +2782,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
97474 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
97475 vma->vm_prev = NULL;
97476 do {
97477+
97478+#ifdef CONFIG_PAX_SEGMEXEC
97479+ if (vma->vm_mirror) {
97480+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
97481+ vma->vm_mirror->vm_mirror = NULL;
97482+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
97483+ vma->vm_mirror = NULL;
97484+ }
97485+#endif
97486+
97487 vma_rb_erase(vma, &mm->mm_rb);
97488 mm->map_count--;
97489 tail_vma = vma;
97490@@ -2448,14 +2819,33 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97491 struct vm_area_struct *new;
97492 int err = -ENOMEM;
97493
97494+#ifdef CONFIG_PAX_SEGMEXEC
97495+ struct vm_area_struct *vma_m, *new_m = NULL;
97496+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
97497+#endif
97498+
97499 if (is_vm_hugetlb_page(vma) && (addr &
97500 ~(huge_page_mask(hstate_vma(vma)))))
97501 return -EINVAL;
97502
97503+#ifdef CONFIG_PAX_SEGMEXEC
97504+ vma_m = pax_find_mirror_vma(vma);
97505+#endif
97506+
97507 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
97508 if (!new)
97509 goto out_err;
97510
97511+#ifdef CONFIG_PAX_SEGMEXEC
97512+ if (vma_m) {
97513+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
97514+ if (!new_m) {
97515+ kmem_cache_free(vm_area_cachep, new);
97516+ goto out_err;
97517+ }
97518+ }
97519+#endif
97520+
97521 /* most fields are the same, copy all, and then fixup */
97522 *new = *vma;
97523
97524@@ -2468,6 +2858,22 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97525 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
97526 }
97527
97528+#ifdef CONFIG_PAX_SEGMEXEC
97529+ if (vma_m) {
97530+ *new_m = *vma_m;
97531+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
97532+ new_m->vm_mirror = new;
97533+ new->vm_mirror = new_m;
97534+
97535+ if (new_below)
97536+ new_m->vm_end = addr_m;
97537+ else {
97538+ new_m->vm_start = addr_m;
97539+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
97540+ }
97541+ }
97542+#endif
97543+
97544 err = vma_dup_policy(vma, new);
97545 if (err)
97546 goto out_free_vma;
97547@@ -2488,6 +2894,38 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97548 else
97549 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
97550
97551+#ifdef CONFIG_PAX_SEGMEXEC
97552+ if (!err && vma_m) {
97553+ struct mempolicy *pol = vma_policy(new);
97554+
97555+ if (anon_vma_clone(new_m, vma_m))
97556+ goto out_free_mpol;
97557+
97558+ mpol_get(pol);
97559+ set_vma_policy(new_m, pol);
97560+
97561+ if (new_m->vm_file)
97562+ get_file(new_m->vm_file);
97563+
97564+ if (new_m->vm_ops && new_m->vm_ops->open)
97565+ new_m->vm_ops->open(new_m);
97566+
97567+ if (new_below)
97568+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
97569+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
97570+ else
97571+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
97572+
97573+ if (err) {
97574+ if (new_m->vm_ops && new_m->vm_ops->close)
97575+ new_m->vm_ops->close(new_m);
97576+ if (new_m->vm_file)
97577+ fput(new_m->vm_file);
97578+ mpol_put(pol);
97579+ }
97580+ }
97581+#endif
97582+
97583 /* Success. */
97584 if (!err)
97585 return 0;
97586@@ -2497,10 +2935,18 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97587 new->vm_ops->close(new);
97588 if (new->vm_file)
97589 fput(new->vm_file);
97590- unlink_anon_vmas(new);
97591 out_free_mpol:
97592 mpol_put(vma_policy(new));
97593 out_free_vma:
97594+
97595+#ifdef CONFIG_PAX_SEGMEXEC
97596+ if (new_m) {
97597+ unlink_anon_vmas(new_m);
97598+ kmem_cache_free(vm_area_cachep, new_m);
97599+ }
97600+#endif
97601+
97602+ unlink_anon_vmas(new);
97603 kmem_cache_free(vm_area_cachep, new);
97604 out_err:
97605 return err;
97606@@ -2513,6 +2959,15 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97607 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97608 unsigned long addr, int new_below)
97609 {
97610+
97611+#ifdef CONFIG_PAX_SEGMEXEC
97612+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
97613+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
97614+ if (mm->map_count >= sysctl_max_map_count-1)
97615+ return -ENOMEM;
97616+ } else
97617+#endif
97618+
97619 if (mm->map_count >= sysctl_max_map_count)
97620 return -ENOMEM;
97621
97622@@ -2524,11 +2979,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97623 * work. This now handles partial unmappings.
97624 * Jeremy Fitzhardinge <jeremy@goop.org>
97625 */
97626+#ifdef CONFIG_PAX_SEGMEXEC
97627 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97628 {
97629+ int ret = __do_munmap(mm, start, len);
97630+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
97631+ return ret;
97632+
97633+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
97634+}
97635+
97636+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97637+#else
97638+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97639+#endif
97640+{
97641 unsigned long end;
97642 struct vm_area_struct *vma, *prev, *last;
97643
97644+ /*
97645+ * mm->mmap_sem is required to protect against another thread
97646+ * changing the mappings in case we sleep.
97647+ */
97648+ verify_mm_writelocked(mm);
97649+
97650 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
97651 return -EINVAL;
97652
97653@@ -2604,6 +3078,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97654 /* Fix up all other VM information */
97655 remove_vma_list(mm, vma);
97656
97657+ track_exec_limit(mm, start, end, 0UL);
97658+
97659 return 0;
97660 }
97661
97662@@ -2612,6 +3088,13 @@ int vm_munmap(unsigned long start, size_t len)
97663 int ret;
97664 struct mm_struct *mm = current->mm;
97665
97666+
97667+#ifdef CONFIG_PAX_SEGMEXEC
97668+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
97669+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
97670+ return -EINVAL;
97671+#endif
97672+
97673 down_write(&mm->mmap_sem);
97674 ret = do_munmap(mm, start, len);
97675 up_write(&mm->mmap_sem);
97676@@ -2625,16 +3108,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
97677 return vm_munmap(addr, len);
97678 }
97679
97680-static inline void verify_mm_writelocked(struct mm_struct *mm)
97681-{
97682-#ifdef CONFIG_DEBUG_VM
97683- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
97684- WARN_ON(1);
97685- up_read(&mm->mmap_sem);
97686- }
97687-#endif
97688-}
97689-
97690 /*
97691 * this is really a simplified "do_mmap". it only handles
97692 * anonymous maps. eventually we may be able to do some
97693@@ -2648,6 +3121,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97694 struct rb_node **rb_link, *rb_parent;
97695 pgoff_t pgoff = addr >> PAGE_SHIFT;
97696 int error;
97697+ unsigned long charged;
97698
97699 len = PAGE_ALIGN(len);
97700 if (!len)
97701@@ -2655,10 +3129,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97702
97703 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
97704
97705+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
97706+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
97707+ flags &= ~VM_EXEC;
97708+
97709+#ifdef CONFIG_PAX_MPROTECT
97710+ if (mm->pax_flags & MF_PAX_MPROTECT)
97711+ flags &= ~VM_MAYEXEC;
97712+#endif
97713+
97714+ }
97715+#endif
97716+
97717 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
97718 if (error & ~PAGE_MASK)
97719 return error;
97720
97721+ charged = len >> PAGE_SHIFT;
97722+
97723 error = mlock_future_check(mm, mm->def_flags, len);
97724 if (error)
97725 return error;
97726@@ -2672,21 +3160,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97727 /*
97728 * Clear old maps. this also does some error checking for us
97729 */
97730- munmap_back:
97731 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
97732 if (do_munmap(mm, addr, len))
97733 return -ENOMEM;
97734- goto munmap_back;
97735+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
97736 }
97737
97738 /* Check against address space limits *after* clearing old maps... */
97739- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
97740+ if (!may_expand_vm(mm, charged))
97741 return -ENOMEM;
97742
97743 if (mm->map_count > sysctl_max_map_count)
97744 return -ENOMEM;
97745
97746- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
97747+ if (security_vm_enough_memory_mm(mm, charged))
97748 return -ENOMEM;
97749
97750 /* Can we just expand an old private anonymous mapping? */
97751@@ -2700,7 +3187,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97752 */
97753 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
97754 if (!vma) {
97755- vm_unacct_memory(len >> PAGE_SHIFT);
97756+ vm_unacct_memory(charged);
97757 return -ENOMEM;
97758 }
97759
97760@@ -2714,10 +3201,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97761 vma_link(mm, vma, prev, rb_link, rb_parent);
97762 out:
97763 perf_event_mmap(vma);
97764- mm->total_vm += len >> PAGE_SHIFT;
97765+ mm->total_vm += charged;
97766 if (flags & VM_LOCKED)
97767- mm->locked_vm += (len >> PAGE_SHIFT);
97768+ mm->locked_vm += charged;
97769 vma->vm_flags |= VM_SOFTDIRTY;
97770+ track_exec_limit(mm, addr, addr + len, flags);
97771 return addr;
97772 }
97773
97774@@ -2779,6 +3267,7 @@ void exit_mmap(struct mm_struct *mm)
97775 while (vma) {
97776 if (vma->vm_flags & VM_ACCOUNT)
97777 nr_accounted += vma_pages(vma);
97778+ vma->vm_mirror = NULL;
97779 vma = remove_vma(vma);
97780 }
97781 vm_unacct_memory(nr_accounted);
97782@@ -2796,6 +3285,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
97783 struct vm_area_struct *prev;
97784 struct rb_node **rb_link, *rb_parent;
97785
97786+#ifdef CONFIG_PAX_SEGMEXEC
97787+ struct vm_area_struct *vma_m = NULL;
97788+#endif
97789+
97790+ if (security_mmap_addr(vma->vm_start))
97791+ return -EPERM;
97792+
97793 /*
97794 * The vm_pgoff of a purely anonymous vma should be irrelevant
97795 * until its first write fault, when page's anon_vma and index
97796@@ -2819,7 +3315,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
97797 security_vm_enough_memory_mm(mm, vma_pages(vma)))
97798 return -ENOMEM;
97799
97800+#ifdef CONFIG_PAX_SEGMEXEC
97801+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
97802+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
97803+ if (!vma_m)
97804+ return -ENOMEM;
97805+ }
97806+#endif
97807+
97808 vma_link(mm, vma, prev, rb_link, rb_parent);
97809+
97810+#ifdef CONFIG_PAX_SEGMEXEC
97811+ if (vma_m)
97812+ BUG_ON(pax_mirror_vma(vma_m, vma));
97813+#endif
97814+
97815 return 0;
97816 }
97817
97818@@ -2838,6 +3348,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
97819 struct rb_node **rb_link, *rb_parent;
97820 bool faulted_in_anon_vma = true;
97821
97822+ BUG_ON(vma->vm_mirror);
97823+
97824 /*
97825 * If anonymous vma has not yet been faulted, update new pgoff
97826 * to match new location, to increase its chance of merging.
97827@@ -2902,6 +3414,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
97828 return NULL;
97829 }
97830
97831+#ifdef CONFIG_PAX_SEGMEXEC
97832+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
97833+{
97834+ struct vm_area_struct *prev_m;
97835+ struct rb_node **rb_link_m, *rb_parent_m;
97836+ struct mempolicy *pol_m;
97837+
97838+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
97839+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
97840+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
97841+ *vma_m = *vma;
97842+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
97843+ if (anon_vma_clone(vma_m, vma))
97844+ return -ENOMEM;
97845+ pol_m = vma_policy(vma_m);
97846+ mpol_get(pol_m);
97847+ set_vma_policy(vma_m, pol_m);
97848+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
97849+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
97850+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
97851+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
97852+ if (vma_m->vm_file)
97853+ get_file(vma_m->vm_file);
97854+ if (vma_m->vm_ops && vma_m->vm_ops->open)
97855+ vma_m->vm_ops->open(vma_m);
97856+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
97857+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
97858+ vma_m->vm_mirror = vma;
97859+ vma->vm_mirror = vma_m;
97860+ return 0;
97861+}
97862+#endif
97863+
97864 /*
97865 * Return true if the calling process may expand its vm space by the passed
97866 * number of pages
97867@@ -2913,6 +3458,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
97868
97869 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
97870
97871+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
97872 if (cur + npages > lim)
97873 return 0;
97874 return 1;
97875@@ -2995,6 +3541,22 @@ static struct vm_area_struct *__install_special_mapping(
97876 vma->vm_start = addr;
97877 vma->vm_end = addr + len;
97878
97879+#ifdef CONFIG_PAX_MPROTECT
97880+ if (mm->pax_flags & MF_PAX_MPROTECT) {
97881+#ifndef CONFIG_PAX_MPROTECT_COMPAT
97882+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
97883+ return ERR_PTR(-EPERM);
97884+ if (!(vm_flags & VM_EXEC))
97885+ vm_flags &= ~VM_MAYEXEC;
97886+#else
97887+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
97888+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
97889+#endif
97890+ else
97891+ vm_flags &= ~VM_MAYWRITE;
97892+ }
97893+#endif
97894+
97895 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
97896 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
97897
97898diff --git a/mm/mprotect.c b/mm/mprotect.c
97899index ace9345..63320dc 100644
97900--- a/mm/mprotect.c
97901+++ b/mm/mprotect.c
97902@@ -24,10 +24,18 @@
97903 #include <linux/migrate.h>
97904 #include <linux/perf_event.h>
97905 #include <linux/ksm.h>
97906+#include <linux/sched/sysctl.h>
97907+
97908+#ifdef CONFIG_PAX_MPROTECT
97909+#include <linux/elf.h>
97910+#include <linux/binfmts.h>
97911+#endif
97912+
97913 #include <asm/uaccess.h>
97914 #include <asm/pgtable.h>
97915 #include <asm/cacheflush.h>
97916 #include <asm/tlbflush.h>
97917+#include <asm/mmu_context.h>
97918
97919 /*
97920 * For a prot_numa update we only hold mmap_sem for read so there is a
97921@@ -251,6 +259,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
97922 return pages;
97923 }
97924
97925+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
97926+/* called while holding the mmap semaphor for writing except stack expansion */
97927+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
97928+{
97929+ unsigned long oldlimit, newlimit = 0UL;
97930+
97931+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
97932+ return;
97933+
97934+ spin_lock(&mm->page_table_lock);
97935+ oldlimit = mm->context.user_cs_limit;
97936+ if ((prot & VM_EXEC) && oldlimit < end)
97937+ /* USER_CS limit moved up */
97938+ newlimit = end;
97939+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
97940+ /* USER_CS limit moved down */
97941+ newlimit = start;
97942+
97943+ if (newlimit) {
97944+ mm->context.user_cs_limit = newlimit;
97945+
97946+#ifdef CONFIG_SMP
97947+ wmb();
97948+ cpus_clear(mm->context.cpu_user_cs_mask);
97949+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
97950+#endif
97951+
97952+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
97953+ }
97954+ spin_unlock(&mm->page_table_lock);
97955+ if (newlimit == end) {
97956+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
97957+
97958+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
97959+ if (is_vm_hugetlb_page(vma))
97960+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
97961+ else
97962+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
97963+ }
97964+}
97965+#endif
97966+
97967 int
97968 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
97969 unsigned long start, unsigned long end, unsigned long newflags)
97970@@ -263,11 +313,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
97971 int error;
97972 int dirty_accountable = 0;
97973
97974+#ifdef CONFIG_PAX_SEGMEXEC
97975+ struct vm_area_struct *vma_m = NULL;
97976+ unsigned long start_m, end_m;
97977+
97978+ start_m = start + SEGMEXEC_TASK_SIZE;
97979+ end_m = end + SEGMEXEC_TASK_SIZE;
97980+#endif
97981+
97982 if (newflags == oldflags) {
97983 *pprev = vma;
97984 return 0;
97985 }
97986
97987+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
97988+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
97989+
97990+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
97991+ return -ENOMEM;
97992+
97993+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
97994+ return -ENOMEM;
97995+ }
97996+
97997 /*
97998 * If we make a private mapping writable we increase our commit;
97999 * but (without finer accounting) cannot reduce our commit if we
98000@@ -284,6 +352,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98001 }
98002 }
98003
98004+#ifdef CONFIG_PAX_SEGMEXEC
98005+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
98006+ if (start != vma->vm_start) {
98007+ error = split_vma(mm, vma, start, 1);
98008+ if (error)
98009+ goto fail;
98010+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
98011+ *pprev = (*pprev)->vm_next;
98012+ }
98013+
98014+ if (end != vma->vm_end) {
98015+ error = split_vma(mm, vma, end, 0);
98016+ if (error)
98017+ goto fail;
98018+ }
98019+
98020+ if (pax_find_mirror_vma(vma)) {
98021+ error = __do_munmap(mm, start_m, end_m - start_m);
98022+ if (error)
98023+ goto fail;
98024+ } else {
98025+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
98026+ if (!vma_m) {
98027+ error = -ENOMEM;
98028+ goto fail;
98029+ }
98030+ vma->vm_flags = newflags;
98031+ error = pax_mirror_vma(vma_m, vma);
98032+ if (error) {
98033+ vma->vm_flags = oldflags;
98034+ goto fail;
98035+ }
98036+ }
98037+ }
98038+#endif
98039+
98040 /*
98041 * First try to merge with previous and/or next vma.
98042 */
98043@@ -314,7 +418,19 @@ success:
98044 * vm_flags and vm_page_prot are protected by the mmap_sem
98045 * held in write mode.
98046 */
98047+
98048+#ifdef CONFIG_PAX_SEGMEXEC
98049+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
98050+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
98051+#endif
98052+
98053 vma->vm_flags = newflags;
98054+
98055+#ifdef CONFIG_PAX_MPROTECT
98056+ if (mm->binfmt && mm->binfmt->handle_mprotect)
98057+ mm->binfmt->handle_mprotect(vma, newflags);
98058+#endif
98059+
98060 dirty_accountable = vma_wants_writenotify(vma);
98061 vma_set_page_prot(vma);
98062
98063@@ -350,6 +466,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98064 end = start + len;
98065 if (end <= start)
98066 return -ENOMEM;
98067+
98068+#ifdef CONFIG_PAX_SEGMEXEC
98069+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
98070+ if (end > SEGMEXEC_TASK_SIZE)
98071+ return -EINVAL;
98072+ } else
98073+#endif
98074+
98075+ if (end > TASK_SIZE)
98076+ return -EINVAL;
98077+
98078 if (!arch_validate_prot(prot))
98079 return -EINVAL;
98080
98081@@ -357,7 +484,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98082 /*
98083 * Does the application expect PROT_READ to imply PROT_EXEC:
98084 */
98085- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
98086+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
98087 prot |= PROT_EXEC;
98088
98089 vm_flags = calc_vm_prot_bits(prot);
98090@@ -389,6 +516,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98091 if (start > vma->vm_start)
98092 prev = vma;
98093
98094+#ifdef CONFIG_PAX_MPROTECT
98095+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
98096+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
98097+#endif
98098+
98099 for (nstart = start ; ; ) {
98100 unsigned long newflags;
98101
98102@@ -399,6 +531,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98103
98104 /* newflags >> 4 shift VM_MAY% in place of VM_% */
98105 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
98106+ if (prot & (PROT_WRITE | PROT_EXEC))
98107+ gr_log_rwxmprotect(vma);
98108+
98109+ error = -EACCES;
98110+ goto out;
98111+ }
98112+
98113+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
98114 error = -EACCES;
98115 goto out;
98116 }
98117@@ -413,6 +553,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98118 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
98119 if (error)
98120 goto out;
98121+
98122+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
98123+
98124 nstart = tmp;
98125
98126 if (nstart < prev->vm_end)
98127diff --git a/mm/mremap.c b/mm/mremap.c
98128index b147f66..98a695a 100644
98129--- a/mm/mremap.c
98130+++ b/mm/mremap.c
98131@@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
98132 continue;
98133 pte = ptep_get_and_clear(mm, old_addr, old_pte);
98134 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
98135+
98136+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
98137+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
98138+ pte = pte_exprotect(pte);
98139+#endif
98140+
98141 pte = move_soft_dirty_pte(pte);
98142 set_pte_at(mm, new_addr, new_pte, pte);
98143 }
98144@@ -345,6 +351,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
98145 if (is_vm_hugetlb_page(vma))
98146 goto Einval;
98147
98148+#ifdef CONFIG_PAX_SEGMEXEC
98149+ if (pax_find_mirror_vma(vma))
98150+ goto Einval;
98151+#endif
98152+
98153 /* We can't remap across vm area boundaries */
98154 if (old_len > vma->vm_end - addr)
98155 goto Efault;
98156@@ -400,20 +411,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
98157 unsigned long ret = -EINVAL;
98158 unsigned long charged = 0;
98159 unsigned long map_flags;
98160+ unsigned long pax_task_size = TASK_SIZE;
98161
98162 if (new_addr & ~PAGE_MASK)
98163 goto out;
98164
98165- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
98166+#ifdef CONFIG_PAX_SEGMEXEC
98167+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
98168+ pax_task_size = SEGMEXEC_TASK_SIZE;
98169+#endif
98170+
98171+ pax_task_size -= PAGE_SIZE;
98172+
98173+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
98174 goto out;
98175
98176 /* Check if the location we're moving into overlaps the
98177 * old location at all, and fail if it does.
98178 */
98179- if ((new_addr <= addr) && (new_addr+new_len) > addr)
98180- goto out;
98181-
98182- if ((addr <= new_addr) && (addr+old_len) > new_addr)
98183+ if (addr + old_len > new_addr && new_addr + new_len > addr)
98184 goto out;
98185
98186 ret = do_munmap(mm, new_addr, new_len);
98187@@ -482,6 +498,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98188 unsigned long ret = -EINVAL;
98189 unsigned long charged = 0;
98190 bool locked = false;
98191+ unsigned long pax_task_size = TASK_SIZE;
98192
98193 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
98194 return ret;
98195@@ -503,6 +520,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98196 if (!new_len)
98197 return ret;
98198
98199+#ifdef CONFIG_PAX_SEGMEXEC
98200+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
98201+ pax_task_size = SEGMEXEC_TASK_SIZE;
98202+#endif
98203+
98204+ pax_task_size -= PAGE_SIZE;
98205+
98206+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
98207+ old_len > pax_task_size || addr > pax_task_size-old_len)
98208+ return ret;
98209+
98210 down_write(&current->mm->mmap_sem);
98211
98212 if (flags & MREMAP_FIXED) {
98213@@ -553,6 +581,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98214 new_addr = addr;
98215 }
98216 ret = addr;
98217+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
98218 goto out;
98219 }
98220 }
98221@@ -576,7 +605,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98222 goto out;
98223 }
98224
98225+ map_flags = vma->vm_flags;
98226 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
98227+ if (!(ret & ~PAGE_MASK)) {
98228+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
98229+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
98230+ }
98231 }
98232 out:
98233 if (ret & ~PAGE_MASK)
98234diff --git a/mm/nommu.c b/mm/nommu.c
98235index bd1808e..b63d87c 100644
98236--- a/mm/nommu.c
98237+++ b/mm/nommu.c
98238@@ -70,7 +70,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
98239 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
98240 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
98241 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
98242-int heap_stack_gap = 0;
98243
98244 atomic_long_t mmap_pages_allocated;
98245
98246@@ -857,15 +856,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
98247 EXPORT_SYMBOL(find_vma);
98248
98249 /*
98250- * find a VMA
98251- * - we don't extend stack VMAs under NOMMU conditions
98252- */
98253-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
98254-{
98255- return find_vma(mm, addr);
98256-}
98257-
98258-/*
98259 * expand a stack to a given address
98260 * - not supported under NOMMU conditions
98261 */
98262@@ -1572,6 +1562,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
98263
98264 /* most fields are the same, copy all, and then fixup */
98265 *new = *vma;
98266+ INIT_LIST_HEAD(&new->anon_vma_chain);
98267 *region = *vma->vm_region;
98268 new->vm_region = region;
98269
98270@@ -2002,8 +1993,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
98271 }
98272 EXPORT_SYMBOL(generic_file_remap_pages);
98273
98274-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98275- unsigned long addr, void *buf, int len, int write)
98276+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98277+ unsigned long addr, void *buf, size_t len, int write)
98278 {
98279 struct vm_area_struct *vma;
98280
98281@@ -2044,8 +2035,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98282 *
98283 * The caller must hold a reference on @mm.
98284 */
98285-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
98286- void *buf, int len, int write)
98287+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
98288+ void *buf, size_t len, int write)
98289 {
98290 return __access_remote_vm(NULL, mm, addr, buf, len, write);
98291 }
98292@@ -2054,7 +2045,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
98293 * Access another process' address space.
98294 * - source/target buffer must be kernel space
98295 */
98296-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
98297+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
98298 {
98299 struct mm_struct *mm;
98300
98301diff --git a/mm/page-writeback.c b/mm/page-writeback.c
98302index 19ceae8..70848ee 100644
98303--- a/mm/page-writeback.c
98304+++ b/mm/page-writeback.c
98305@@ -664,7 +664,7 @@ static long long pos_ratio_polynom(unsigned long setpoint,
98306 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
98307 * - the bdi dirty thresh drops quickly due to change of JBOD workload
98308 */
98309-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
98310+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
98311 unsigned long thresh,
98312 unsigned long bg_thresh,
98313 unsigned long dirty,
98314diff --git a/mm/page_alloc.c b/mm/page_alloc.c
98315index 616a2c9..0e755f6 100644
98316--- a/mm/page_alloc.c
98317+++ b/mm/page_alloc.c
98318@@ -59,6 +59,7 @@
98319 #include <linux/page-debug-flags.h>
98320 #include <linux/hugetlb.h>
98321 #include <linux/sched/rt.h>
98322+#include <linux/random.h>
98323
98324 #include <asm/sections.h>
98325 #include <asm/tlbflush.h>
98326@@ -356,7 +357,7 @@ out:
98327 * This usage means that zero-order pages may not be compound.
98328 */
98329
98330-static void free_compound_page(struct page *page)
98331+void free_compound_page(struct page *page)
98332 {
98333 __free_pages_ok(page, compound_order(page));
98334 }
98335@@ -741,6 +742,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
98336 int i;
98337 int bad = 0;
98338
98339+#ifdef CONFIG_PAX_MEMORY_SANITIZE
98340+ unsigned long index = 1UL << order;
98341+#endif
98342+
98343 trace_mm_page_free(page, order);
98344 kmemcheck_free_shadow(page, order);
98345
98346@@ -757,6 +762,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
98347 debug_check_no_obj_freed(page_address(page),
98348 PAGE_SIZE << order);
98349 }
98350+
98351+#ifdef CONFIG_PAX_MEMORY_SANITIZE
98352+ for (; index; --index)
98353+ sanitize_highpage(page + index - 1);
98354+#endif
98355+
98356 arch_free_page(page, order);
98357 kernel_map_pages(page, 1 << order, 0);
98358
98359@@ -780,6 +791,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
98360 local_irq_restore(flags);
98361 }
98362
98363+#ifdef CONFIG_PAX_LATENT_ENTROPY
98364+bool __meminitdata extra_latent_entropy;
98365+
98366+static int __init setup_pax_extra_latent_entropy(char *str)
98367+{
98368+ extra_latent_entropy = true;
98369+ return 0;
98370+}
98371+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
98372+
98373+volatile u64 latent_entropy __latent_entropy;
98374+EXPORT_SYMBOL(latent_entropy);
98375+#endif
98376+
98377 void __init __free_pages_bootmem(struct page *page, unsigned int order)
98378 {
98379 unsigned int nr_pages = 1 << order;
98380@@ -795,6 +820,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
98381 __ClearPageReserved(p);
98382 set_page_count(p, 0);
98383
98384+#ifdef CONFIG_PAX_LATENT_ENTROPY
98385+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
98386+ u64 hash = 0;
98387+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
98388+ const u64 *data = lowmem_page_address(page);
98389+
98390+ for (index = 0; index < end; index++)
98391+ hash ^= hash + data[index];
98392+ latent_entropy ^= hash;
98393+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
98394+ }
98395+#endif
98396+
98397 page_zone(page)->managed_pages += nr_pages;
98398 set_page_refcounted(page);
98399 __free_pages(page, order);
98400@@ -923,8 +961,10 @@ static int prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags)
98401 arch_alloc_page(page, order);
98402 kernel_map_pages(page, 1 << order, 1);
98403
98404+#ifndef CONFIG_PAX_MEMORY_SANITIZE
98405 if (gfp_flags & __GFP_ZERO)
98406 prep_zero_page(page, order, gfp_flags);
98407+#endif
98408
98409 if (order && (gfp_flags & __GFP_COMP))
98410 prep_compound_page(page, order);
98411@@ -1602,7 +1642,7 @@ again:
98412 }
98413
98414 __mod_zone_page_state(zone, NR_ALLOC_BATCH, -(1 << order));
98415- if (atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
98416+ if (atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
98417 !test_bit(ZONE_FAIR_DEPLETED, &zone->flags))
98418 set_bit(ZONE_FAIR_DEPLETED, &zone->flags);
98419
98420@@ -1923,7 +1963,7 @@ static void reset_alloc_batches(struct zone *preferred_zone)
98421 do {
98422 mod_zone_page_state(zone, NR_ALLOC_BATCH,
98423 high_wmark_pages(zone) - low_wmark_pages(zone) -
98424- atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
98425+ atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
98426 clear_bit(ZONE_FAIR_DEPLETED, &zone->flags);
98427 } while (zone++ != preferred_zone);
98428 }
98429@@ -5698,7 +5738,7 @@ static void __setup_per_zone_wmarks(void)
98430
98431 __mod_zone_page_state(zone, NR_ALLOC_BATCH,
98432 high_wmark_pages(zone) - low_wmark_pages(zone) -
98433- atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
98434+ atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
98435
98436 setup_zone_migrate_reserve(zone);
98437 spin_unlock_irqrestore(&zone->lock, flags);
98438diff --git a/mm/percpu.c b/mm/percpu.c
98439index 014bab6..db5a76f 100644
98440--- a/mm/percpu.c
98441+++ b/mm/percpu.c
98442@@ -131,7 +131,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
98443 static unsigned int pcpu_high_unit_cpu __read_mostly;
98444
98445 /* the address of the first chunk which starts with the kernel static area */
98446-void *pcpu_base_addr __read_mostly;
98447+void *pcpu_base_addr __read_only;
98448 EXPORT_SYMBOL_GPL(pcpu_base_addr);
98449
98450 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
98451diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
98452index 5077afc..846c9ef 100644
98453--- a/mm/process_vm_access.c
98454+++ b/mm/process_vm_access.c
98455@@ -13,6 +13,7 @@
98456 #include <linux/uio.h>
98457 #include <linux/sched.h>
98458 #include <linux/highmem.h>
98459+#include <linux/security.h>
98460 #include <linux/ptrace.h>
98461 #include <linux/slab.h>
98462 #include <linux/syscalls.h>
98463@@ -157,19 +158,19 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
98464 ssize_t iov_len;
98465 size_t total_len = iov_iter_count(iter);
98466
98467+ return -ENOSYS; // PaX: until properly audited
98468+
98469 /*
98470 * Work out how many pages of struct pages we're going to need
98471 * when eventually calling get_user_pages
98472 */
98473 for (i = 0; i < riovcnt; i++) {
98474 iov_len = rvec[i].iov_len;
98475- if (iov_len > 0) {
98476- nr_pages_iov = ((unsigned long)rvec[i].iov_base
98477- + iov_len)
98478- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
98479- / PAGE_SIZE + 1;
98480- nr_pages = max(nr_pages, nr_pages_iov);
98481- }
98482+ if (iov_len <= 0)
98483+ continue;
98484+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
98485+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
98486+ nr_pages = max(nr_pages, nr_pages_iov);
98487 }
98488
98489 if (nr_pages == 0)
98490@@ -197,6 +198,11 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
98491 goto free_proc_pages;
98492 }
98493
98494+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
98495+ rc = -EPERM;
98496+ goto put_task_struct;
98497+ }
98498+
98499 mm = mm_access(task, PTRACE_MODE_ATTACH);
98500 if (!mm || IS_ERR(mm)) {
98501 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
98502diff --git a/mm/rmap.c b/mm/rmap.c
98503index 3e4c721..a5e3e39 100644
98504--- a/mm/rmap.c
98505+++ b/mm/rmap.c
98506@@ -164,6 +164,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98507 struct anon_vma *anon_vma = vma->anon_vma;
98508 struct anon_vma_chain *avc;
98509
98510+#ifdef CONFIG_PAX_SEGMEXEC
98511+ struct anon_vma_chain *avc_m = NULL;
98512+#endif
98513+
98514 might_sleep();
98515 if (unlikely(!anon_vma)) {
98516 struct mm_struct *mm = vma->vm_mm;
98517@@ -173,6 +177,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98518 if (!avc)
98519 goto out_enomem;
98520
98521+#ifdef CONFIG_PAX_SEGMEXEC
98522+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
98523+ if (!avc_m)
98524+ goto out_enomem_free_avc;
98525+#endif
98526+
98527 anon_vma = find_mergeable_anon_vma(vma);
98528 allocated = NULL;
98529 if (!anon_vma) {
98530@@ -186,6 +196,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98531 /* page_table_lock to protect against threads */
98532 spin_lock(&mm->page_table_lock);
98533 if (likely(!vma->anon_vma)) {
98534+
98535+#ifdef CONFIG_PAX_SEGMEXEC
98536+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
98537+
98538+ if (vma_m) {
98539+ BUG_ON(vma_m->anon_vma);
98540+ vma_m->anon_vma = anon_vma;
98541+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
98542+ avc_m = NULL;
98543+ }
98544+#endif
98545+
98546 vma->anon_vma = anon_vma;
98547 anon_vma_chain_link(vma, avc, anon_vma);
98548 allocated = NULL;
98549@@ -196,12 +218,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98550
98551 if (unlikely(allocated))
98552 put_anon_vma(allocated);
98553+
98554+#ifdef CONFIG_PAX_SEGMEXEC
98555+ if (unlikely(avc_m))
98556+ anon_vma_chain_free(avc_m);
98557+#endif
98558+
98559 if (unlikely(avc))
98560 anon_vma_chain_free(avc);
98561 }
98562 return 0;
98563
98564 out_enomem_free_avc:
98565+
98566+#ifdef CONFIG_PAX_SEGMEXEC
98567+ if (avc_m)
98568+ anon_vma_chain_free(avc_m);
98569+#endif
98570+
98571 anon_vma_chain_free(avc);
98572 out_enomem:
98573 return -ENOMEM;
98574@@ -237,7 +271,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
98575 * Attach the anon_vmas from src to dst.
98576 * Returns 0 on success, -ENOMEM on failure.
98577 */
98578-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
98579+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
98580 {
98581 struct anon_vma_chain *avc, *pavc;
98582 struct anon_vma *root = NULL;
98583@@ -270,7 +304,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
98584 * the corresponding VMA in the parent process is attached to.
98585 * Returns 0 on success, non-zero on failure.
98586 */
98587-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
98588+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
98589 {
98590 struct anon_vma_chain *avc;
98591 struct anon_vma *anon_vma;
98592@@ -376,8 +410,10 @@ static void anon_vma_ctor(void *data)
98593 void __init anon_vma_init(void)
98594 {
98595 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
98596- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
98597- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
98598+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
98599+ anon_vma_ctor);
98600+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
98601+ SLAB_PANIC|SLAB_NO_SANITIZE);
98602 }
98603
98604 /*
98605diff --git a/mm/shmem.c b/mm/shmem.c
98606index 185836b..d7255a1 100644
98607--- a/mm/shmem.c
98608+++ b/mm/shmem.c
98609@@ -33,7 +33,7 @@
98610 #include <linux/swap.h>
98611 #include <linux/aio.h>
98612
98613-static struct vfsmount *shm_mnt;
98614+struct vfsmount *shm_mnt;
98615
98616 #ifdef CONFIG_SHMEM
98617 /*
98618@@ -80,7 +80,7 @@ static struct vfsmount *shm_mnt;
98619 #define BOGO_DIRENT_SIZE 20
98620
98621 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
98622-#define SHORT_SYMLINK_LEN 128
98623+#define SHORT_SYMLINK_LEN 64
98624
98625 /*
98626 * shmem_fallocate communicates with shmem_fault or shmem_writepage via
98627@@ -2558,6 +2558,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
98628 static int shmem_xattr_validate(const char *name)
98629 {
98630 struct { const char *prefix; size_t len; } arr[] = {
98631+
98632+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
98633+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
98634+#endif
98635+
98636 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
98637 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
98638 };
98639@@ -2613,6 +2618,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
98640 if (err)
98641 return err;
98642
98643+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
98644+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
98645+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
98646+ return -EOPNOTSUPP;
98647+ if (size > 8)
98648+ return -EINVAL;
98649+ }
98650+#endif
98651+
98652 return simple_xattr_set(&info->xattrs, name, value, size, flags);
98653 }
98654
98655@@ -2996,8 +3010,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
98656 int err = -ENOMEM;
98657
98658 /* Round up to L1_CACHE_BYTES to resist false sharing */
98659- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
98660- L1_CACHE_BYTES), GFP_KERNEL);
98661+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
98662 if (!sbinfo)
98663 return -ENOMEM;
98664
98665diff --git a/mm/slab.c b/mm/slab.c
98666index f34e053..78a3839 100644
98667--- a/mm/slab.c
98668+++ b/mm/slab.c
98669@@ -314,10 +314,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
98670 if ((x)->max_freeable < i) \
98671 (x)->max_freeable = i; \
98672 } while (0)
98673-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
98674-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
98675-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
98676-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
98677+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
98678+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
98679+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
98680+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
98681+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
98682+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
98683 #else
98684 #define STATS_INC_ACTIVE(x) do { } while (0)
98685 #define STATS_DEC_ACTIVE(x) do { } while (0)
98686@@ -334,6 +336,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
98687 #define STATS_INC_ALLOCMISS(x) do { } while (0)
98688 #define STATS_INC_FREEHIT(x) do { } while (0)
98689 #define STATS_INC_FREEMISS(x) do { } while (0)
98690+#define STATS_INC_SANITIZED(x) do { } while (0)
98691+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
98692 #endif
98693
98694 #if DEBUG
98695@@ -450,7 +454,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
98696 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
98697 */
98698 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
98699- const struct page *page, void *obj)
98700+ const struct page *page, const void *obj)
98701 {
98702 u32 offset = (obj - page->s_mem);
98703 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
98704@@ -1438,7 +1442,7 @@ void __init kmem_cache_init(void)
98705 * structures first. Without this, further allocations will bug.
98706 */
98707 kmalloc_caches[INDEX_NODE] = create_kmalloc_cache("kmalloc-node",
98708- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
98709+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
98710 slab_state = PARTIAL_NODE;
98711
98712 slab_early_init = 0;
98713@@ -2059,7 +2063,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
98714
98715 cachep = find_mergeable(size, align, flags, name, ctor);
98716 if (cachep) {
98717- cachep->refcount++;
98718+ atomic_inc(&cachep->refcount);
98719
98720 /*
98721 * Adjust the object sizes so that we clear
98722@@ -3352,6 +3356,20 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
98723 struct array_cache *ac = cpu_cache_get(cachep);
98724
98725 check_irq_off();
98726+
98727+#ifdef CONFIG_PAX_MEMORY_SANITIZE
98728+ if (cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))
98729+ STATS_INC_NOT_SANITIZED(cachep);
98730+ else {
98731+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
98732+
98733+ if (cachep->ctor)
98734+ cachep->ctor(objp);
98735+
98736+ STATS_INC_SANITIZED(cachep);
98737+ }
98738+#endif
98739+
98740 kmemleak_free_recursive(objp, cachep->flags);
98741 objp = cache_free_debugcheck(cachep, objp, caller);
98742
98743@@ -3557,6 +3575,7 @@ void kfree(const void *objp)
98744
98745 if (unlikely(ZERO_OR_NULL_PTR(objp)))
98746 return;
98747+ VM_BUG_ON(!virt_addr_valid(objp));
98748 local_irq_save(flags);
98749 kfree_debugcheck(objp);
98750 c = virt_to_cache(objp);
98751@@ -3979,14 +3998,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
98752 }
98753 /* cpu stats */
98754 {
98755- unsigned long allochit = atomic_read(&cachep->allochit);
98756- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
98757- unsigned long freehit = atomic_read(&cachep->freehit);
98758- unsigned long freemiss = atomic_read(&cachep->freemiss);
98759+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
98760+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
98761+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
98762+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
98763
98764 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
98765 allochit, allocmiss, freehit, freemiss);
98766 }
98767+#ifdef CONFIG_PAX_MEMORY_SANITIZE
98768+ {
98769+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
98770+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
98771+
98772+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
98773+ }
98774+#endif
98775 #endif
98776 }
98777
98778@@ -4200,13 +4227,69 @@ static const struct file_operations proc_slabstats_operations = {
98779 static int __init slab_proc_init(void)
98780 {
98781 #ifdef CONFIG_DEBUG_SLAB_LEAK
98782- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
98783+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
98784 #endif
98785 return 0;
98786 }
98787 module_init(slab_proc_init);
98788 #endif
98789
98790+bool is_usercopy_object(const void *ptr)
98791+{
98792+ struct page *page;
98793+ struct kmem_cache *cachep;
98794+
98795+ if (ZERO_OR_NULL_PTR(ptr))
98796+ return false;
98797+
98798+ if (!slab_is_available())
98799+ return false;
98800+
98801+ if (!virt_addr_valid(ptr))
98802+ return false;
98803+
98804+ page = virt_to_head_page(ptr);
98805+
98806+ if (!PageSlab(page))
98807+ return false;
98808+
98809+ cachep = page->slab_cache;
98810+ return cachep->flags & SLAB_USERCOPY;
98811+}
98812+
98813+#ifdef CONFIG_PAX_USERCOPY
98814+const char *check_heap_object(const void *ptr, unsigned long n)
98815+{
98816+ struct page *page;
98817+ struct kmem_cache *cachep;
98818+ unsigned int objnr;
98819+ unsigned long offset;
98820+
98821+ if (ZERO_OR_NULL_PTR(ptr))
98822+ return "<null>";
98823+
98824+ if (!virt_addr_valid(ptr))
98825+ return NULL;
98826+
98827+ page = virt_to_head_page(ptr);
98828+
98829+ if (!PageSlab(page))
98830+ return NULL;
98831+
98832+ cachep = page->slab_cache;
98833+ if (!(cachep->flags & SLAB_USERCOPY))
98834+ return cachep->name;
98835+
98836+ objnr = obj_to_index(cachep, page, ptr);
98837+ BUG_ON(objnr >= cachep->num);
98838+ offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
98839+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
98840+ return NULL;
98841+
98842+ return cachep->name;
98843+}
98844+#endif
98845+
98846 /**
98847 * ksize - get the actual amount of memory allocated for a given object
98848 * @objp: Pointer to the object
98849diff --git a/mm/slab.h b/mm/slab.h
98850index ab019e6..fbcac34 100644
98851--- a/mm/slab.h
98852+++ b/mm/slab.h
98853@@ -22,7 +22,7 @@ struct kmem_cache {
98854 unsigned int align; /* Alignment as calculated */
98855 unsigned long flags; /* Active flags on the slab */
98856 const char *name; /* Slab name for sysfs */
98857- int refcount; /* Use counter */
98858+ atomic_t refcount; /* Use counter */
98859 void (*ctor)(void *); /* Called on object slot creation */
98860 struct list_head list; /* List of all slab caches on the system */
98861 };
98862@@ -66,6 +66,20 @@ extern struct list_head slab_caches;
98863 /* The slab cache that manages slab cache information */
98864 extern struct kmem_cache *kmem_cache;
98865
98866+#ifdef CONFIG_PAX_MEMORY_SANITIZE
98867+#ifdef CONFIG_X86_64
98868+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
98869+#else
98870+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
98871+#endif
98872+enum pax_sanitize_mode {
98873+ PAX_SANITIZE_SLAB_OFF = 0,
98874+ PAX_SANITIZE_SLAB_FAST,
98875+ PAX_SANITIZE_SLAB_FULL,
98876+};
98877+extern enum pax_sanitize_mode pax_sanitize_slab;
98878+#endif
98879+
98880 unsigned long calculate_alignment(unsigned long flags,
98881 unsigned long align, unsigned long size);
98882
98883@@ -116,7 +130,8 @@ static inline unsigned long kmem_cache_flags(unsigned long object_size,
98884
98885 /* Legal flag mask for kmem_cache_create(), for various configurations */
98886 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
98887- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
98888+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
98889+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
98890
98891 #if defined(CONFIG_DEBUG_SLAB)
98892 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
98893@@ -300,6 +315,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
98894 return s;
98895
98896 page = virt_to_head_page(x);
98897+
98898+ BUG_ON(!PageSlab(page));
98899+
98900 cachep = page->slab_cache;
98901 if (slab_equal_or_root(cachep, s))
98902 return cachep;
98903diff --git a/mm/slab_common.c b/mm/slab_common.c
98904index dcdab81..3576646 100644
98905--- a/mm/slab_common.c
98906+++ b/mm/slab_common.c
98907@@ -25,11 +25,35 @@
98908
98909 #include "slab.h"
98910
98911-enum slab_state slab_state;
98912+enum slab_state slab_state __read_only;
98913 LIST_HEAD(slab_caches);
98914 DEFINE_MUTEX(slab_mutex);
98915 struct kmem_cache *kmem_cache;
98916
98917+#ifdef CONFIG_PAX_MEMORY_SANITIZE
98918+enum pax_sanitize_mode pax_sanitize_slab __read_only = PAX_SANITIZE_SLAB_FAST;
98919+static int __init pax_sanitize_slab_setup(char *str)
98920+{
98921+ if (!str)
98922+ return 0;
98923+
98924+ if (!strcmp(str, "0") || !strcmp(str, "off")) {
98925+ pr_info("PaX slab sanitization: %s\n", "disabled");
98926+ pax_sanitize_slab = PAX_SANITIZE_SLAB_OFF;
98927+ } else if (!strcmp(str, "1") || !strcmp(str, "fast")) {
98928+ pr_info("PaX slab sanitization: %s\n", "fast");
98929+ pax_sanitize_slab = PAX_SANITIZE_SLAB_FAST;
98930+ } else if (!strcmp(str, "full")) {
98931+ pr_info("PaX slab sanitization: %s\n", "full");
98932+ pax_sanitize_slab = PAX_SANITIZE_SLAB_FULL;
98933+ } else
98934+ pr_err("PaX slab sanitization: unsupported option '%s'\n", str);
98935+
98936+ return 0;
98937+}
98938+early_param("pax_sanitize_slab", pax_sanitize_slab_setup);
98939+#endif
98940+
98941 /*
98942 * Set of flags that will prevent slab merging
98943 */
98944@@ -44,7 +68,7 @@ struct kmem_cache *kmem_cache;
98945 * Merge control. If this is set then no merging of slab caches will occur.
98946 * (Could be removed. This was introduced to pacify the merge skeptics.)
98947 */
98948-static int slab_nomerge;
98949+static int slab_nomerge = 1;
98950
98951 static int __init setup_slab_nomerge(char *str)
98952 {
98953@@ -218,7 +242,7 @@ int slab_unmergeable(struct kmem_cache *s)
98954 /*
98955 * We may have set a slab to be unmergeable during bootstrap.
98956 */
98957- if (s->refcount < 0)
98958+ if (atomic_read(&s->refcount) < 0)
98959 return 1;
98960
98961 return 0;
98962@@ -322,7 +346,7 @@ do_kmem_cache_create(char *name, size_t object_size, size_t size, size_t align,
98963 if (err)
98964 goto out_free_cache;
98965
98966- s->refcount = 1;
98967+ atomic_set(&s->refcount, 1);
98968 list_add(&s->list, &slab_caches);
98969 out:
98970 if (err)
98971@@ -386,6 +410,13 @@ kmem_cache_create(const char *name, size_t size, size_t align,
98972 */
98973 flags &= CACHE_CREATE_MASK;
98974
98975+#ifdef CONFIG_PAX_MEMORY_SANITIZE
98976+ if (pax_sanitize_slab == PAX_SANITIZE_SLAB_OFF || (flags & SLAB_DESTROY_BY_RCU))
98977+ flags |= SLAB_NO_SANITIZE;
98978+ else if (pax_sanitize_slab == PAX_SANITIZE_SLAB_FULL)
98979+ flags &= ~SLAB_NO_SANITIZE;
98980+#endif
98981+
98982 s = __kmem_cache_alias(name, size, align, flags, ctor);
98983 if (s)
98984 goto out_unlock;
98985@@ -505,8 +536,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
98986
98987 mutex_lock(&slab_mutex);
98988
98989- s->refcount--;
98990- if (s->refcount)
98991+ if (!atomic_dec_and_test(&s->refcount))
98992 goto out_unlock;
98993
98994 if (memcg_cleanup_cache_params(s) != 0)
98995@@ -526,7 +556,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
98996 rcu_barrier();
98997
98998 memcg_free_cache_params(s);
98999-#ifdef SLAB_SUPPORTS_SYSFS
99000+#if defined(SLAB_SUPPORTS_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99001 sysfs_slab_remove(s);
99002 #else
99003 slab_kmem_cache_release(s);
99004@@ -582,7 +612,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
99005 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
99006 name, size, err);
99007
99008- s->refcount = -1; /* Exempt from merging for now */
99009+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
99010 }
99011
99012 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
99013@@ -595,7 +625,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
99014
99015 create_boot_cache(s, name, size, flags);
99016 list_add(&s->list, &slab_caches);
99017- s->refcount = 1;
99018+ atomic_set(&s->refcount, 1);
99019 return s;
99020 }
99021
99022@@ -607,6 +637,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
99023 EXPORT_SYMBOL(kmalloc_dma_caches);
99024 #endif
99025
99026+#ifdef CONFIG_PAX_USERCOPY_SLABS
99027+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
99028+EXPORT_SYMBOL(kmalloc_usercopy_caches);
99029+#endif
99030+
99031 /*
99032 * Conversion table for small slabs sizes / 8 to the index in the
99033 * kmalloc array. This is necessary for slabs < 192 since we have non power
99034@@ -671,6 +706,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
99035 return kmalloc_dma_caches[index];
99036
99037 #endif
99038+
99039+#ifdef CONFIG_PAX_USERCOPY_SLABS
99040+ if (unlikely((flags & GFP_USERCOPY)))
99041+ return kmalloc_usercopy_caches[index];
99042+
99043+#endif
99044+
99045 return kmalloc_caches[index];
99046 }
99047
99048@@ -727,7 +769,7 @@ void __init create_kmalloc_caches(unsigned long flags)
99049 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
99050 if (!kmalloc_caches[i]) {
99051 kmalloc_caches[i] = create_kmalloc_cache(NULL,
99052- 1 << i, flags);
99053+ 1 << i, SLAB_USERCOPY | flags);
99054 }
99055
99056 /*
99057@@ -736,10 +778,10 @@ void __init create_kmalloc_caches(unsigned long flags)
99058 * earlier power of two caches
99059 */
99060 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
99061- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
99062+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
99063
99064 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
99065- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
99066+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
99067 }
99068
99069 /* Kmalloc array is now usable */
99070@@ -772,6 +814,23 @@ void __init create_kmalloc_caches(unsigned long flags)
99071 }
99072 }
99073 #endif
99074+
99075+#ifdef CONFIG_PAX_USERCOPY_SLABS
99076+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
99077+ struct kmem_cache *s = kmalloc_caches[i];
99078+
99079+ if (s) {
99080+ int size = kmalloc_size(i);
99081+ char *n = kasprintf(GFP_NOWAIT,
99082+ "usercopy-kmalloc-%d", size);
99083+
99084+ BUG_ON(!n);
99085+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
99086+ size, SLAB_USERCOPY | flags);
99087+ }
99088+ }
99089+#endif
99090+
99091 }
99092 #endif /* !CONFIG_SLOB */
99093
99094@@ -830,6 +889,9 @@ void print_slabinfo_header(struct seq_file *m)
99095 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
99096 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
99097 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
99098+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99099+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
99100+#endif
99101 #endif
99102 seq_putc(m, '\n');
99103 }
99104diff --git a/mm/slob.c b/mm/slob.c
99105index 96a8620..3e7e663 100644
99106--- a/mm/slob.c
99107+++ b/mm/slob.c
99108@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
99109 /*
99110 * Return the size of a slob block.
99111 */
99112-static slobidx_t slob_units(slob_t *s)
99113+static slobidx_t slob_units(const slob_t *s)
99114 {
99115 if (s->units > 0)
99116 return s->units;
99117@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
99118 /*
99119 * Return the next free slob block pointer after this one.
99120 */
99121-static slob_t *slob_next(slob_t *s)
99122+static slob_t *slob_next(const slob_t *s)
99123 {
99124 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
99125 slobidx_t next;
99126@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
99127 /*
99128 * Returns true if s is the last free block in its page.
99129 */
99130-static int slob_last(slob_t *s)
99131+static int slob_last(const slob_t *s)
99132 {
99133 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
99134 }
99135
99136-static void *slob_new_pages(gfp_t gfp, int order, int node)
99137+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
99138 {
99139- void *page;
99140+ struct page *page;
99141
99142 #ifdef CONFIG_NUMA
99143 if (node != NUMA_NO_NODE)
99144@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
99145 if (!page)
99146 return NULL;
99147
99148- return page_address(page);
99149+ __SetPageSlab(page);
99150+ return page;
99151 }
99152
99153-static void slob_free_pages(void *b, int order)
99154+static void slob_free_pages(struct page *sp, int order)
99155 {
99156 if (current->reclaim_state)
99157 current->reclaim_state->reclaimed_slab += 1 << order;
99158- free_pages((unsigned long)b, order);
99159+ __ClearPageSlab(sp);
99160+ page_mapcount_reset(sp);
99161+ sp->private = 0;
99162+ __free_pages(sp, order);
99163 }
99164
99165 /*
99166@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
99167
99168 /* Not enough space: must allocate a new page */
99169 if (!b) {
99170- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
99171- if (!b)
99172+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
99173+ if (!sp)
99174 return NULL;
99175- sp = virt_to_page(b);
99176- __SetPageSlab(sp);
99177+ b = page_address(sp);
99178
99179 spin_lock_irqsave(&slob_lock, flags);
99180 sp->units = SLOB_UNITS(PAGE_SIZE);
99181 sp->freelist = b;
99182+ sp->private = 0;
99183 INIT_LIST_HEAD(&sp->lru);
99184 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
99185 set_slob_page_free(sp, slob_list);
99186@@ -337,7 +341,7 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
99187 /*
99188 * slob_free: entry point into the slob allocator.
99189 */
99190-static void slob_free(void *block, int size)
99191+static void slob_free(struct kmem_cache *c, void *block, int size)
99192 {
99193 struct page *sp;
99194 slob_t *prev, *next, *b = (slob_t *)block;
99195@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
99196 if (slob_page_free(sp))
99197 clear_slob_page_free(sp);
99198 spin_unlock_irqrestore(&slob_lock, flags);
99199- __ClearPageSlab(sp);
99200- page_mapcount_reset(sp);
99201- slob_free_pages(b, 0);
99202+ slob_free_pages(sp, 0);
99203 return;
99204 }
99205
99206+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99207+ if (pax_sanitize_slab && !(c && (c->flags & SLAB_NO_SANITIZE)))
99208+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
99209+#endif
99210+
99211 if (!slob_page_free(sp)) {
99212 /* This slob page is about to become partially free. Easy! */
99213 sp->units = units;
99214@@ -424,11 +431,10 @@ out:
99215 */
99216
99217 static __always_inline void *
99218-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99219+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
99220 {
99221- unsigned int *m;
99222- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99223- void *ret;
99224+ slob_t *m;
99225+ void *ret = NULL;
99226
99227 gfp &= gfp_allowed_mask;
99228
99229@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99230
99231 if (!m)
99232 return NULL;
99233- *m = size;
99234+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
99235+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
99236+ m[0].units = size;
99237+ m[1].units = align;
99238 ret = (void *)m + align;
99239
99240 trace_kmalloc_node(caller, ret,
99241 size, size + align, gfp, node);
99242 } else {
99243 unsigned int order = get_order(size);
99244+ struct page *page;
99245
99246 if (likely(order))
99247 gfp |= __GFP_COMP;
99248- ret = slob_new_pages(gfp, order, node);
99249+ page = slob_new_pages(gfp, order, node);
99250+ if (page) {
99251+ ret = page_address(page);
99252+ page->private = size;
99253+ }
99254
99255 trace_kmalloc_node(caller, ret,
99256 size, PAGE_SIZE << order, gfp, node);
99257 }
99258
99259- kmemleak_alloc(ret, size, 1, gfp);
99260+ return ret;
99261+}
99262+
99263+static __always_inline void *
99264+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99265+{
99266+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99267+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
99268+
99269+ if (!ZERO_OR_NULL_PTR(ret))
99270+ kmemleak_alloc(ret, size, 1, gfp);
99271 return ret;
99272 }
99273
99274@@ -491,34 +515,112 @@ void kfree(const void *block)
99275 return;
99276 kmemleak_free(block);
99277
99278+ VM_BUG_ON(!virt_addr_valid(block));
99279 sp = virt_to_page(block);
99280- if (PageSlab(sp)) {
99281+ VM_BUG_ON(!PageSlab(sp));
99282+ if (!sp->private) {
99283 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99284- unsigned int *m = (unsigned int *)(block - align);
99285- slob_free(m, *m + align);
99286- } else
99287+ slob_t *m = (slob_t *)(block - align);
99288+ slob_free(NULL, m, m[0].units + align);
99289+ } else {
99290+ __ClearPageSlab(sp);
99291+ page_mapcount_reset(sp);
99292+ sp->private = 0;
99293 __free_pages(sp, compound_order(sp));
99294+ }
99295 }
99296 EXPORT_SYMBOL(kfree);
99297
99298+bool is_usercopy_object(const void *ptr)
99299+{
99300+ if (!slab_is_available())
99301+ return false;
99302+
99303+ // PAX: TODO
99304+
99305+ return false;
99306+}
99307+
99308+#ifdef CONFIG_PAX_USERCOPY
99309+const char *check_heap_object(const void *ptr, unsigned long n)
99310+{
99311+ struct page *page;
99312+ const slob_t *free;
99313+ const void *base;
99314+ unsigned long flags;
99315+
99316+ if (ZERO_OR_NULL_PTR(ptr))
99317+ return "<null>";
99318+
99319+ if (!virt_addr_valid(ptr))
99320+ return NULL;
99321+
99322+ page = virt_to_head_page(ptr);
99323+ if (!PageSlab(page))
99324+ return NULL;
99325+
99326+ if (page->private) {
99327+ base = page;
99328+ if (base <= ptr && n <= page->private - (ptr - base))
99329+ return NULL;
99330+ return "<slob>";
99331+ }
99332+
99333+ /* some tricky double walking to find the chunk */
99334+ spin_lock_irqsave(&slob_lock, flags);
99335+ base = (void *)((unsigned long)ptr & PAGE_MASK);
99336+ free = page->freelist;
99337+
99338+ while (!slob_last(free) && (void *)free <= ptr) {
99339+ base = free + slob_units(free);
99340+ free = slob_next(free);
99341+ }
99342+
99343+ while (base < (void *)free) {
99344+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
99345+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
99346+ int offset;
99347+
99348+ if (ptr < base + align)
99349+ break;
99350+
99351+ offset = ptr - base - align;
99352+ if (offset >= m) {
99353+ base += size;
99354+ continue;
99355+ }
99356+
99357+ if (n > m - offset)
99358+ break;
99359+
99360+ spin_unlock_irqrestore(&slob_lock, flags);
99361+ return NULL;
99362+ }
99363+
99364+ spin_unlock_irqrestore(&slob_lock, flags);
99365+ return "<slob>";
99366+}
99367+#endif
99368+
99369 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
99370 size_t ksize(const void *block)
99371 {
99372 struct page *sp;
99373 int align;
99374- unsigned int *m;
99375+ slob_t *m;
99376
99377 BUG_ON(!block);
99378 if (unlikely(block == ZERO_SIZE_PTR))
99379 return 0;
99380
99381 sp = virt_to_page(block);
99382- if (unlikely(!PageSlab(sp)))
99383- return PAGE_SIZE << compound_order(sp);
99384+ VM_BUG_ON(!PageSlab(sp));
99385+ if (sp->private)
99386+ return sp->private;
99387
99388 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99389- m = (unsigned int *)(block - align);
99390- return SLOB_UNITS(*m) * SLOB_UNIT;
99391+ m = (slob_t *)(block - align);
99392+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
99393 }
99394 EXPORT_SYMBOL(ksize);
99395
99396@@ -534,23 +636,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
99397
99398 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
99399 {
99400- void *b;
99401+ void *b = NULL;
99402
99403 flags &= gfp_allowed_mask;
99404
99405 lockdep_trace_alloc(flags);
99406
99407+#ifdef CONFIG_PAX_USERCOPY_SLABS
99408+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
99409+#else
99410 if (c->size < PAGE_SIZE) {
99411 b = slob_alloc(c->size, flags, c->align, node);
99412 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
99413 SLOB_UNITS(c->size) * SLOB_UNIT,
99414 flags, node);
99415 } else {
99416- b = slob_new_pages(flags, get_order(c->size), node);
99417+ struct page *sp;
99418+
99419+ sp = slob_new_pages(flags, get_order(c->size), node);
99420+ if (sp) {
99421+ b = page_address(sp);
99422+ sp->private = c->size;
99423+ }
99424 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
99425 PAGE_SIZE << get_order(c->size),
99426 flags, node);
99427 }
99428+#endif
99429
99430 if (b && c->ctor)
99431 c->ctor(b);
99432@@ -580,12 +692,16 @@ void *kmem_cache_alloc_node(struct kmem_cache *cachep, gfp_t gfp, int node)
99433 EXPORT_SYMBOL(kmem_cache_alloc_node);
99434 #endif
99435
99436-static void __kmem_cache_free(void *b, int size)
99437+static void __kmem_cache_free(struct kmem_cache *c, void *b, int size)
99438 {
99439- if (size < PAGE_SIZE)
99440- slob_free(b, size);
99441+ struct page *sp;
99442+
99443+ sp = virt_to_page(b);
99444+ BUG_ON(!PageSlab(sp));
99445+ if (!sp->private)
99446+ slob_free(c, b, size);
99447 else
99448- slob_free_pages(b, get_order(size));
99449+ slob_free_pages(sp, get_order(size));
99450 }
99451
99452 static void kmem_rcu_free(struct rcu_head *head)
99453@@ -593,22 +709,36 @@ static void kmem_rcu_free(struct rcu_head *head)
99454 struct slob_rcu *slob_rcu = (struct slob_rcu *)head;
99455 void *b = (void *)slob_rcu - (slob_rcu->size - sizeof(struct slob_rcu));
99456
99457- __kmem_cache_free(b, slob_rcu->size);
99458+ __kmem_cache_free(NULL, b, slob_rcu->size);
99459 }
99460
99461 void kmem_cache_free(struct kmem_cache *c, void *b)
99462 {
99463+ int size = c->size;
99464+
99465+#ifdef CONFIG_PAX_USERCOPY_SLABS
99466+ if (size + c->align < PAGE_SIZE) {
99467+ size += c->align;
99468+ b -= c->align;
99469+ }
99470+#endif
99471+
99472 kmemleak_free_recursive(b, c->flags);
99473 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
99474 struct slob_rcu *slob_rcu;
99475- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
99476- slob_rcu->size = c->size;
99477+ slob_rcu = b + (size - sizeof(struct slob_rcu));
99478+ slob_rcu->size = size;
99479 call_rcu(&slob_rcu->head, kmem_rcu_free);
99480 } else {
99481- __kmem_cache_free(b, c->size);
99482+ __kmem_cache_free(c, b, size);
99483 }
99484
99485+#ifdef CONFIG_PAX_USERCOPY_SLABS
99486+ trace_kfree(_RET_IP_, b);
99487+#else
99488 trace_kmem_cache_free(_RET_IP_, b);
99489+#endif
99490+
99491 }
99492 EXPORT_SYMBOL(kmem_cache_free);
99493
99494diff --git a/mm/slub.c b/mm/slub.c
99495index ae7b9f1..7b3fdbe 100644
99496--- a/mm/slub.c
99497+++ b/mm/slub.c
99498@@ -197,7 +197,7 @@ struct track {
99499
99500 enum track_item { TRACK_ALLOC, TRACK_FREE };
99501
99502-#ifdef CONFIG_SYSFS
99503+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99504 static int sysfs_slab_add(struct kmem_cache *);
99505 static int sysfs_slab_alias(struct kmem_cache *, const char *);
99506 static void memcg_propagate_slab_attrs(struct kmem_cache *s);
99507@@ -535,7 +535,7 @@ static void print_track(const char *s, struct track *t)
99508 if (!t->addr)
99509 return;
99510
99511- pr_err("INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
99512+ pr_err("INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
99513 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
99514 #ifdef CONFIG_STACKTRACE
99515 {
99516@@ -2645,6 +2645,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
99517
99518 slab_free_hook(s, x);
99519
99520+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99521+ if (!(s->flags & SLAB_NO_SANITIZE)) {
99522+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
99523+ if (s->ctor)
99524+ s->ctor(x);
99525+ }
99526+#endif
99527+
99528 redo:
99529 /*
99530 * Determine the currently cpus per cpu slab.
99531@@ -2982,6 +2990,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
99532 s->inuse = size;
99533
99534 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
99535+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99536+ (!(flags & SLAB_NO_SANITIZE)) ||
99537+#endif
99538 s->ctor)) {
99539 /*
99540 * Relocate free pointer after the object if it is not
99541@@ -3301,6 +3312,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
99542 EXPORT_SYMBOL(__kmalloc_node);
99543 #endif
99544
99545+bool is_usercopy_object(const void *ptr)
99546+{
99547+ struct page *page;
99548+ struct kmem_cache *s;
99549+
99550+ if (ZERO_OR_NULL_PTR(ptr))
99551+ return false;
99552+
99553+ if (!slab_is_available())
99554+ return false;
99555+
99556+ if (!virt_addr_valid(ptr))
99557+ return false;
99558+
99559+ page = virt_to_head_page(ptr);
99560+
99561+ if (!PageSlab(page))
99562+ return false;
99563+
99564+ s = page->slab_cache;
99565+ return s->flags & SLAB_USERCOPY;
99566+}
99567+
99568+#ifdef CONFIG_PAX_USERCOPY
99569+const char *check_heap_object(const void *ptr, unsigned long n)
99570+{
99571+ struct page *page;
99572+ struct kmem_cache *s;
99573+ unsigned long offset;
99574+
99575+ if (ZERO_OR_NULL_PTR(ptr))
99576+ return "<null>";
99577+
99578+ if (!virt_addr_valid(ptr))
99579+ return NULL;
99580+
99581+ page = virt_to_head_page(ptr);
99582+
99583+ if (!PageSlab(page))
99584+ return NULL;
99585+
99586+ s = page->slab_cache;
99587+ if (!(s->flags & SLAB_USERCOPY))
99588+ return s->name;
99589+
99590+ offset = (ptr - page_address(page)) % s->size;
99591+ if (offset <= s->object_size && n <= s->object_size - offset)
99592+ return NULL;
99593+
99594+ return s->name;
99595+}
99596+#endif
99597+
99598 size_t ksize(const void *object)
99599 {
99600 struct page *page;
99601@@ -3329,6 +3393,7 @@ void kfree(const void *x)
99602 if (unlikely(ZERO_OR_NULL_PTR(x)))
99603 return;
99604
99605+ VM_BUG_ON(!virt_addr_valid(x));
99606 page = virt_to_head_page(x);
99607 if (unlikely(!PageSlab(page))) {
99608 BUG_ON(!PageCompound(page));
99609@@ -3624,7 +3689,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
99610 int i;
99611 struct kmem_cache *c;
99612
99613- s->refcount++;
99614+ atomic_inc(&s->refcount);
99615
99616 /*
99617 * Adjust the object sizes so that we clear
99618@@ -3643,7 +3708,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
99619 }
99620
99621 if (sysfs_slab_alias(s, name)) {
99622- s->refcount--;
99623+ atomic_dec(&s->refcount);
99624 s = NULL;
99625 }
99626 }
99627@@ -3760,7 +3825,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
99628 }
99629 #endif
99630
99631-#ifdef CONFIG_SYSFS
99632+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99633 static int count_inuse(struct page *page)
99634 {
99635 return page->inuse;
99636@@ -4041,7 +4106,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
99637 len += sprintf(buf + len, "%7ld ", l->count);
99638
99639 if (l->addr)
99640+#ifdef CONFIG_GRKERNSEC_HIDESYM
99641+ len += sprintf(buf + len, "%pS", NULL);
99642+#else
99643 len += sprintf(buf + len, "%pS", (void *)l->addr);
99644+#endif
99645 else
99646 len += sprintf(buf + len, "<not-available>");
99647
99648@@ -4143,12 +4212,12 @@ static void __init resiliency_test(void)
99649 validate_slab_cache(kmalloc_caches[9]);
99650 }
99651 #else
99652-#ifdef CONFIG_SYSFS
99653+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99654 static void resiliency_test(void) {};
99655 #endif
99656 #endif
99657
99658-#ifdef CONFIG_SYSFS
99659+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99660 enum slab_stat_type {
99661 SL_ALL, /* All slabs */
99662 SL_PARTIAL, /* Only partially allocated slabs */
99663@@ -4385,13 +4454,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
99664 {
99665 if (!s->ctor)
99666 return 0;
99667+#ifdef CONFIG_GRKERNSEC_HIDESYM
99668+ return sprintf(buf, "%pS\n", NULL);
99669+#else
99670 return sprintf(buf, "%pS\n", s->ctor);
99671+#endif
99672 }
99673 SLAB_ATTR_RO(ctor);
99674
99675 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
99676 {
99677- return sprintf(buf, "%d\n", s->refcount < 0 ? 0 : s->refcount - 1);
99678+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) < 0 ? 0 : atomic_read(&s->refcount) - 1);
99679 }
99680 SLAB_ATTR_RO(aliases);
99681
99682@@ -4479,6 +4552,22 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
99683 SLAB_ATTR_RO(cache_dma);
99684 #endif
99685
99686+#ifdef CONFIG_PAX_USERCOPY_SLABS
99687+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
99688+{
99689+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
99690+}
99691+SLAB_ATTR_RO(usercopy);
99692+#endif
99693+
99694+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99695+static ssize_t sanitize_show(struct kmem_cache *s, char *buf)
99696+{
99697+ return sprintf(buf, "%d\n", !(s->flags & SLAB_NO_SANITIZE));
99698+}
99699+SLAB_ATTR_RO(sanitize);
99700+#endif
99701+
99702 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
99703 {
99704 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
99705@@ -4534,7 +4623,7 @@ static ssize_t trace_store(struct kmem_cache *s, const char *buf,
99706 * as well as cause other issues like converting a mergeable
99707 * cache into an umergeable one.
99708 */
99709- if (s->refcount > 1)
99710+ if (atomic_read(&s->refcount) > 1)
99711 return -EINVAL;
99712
99713 s->flags &= ~SLAB_TRACE;
99714@@ -4654,7 +4743,7 @@ static ssize_t failslab_show(struct kmem_cache *s, char *buf)
99715 static ssize_t failslab_store(struct kmem_cache *s, const char *buf,
99716 size_t length)
99717 {
99718- if (s->refcount > 1)
99719+ if (atomic_read(&s->refcount) > 1)
99720 return -EINVAL;
99721
99722 s->flags &= ~SLAB_FAILSLAB;
99723@@ -4824,6 +4913,12 @@ static struct attribute *slab_attrs[] = {
99724 #ifdef CONFIG_ZONE_DMA
99725 &cache_dma_attr.attr,
99726 #endif
99727+#ifdef CONFIG_PAX_USERCOPY_SLABS
99728+ &usercopy_attr.attr,
99729+#endif
99730+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99731+ &sanitize_attr.attr,
99732+#endif
99733 #ifdef CONFIG_NUMA
99734 &remote_node_defrag_ratio_attr.attr,
99735 #endif
99736@@ -5068,6 +5163,7 @@ static char *create_unique_id(struct kmem_cache *s)
99737 return name;
99738 }
99739
99740+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99741 static int sysfs_slab_add(struct kmem_cache *s)
99742 {
99743 int err;
99744@@ -5141,6 +5237,7 @@ void sysfs_slab_remove(struct kmem_cache *s)
99745 kobject_del(&s->kobj);
99746 kobject_put(&s->kobj);
99747 }
99748+#endif
99749
99750 /*
99751 * Need to buffer aliases during bootup until sysfs becomes
99752@@ -5154,6 +5251,7 @@ struct saved_alias {
99753
99754 static struct saved_alias *alias_list;
99755
99756+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99757 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
99758 {
99759 struct saved_alias *al;
99760@@ -5176,6 +5274,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
99761 alias_list = al;
99762 return 0;
99763 }
99764+#endif
99765
99766 static int __init slab_sysfs_init(void)
99767 {
99768diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
99769index 4cba9c2..b4f9fcc 100644
99770--- a/mm/sparse-vmemmap.c
99771+++ b/mm/sparse-vmemmap.c
99772@@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
99773 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
99774 if (!p)
99775 return NULL;
99776- pud_populate(&init_mm, pud, p);
99777+ pud_populate_kernel(&init_mm, pud, p);
99778 }
99779 return pud;
99780 }
99781@@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
99782 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
99783 if (!p)
99784 return NULL;
99785- pgd_populate(&init_mm, pgd, p);
99786+ pgd_populate_kernel(&init_mm, pgd, p);
99787 }
99788 return pgd;
99789 }
99790diff --git a/mm/sparse.c b/mm/sparse.c
99791index d1b48b6..6e8590e 100644
99792--- a/mm/sparse.c
99793+++ b/mm/sparse.c
99794@@ -750,7 +750,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
99795
99796 for (i = 0; i < PAGES_PER_SECTION; i++) {
99797 if (PageHWPoison(&memmap[i])) {
99798- atomic_long_sub(1, &num_poisoned_pages);
99799+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
99800 ClearPageHWPoison(&memmap[i]);
99801 }
99802 }
99803diff --git a/mm/swap.c b/mm/swap.c
99804index 8a12b33..7068e78 100644
99805--- a/mm/swap.c
99806+++ b/mm/swap.c
99807@@ -31,6 +31,7 @@
99808 #include <linux/memcontrol.h>
99809 #include <linux/gfp.h>
99810 #include <linux/uio.h>
99811+#include <linux/hugetlb.h>
99812
99813 #include "internal.h"
99814
99815@@ -77,6 +78,8 @@ static void __put_compound_page(struct page *page)
99816
99817 __page_cache_release(page);
99818 dtor = get_compound_page_dtor(page);
99819+ if (!PageHuge(page))
99820+ BUG_ON(dtor != free_compound_page);
99821 (*dtor)(page);
99822 }
99823
99824diff --git a/mm/swapfile.c b/mm/swapfile.c
99825index 8798b2e..348f9dd 100644
99826--- a/mm/swapfile.c
99827+++ b/mm/swapfile.c
99828@@ -84,7 +84,7 @@ static DEFINE_MUTEX(swapon_mutex);
99829
99830 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
99831 /* Activity counter to indicate that a swapon or swapoff has occurred */
99832-static atomic_t proc_poll_event = ATOMIC_INIT(0);
99833+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
99834
99835 static inline unsigned char swap_count(unsigned char ent)
99836 {
99837@@ -1944,7 +1944,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
99838 spin_unlock(&swap_lock);
99839
99840 err = 0;
99841- atomic_inc(&proc_poll_event);
99842+ atomic_inc_unchecked(&proc_poll_event);
99843 wake_up_interruptible(&proc_poll_wait);
99844
99845 out_dput:
99846@@ -1961,8 +1961,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
99847
99848 poll_wait(file, &proc_poll_wait, wait);
99849
99850- if (seq->poll_event != atomic_read(&proc_poll_event)) {
99851- seq->poll_event = atomic_read(&proc_poll_event);
99852+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
99853+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
99854 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
99855 }
99856
99857@@ -2060,7 +2060,7 @@ static int swaps_open(struct inode *inode, struct file *file)
99858 return ret;
99859
99860 seq = file->private_data;
99861- seq->poll_event = atomic_read(&proc_poll_event);
99862+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
99863 return 0;
99864 }
99865
99866@@ -2520,7 +2520,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
99867 (frontswap_map) ? "FS" : "");
99868
99869 mutex_unlock(&swapon_mutex);
99870- atomic_inc(&proc_poll_event);
99871+ atomic_inc_unchecked(&proc_poll_event);
99872 wake_up_interruptible(&proc_poll_wait);
99873
99874 if (S_ISREG(inode->i_mode))
99875diff --git a/mm/util.c b/mm/util.c
99876index fec39d4..3e60325 100644
99877--- a/mm/util.c
99878+++ b/mm/util.c
99879@@ -195,6 +195,12 @@ struct task_struct *task_of_stack(struct task_struct *task,
99880 void arch_pick_mmap_layout(struct mm_struct *mm)
99881 {
99882 mm->mmap_base = TASK_UNMAPPED_BASE;
99883+
99884+#ifdef CONFIG_PAX_RANDMMAP
99885+ if (mm->pax_flags & MF_PAX_RANDMMAP)
99886+ mm->mmap_base += mm->delta_mmap;
99887+#endif
99888+
99889 mm->get_unmapped_area = arch_get_unmapped_area;
99890 }
99891 #endif
99892@@ -371,6 +377,9 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
99893 if (!mm->arg_end)
99894 goto out_mm; /* Shh! No looking before we're done */
99895
99896+ if (gr_acl_handle_procpidmem(task))
99897+ goto out_mm;
99898+
99899 len = mm->arg_end - mm->arg_start;
99900
99901 if (len > buflen)
99902diff --git a/mm/vmalloc.c b/mm/vmalloc.c
99903index 90520af..24231aa 100644
99904--- a/mm/vmalloc.c
99905+++ b/mm/vmalloc.c
99906@@ -40,6 +40,21 @@ struct vfree_deferred {
99907 };
99908 static DEFINE_PER_CPU(struct vfree_deferred, vfree_deferred);
99909
99910+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
99911+struct stack_deferred_llist {
99912+ struct llist_head list;
99913+ void *stack;
99914+ void *lowmem_stack;
99915+};
99916+
99917+struct stack_deferred {
99918+ struct stack_deferred_llist list;
99919+ struct work_struct wq;
99920+};
99921+
99922+static DEFINE_PER_CPU(struct stack_deferred, stack_deferred);
99923+#endif
99924+
99925 static void __vunmap(const void *, int);
99926
99927 static void free_work(struct work_struct *w)
99928@@ -47,12 +62,30 @@ static void free_work(struct work_struct *w)
99929 struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq);
99930 struct llist_node *llnode = llist_del_all(&p->list);
99931 while (llnode) {
99932- void *p = llnode;
99933+ void *x = llnode;
99934 llnode = llist_next(llnode);
99935- __vunmap(p, 1);
99936+ __vunmap(x, 1);
99937 }
99938 }
99939
99940+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
99941+static void unmap_work(struct work_struct *w)
99942+{
99943+ struct stack_deferred *p = container_of(w, struct stack_deferred, wq);
99944+ struct llist_node *llnode = llist_del_all(&p->list.list);
99945+ while (llnode) {
99946+ struct stack_deferred_llist *x =
99947+ llist_entry((struct llist_head *)llnode,
99948+ struct stack_deferred_llist, list);
99949+ void *stack = ACCESS_ONCE(x->stack);
99950+ void *lowmem_stack = ACCESS_ONCE(x->lowmem_stack);
99951+ llnode = llist_next(llnode);
99952+ __vunmap(stack, 0);
99953+ free_kmem_pages((unsigned long)lowmem_stack, THREAD_SIZE_ORDER);
99954+ }
99955+}
99956+#endif
99957+
99958 /*** Page table manipulation functions ***/
99959
99960 static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
99961@@ -61,8 +94,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
99962
99963 pte = pte_offset_kernel(pmd, addr);
99964 do {
99965- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
99966- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
99967+
99968+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
99969+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
99970+ BUG_ON(!pte_exec(*pte));
99971+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
99972+ continue;
99973+ }
99974+#endif
99975+
99976+ {
99977+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
99978+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
99979+ }
99980 } while (pte++, addr += PAGE_SIZE, addr != end);
99981 }
99982
99983@@ -122,16 +166,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
99984 pte = pte_alloc_kernel(pmd, addr);
99985 if (!pte)
99986 return -ENOMEM;
99987+
99988+ pax_open_kernel();
99989 do {
99990 struct page *page = pages[*nr];
99991
99992- if (WARN_ON(!pte_none(*pte)))
99993+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
99994+ if (pgprot_val(prot) & _PAGE_NX)
99995+#endif
99996+
99997+ if (!pte_none(*pte)) {
99998+ pax_close_kernel();
99999+ WARN_ON(1);
100000 return -EBUSY;
100001- if (WARN_ON(!page))
100002+ }
100003+ if (!page) {
100004+ pax_close_kernel();
100005+ WARN_ON(1);
100006 return -ENOMEM;
100007+ }
100008 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
100009 (*nr)++;
100010 } while (pte++, addr += PAGE_SIZE, addr != end);
100011+ pax_close_kernel();
100012 return 0;
100013 }
100014
100015@@ -141,7 +198,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
100016 pmd_t *pmd;
100017 unsigned long next;
100018
100019- pmd = pmd_alloc(&init_mm, pud, addr);
100020+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
100021 if (!pmd)
100022 return -ENOMEM;
100023 do {
100024@@ -158,7 +215,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
100025 pud_t *pud;
100026 unsigned long next;
100027
100028- pud = pud_alloc(&init_mm, pgd, addr);
100029+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
100030 if (!pud)
100031 return -ENOMEM;
100032 do {
100033@@ -218,6 +275,12 @@ int is_vmalloc_or_module_addr(const void *x)
100034 if (addr >= MODULES_VADDR && addr < MODULES_END)
100035 return 1;
100036 #endif
100037+
100038+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100039+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
100040+ return 1;
100041+#endif
100042+
100043 return is_vmalloc_addr(x);
100044 }
100045
100046@@ -238,8 +301,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
100047
100048 if (!pgd_none(*pgd)) {
100049 pud_t *pud = pud_offset(pgd, addr);
100050+#ifdef CONFIG_X86
100051+ if (!pud_large(*pud))
100052+#endif
100053 if (!pud_none(*pud)) {
100054 pmd_t *pmd = pmd_offset(pud, addr);
100055+#ifdef CONFIG_X86
100056+ if (!pmd_large(*pmd))
100057+#endif
100058 if (!pmd_none(*pmd)) {
100059 pte_t *ptep, pte;
100060
100061@@ -1183,13 +1252,23 @@ void __init vmalloc_init(void)
100062 for_each_possible_cpu(i) {
100063 struct vmap_block_queue *vbq;
100064 struct vfree_deferred *p;
100065+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100066+ struct stack_deferred *p2;
100067+#endif
100068
100069 vbq = &per_cpu(vmap_block_queue, i);
100070 spin_lock_init(&vbq->lock);
100071 INIT_LIST_HEAD(&vbq->free);
100072+
100073 p = &per_cpu(vfree_deferred, i);
100074 init_llist_head(&p->list);
100075 INIT_WORK(&p->wq, free_work);
100076+
100077+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100078+ p2 = &per_cpu(stack_deferred, i);
100079+ init_llist_head(&p2->list.list);
100080+ INIT_WORK(&p2->wq, unmap_work);
100081+#endif
100082 }
100083
100084 /* Import existing vmlist entries. */
100085@@ -1314,6 +1393,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
100086 struct vm_struct *area;
100087
100088 BUG_ON(in_interrupt());
100089+
100090+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100091+ if (flags & VM_KERNEXEC) {
100092+ if (start != VMALLOC_START || end != VMALLOC_END)
100093+ return NULL;
100094+ start = (unsigned long)MODULES_EXEC_VADDR;
100095+ end = (unsigned long)MODULES_EXEC_END;
100096+ }
100097+#endif
100098+
100099 if (flags & VM_IOREMAP)
100100 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
100101
100102@@ -1519,6 +1608,23 @@ void vunmap(const void *addr)
100103 }
100104 EXPORT_SYMBOL(vunmap);
100105
100106+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100107+void unmap_process_stacks(struct task_struct *task)
100108+{
100109+ if (unlikely(in_interrupt())) {
100110+ struct stack_deferred *p = &__get_cpu_var(stack_deferred);
100111+ struct stack_deferred_llist *list = task->stack;
100112+ list->stack = task->stack;
100113+ list->lowmem_stack = task->lowmem_stack;
100114+ if (llist_add((struct llist_node *)&list->list, &p->list.list))
100115+ schedule_work(&p->wq);
100116+ } else {
100117+ __vunmap(task->stack, 0);
100118+ free_kmem_pages((unsigned long)task->lowmem_stack, THREAD_SIZE_ORDER);
100119+ }
100120+}
100121+#endif
100122+
100123 /**
100124 * vmap - map an array of pages into virtually contiguous space
100125 * @pages: array of page pointers
100126@@ -1539,6 +1645,11 @@ void *vmap(struct page **pages, unsigned int count,
100127 if (count > totalram_pages)
100128 return NULL;
100129
100130+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100131+ if (!(pgprot_val(prot) & _PAGE_NX))
100132+ flags |= VM_KERNEXEC;
100133+#endif
100134+
100135 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
100136 __builtin_return_address(0));
100137 if (!area)
100138@@ -1641,6 +1752,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
100139 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
100140 goto fail;
100141
100142+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100143+ if (!(pgprot_val(prot) & _PAGE_NX))
100144+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
100145+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
100146+ else
100147+#endif
100148+
100149 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
100150 start, end, node, gfp_mask, caller);
100151 if (!area)
100152@@ -1817,10 +1935,9 @@ EXPORT_SYMBOL(vzalloc_node);
100153 * For tight control over page level allocator and protection flags
100154 * use __vmalloc() instead.
100155 */
100156-
100157 void *vmalloc_exec(unsigned long size)
100158 {
100159- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
100160+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
100161 NUMA_NO_NODE, __builtin_return_address(0));
100162 }
100163
100164@@ -2127,6 +2244,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
100165 {
100166 struct vm_struct *area;
100167
100168+ BUG_ON(vma->vm_mirror);
100169+
100170 size = PAGE_ALIGN(size);
100171
100172 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
100173@@ -2609,7 +2728,11 @@ static int s_show(struct seq_file *m, void *p)
100174 v->addr, v->addr + v->size, v->size);
100175
100176 if (v->caller)
100177+#ifdef CONFIG_GRKERNSEC_HIDESYM
100178+ seq_printf(m, " %pK", v->caller);
100179+#else
100180 seq_printf(m, " %pS", v->caller);
100181+#endif
100182
100183 if (v->nr_pages)
100184 seq_printf(m, " pages=%d", v->nr_pages);
100185diff --git a/mm/vmstat.c b/mm/vmstat.c
100186index 1b12d39..57b29b2 100644
100187--- a/mm/vmstat.c
100188+++ b/mm/vmstat.c
100189@@ -22,6 +22,7 @@
100190 #include <linux/writeback.h>
100191 #include <linux/compaction.h>
100192 #include <linux/mm_inline.h>
100193+#include <linux/grsecurity.h>
100194
100195 #include "internal.h"
100196
100197@@ -81,7 +82,7 @@ void vm_events_fold_cpu(int cpu)
100198 *
100199 * vm_stat contains the global counters
100200 */
100201-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
100202+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
100203 EXPORT_SYMBOL(vm_stat);
100204
100205 #ifdef CONFIG_SMP
100206@@ -433,7 +434,7 @@ static int fold_diff(int *diff)
100207
100208 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
100209 if (diff[i]) {
100210- atomic_long_add(diff[i], &vm_stat[i]);
100211+ atomic_long_add_unchecked(diff[i], &vm_stat[i]);
100212 changes++;
100213 }
100214 return changes;
100215@@ -471,7 +472,7 @@ static int refresh_cpu_vm_stats(void)
100216 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
100217 if (v) {
100218
100219- atomic_long_add(v, &zone->vm_stat[i]);
100220+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100221 global_diff[i] += v;
100222 #ifdef CONFIG_NUMA
100223 /* 3 seconds idle till flush */
100224@@ -535,7 +536,7 @@ void cpu_vm_stats_fold(int cpu)
100225
100226 v = p->vm_stat_diff[i];
100227 p->vm_stat_diff[i] = 0;
100228- atomic_long_add(v, &zone->vm_stat[i]);
100229+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100230 global_diff[i] += v;
100231 }
100232 }
100233@@ -555,8 +556,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
100234 if (pset->vm_stat_diff[i]) {
100235 int v = pset->vm_stat_diff[i];
100236 pset->vm_stat_diff[i] = 0;
100237- atomic_long_add(v, &zone->vm_stat[i]);
100238- atomic_long_add(v, &vm_stat[i]);
100239+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100240+ atomic_long_add_unchecked(v, &vm_stat[i]);
100241 }
100242 }
100243 #endif
100244@@ -1189,10 +1190,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
100245 stat_items_size += sizeof(struct vm_event_state);
100246 #endif
100247
100248- v = kmalloc(stat_items_size, GFP_KERNEL);
100249+ v = kzalloc(stat_items_size, GFP_KERNEL);
100250 m->private = v;
100251 if (!v)
100252 return ERR_PTR(-ENOMEM);
100253+
100254+#ifdef CONFIG_GRKERNSEC_PROC_ADD
100255+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
100256+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
100257+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
100258+ && !in_group_p(grsec_proc_gid)
100259+#endif
100260+ )
100261+ return (unsigned long *)m->private + *pos;
100262+#endif
100263+#endif
100264+
100265 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
100266 v[i] = global_page_state(i);
100267 v += NR_VM_ZONE_STAT_ITEMS;
100268@@ -1424,10 +1437,16 @@ static int __init setup_vmstat(void)
100269 cpu_notifier_register_done();
100270 #endif
100271 #ifdef CONFIG_PROC_FS
100272- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
100273- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
100274- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
100275- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
100276+ {
100277+ mode_t gr_mode = S_IRUGO;
100278+#ifdef CONFIG_GRKERNSEC_PROC_ADD
100279+ gr_mode = S_IRUSR;
100280+#endif
100281+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
100282+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
100283+ proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
100284+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
100285+ }
100286 #endif
100287 return 0;
100288 }
100289diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
100290index 64c6bed..b79a5de 100644
100291--- a/net/8021q/vlan.c
100292+++ b/net/8021q/vlan.c
100293@@ -481,7 +481,7 @@ out:
100294 return NOTIFY_DONE;
100295 }
100296
100297-static struct notifier_block vlan_notifier_block __read_mostly = {
100298+static struct notifier_block vlan_notifier_block = {
100299 .notifier_call = vlan_device_event,
100300 };
100301
100302@@ -556,8 +556,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
100303 err = -EPERM;
100304 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
100305 break;
100306- if ((args.u.name_type >= 0) &&
100307- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
100308+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
100309 struct vlan_net *vn;
100310
100311 vn = net_generic(net, vlan_net_id);
100312diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c
100313index 8ac8a5c..991defc 100644
100314--- a/net/8021q/vlan_netlink.c
100315+++ b/net/8021q/vlan_netlink.c
100316@@ -238,7 +238,7 @@ nla_put_failure:
100317 return -EMSGSIZE;
100318 }
100319
100320-struct rtnl_link_ops vlan_link_ops __read_mostly = {
100321+struct rtnl_link_ops vlan_link_ops = {
100322 .kind = "vlan",
100323 .maxtype = IFLA_VLAN_MAX,
100324 .policy = vlan_policy,
100325diff --git a/net/9p/client.c b/net/9p/client.c
100326index e86a9bea..e91f70e 100644
100327--- a/net/9p/client.c
100328+++ b/net/9p/client.c
100329@@ -596,7 +596,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
100330 len - inline_len);
100331 } else {
100332 err = copy_from_user(ename + inline_len,
100333- uidata, len - inline_len);
100334+ (char __force_user *)uidata, len - inline_len);
100335 if (err) {
100336 err = -EFAULT;
100337 goto out_err;
100338@@ -1570,7 +1570,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
100339 kernel_buf = 1;
100340 indata = data;
100341 } else
100342- indata = (__force char *)udata;
100343+ indata = (__force_kernel char *)udata;
100344 /*
100345 * response header len is 11
100346 * PDU Header(7) + IO Size (4)
100347@@ -1645,7 +1645,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
100348 kernel_buf = 1;
100349 odata = data;
100350 } else
100351- odata = (char *)udata;
100352+ odata = (char __force_kernel *)udata;
100353 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
100354 P9_ZC_HDR_SZ, kernel_buf, "dqd",
100355 fid->fid, offset, rsize);
100356diff --git a/net/9p/mod.c b/net/9p/mod.c
100357index 6ab36ae..6f1841b 100644
100358--- a/net/9p/mod.c
100359+++ b/net/9p/mod.c
100360@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
100361 void v9fs_register_trans(struct p9_trans_module *m)
100362 {
100363 spin_lock(&v9fs_trans_lock);
100364- list_add_tail(&m->list, &v9fs_trans_list);
100365+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
100366 spin_unlock(&v9fs_trans_lock);
100367 }
100368 EXPORT_SYMBOL(v9fs_register_trans);
100369@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
100370 void v9fs_unregister_trans(struct p9_trans_module *m)
100371 {
100372 spin_lock(&v9fs_trans_lock);
100373- list_del_init(&m->list);
100374+ pax_list_del_init((struct list_head *)&m->list);
100375 spin_unlock(&v9fs_trans_lock);
100376 }
100377 EXPORT_SYMBOL(v9fs_unregister_trans);
100378diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
100379index 80d08f6..de63fd1 100644
100380--- a/net/9p/trans_fd.c
100381+++ b/net/9p/trans_fd.c
100382@@ -428,7 +428,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
100383 oldfs = get_fs();
100384 set_fs(get_ds());
100385 /* The cast to a user pointer is valid due to the set_fs() */
100386- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
100387+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
100388 set_fs(oldfs);
100389
100390 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
100391diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
100392index af46bc4..f9adfcd 100644
100393--- a/net/appletalk/atalk_proc.c
100394+++ b/net/appletalk/atalk_proc.c
100395@@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
100396 struct proc_dir_entry *p;
100397 int rc = -ENOMEM;
100398
100399- atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
100400+ atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
100401 if (!atalk_proc_dir)
100402 goto out;
100403
100404diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
100405index 876fbe8..8bbea9f 100644
100406--- a/net/atm/atm_misc.c
100407+++ b/net/atm/atm_misc.c
100408@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
100409 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
100410 return 1;
100411 atm_return(vcc, truesize);
100412- atomic_inc(&vcc->stats->rx_drop);
100413+ atomic_inc_unchecked(&vcc->stats->rx_drop);
100414 return 0;
100415 }
100416 EXPORT_SYMBOL(atm_charge);
100417@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
100418 }
100419 }
100420 atm_return(vcc, guess);
100421- atomic_inc(&vcc->stats->rx_drop);
100422+ atomic_inc_unchecked(&vcc->stats->rx_drop);
100423 return NULL;
100424 }
100425 EXPORT_SYMBOL(atm_alloc_charge);
100426@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
100427
100428 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
100429 {
100430-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
100431+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
100432 __SONET_ITEMS
100433 #undef __HANDLE_ITEM
100434 }
100435@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
100436
100437 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
100438 {
100439-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
100440+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
100441 __SONET_ITEMS
100442 #undef __HANDLE_ITEM
100443 }
100444diff --git a/net/atm/lec.c b/net/atm/lec.c
100445index 4b98f89..5a2f6cb 100644
100446--- a/net/atm/lec.c
100447+++ b/net/atm/lec.c
100448@@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
100449 }
100450
100451 static struct lane2_ops lane2_ops = {
100452- lane2_resolve, /* resolve, spec 3.1.3 */
100453- lane2_associate_req, /* associate_req, spec 3.1.4 */
100454- NULL /* associate indicator, spec 3.1.5 */
100455+ .resolve = lane2_resolve,
100456+ .associate_req = lane2_associate_req,
100457+ .associate_indicator = NULL
100458 };
100459
100460 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
100461diff --git a/net/atm/lec.h b/net/atm/lec.h
100462index 4149db1..f2ab682 100644
100463--- a/net/atm/lec.h
100464+++ b/net/atm/lec.h
100465@@ -48,7 +48,7 @@ struct lane2_ops {
100466 const u8 *tlvs, u32 sizeoftlvs);
100467 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
100468 const u8 *tlvs, u32 sizeoftlvs);
100469-};
100470+} __no_const;
100471
100472 /*
100473 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
100474diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
100475index d1b2d9a..d549f7f 100644
100476--- a/net/atm/mpoa_caches.c
100477+++ b/net/atm/mpoa_caches.c
100478@@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
100479
100480
100481 static struct in_cache_ops ingress_ops = {
100482- in_cache_add_entry, /* add_entry */
100483- in_cache_get, /* get */
100484- in_cache_get_with_mask, /* get_with_mask */
100485- in_cache_get_by_vcc, /* get_by_vcc */
100486- in_cache_put, /* put */
100487- in_cache_remove_entry, /* remove_entry */
100488- cache_hit, /* cache_hit */
100489- clear_count_and_expired, /* clear_count */
100490- check_resolving_entries, /* check_resolving */
100491- refresh_entries, /* refresh */
100492- in_destroy_cache /* destroy_cache */
100493+ .add_entry = in_cache_add_entry,
100494+ .get = in_cache_get,
100495+ .get_with_mask = in_cache_get_with_mask,
100496+ .get_by_vcc = in_cache_get_by_vcc,
100497+ .put = in_cache_put,
100498+ .remove_entry = in_cache_remove_entry,
100499+ .cache_hit = cache_hit,
100500+ .clear_count = clear_count_and_expired,
100501+ .check_resolving = check_resolving_entries,
100502+ .refresh = refresh_entries,
100503+ .destroy_cache = in_destroy_cache
100504 };
100505
100506 static struct eg_cache_ops egress_ops = {
100507- eg_cache_add_entry, /* add_entry */
100508- eg_cache_get_by_cache_id, /* get_by_cache_id */
100509- eg_cache_get_by_tag, /* get_by_tag */
100510- eg_cache_get_by_vcc, /* get_by_vcc */
100511- eg_cache_get_by_src_ip, /* get_by_src_ip */
100512- eg_cache_put, /* put */
100513- eg_cache_remove_entry, /* remove_entry */
100514- update_eg_cache_entry, /* update */
100515- clear_expired, /* clear_expired */
100516- eg_destroy_cache /* destroy_cache */
100517+ .add_entry = eg_cache_add_entry,
100518+ .get_by_cache_id = eg_cache_get_by_cache_id,
100519+ .get_by_tag = eg_cache_get_by_tag,
100520+ .get_by_vcc = eg_cache_get_by_vcc,
100521+ .get_by_src_ip = eg_cache_get_by_src_ip,
100522+ .put = eg_cache_put,
100523+ .remove_entry = eg_cache_remove_entry,
100524+ .update = update_eg_cache_entry,
100525+ .clear_expired = clear_expired,
100526+ .destroy_cache = eg_destroy_cache
100527 };
100528
100529
100530diff --git a/net/atm/proc.c b/net/atm/proc.c
100531index bbb6461..cf04016 100644
100532--- a/net/atm/proc.c
100533+++ b/net/atm/proc.c
100534@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
100535 const struct k_atm_aal_stats *stats)
100536 {
100537 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
100538- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
100539- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
100540- atomic_read(&stats->rx_drop));
100541+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
100542+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
100543+ atomic_read_unchecked(&stats->rx_drop));
100544 }
100545
100546 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
100547diff --git a/net/atm/resources.c b/net/atm/resources.c
100548index 0447d5d..3cf4728 100644
100549--- a/net/atm/resources.c
100550+++ b/net/atm/resources.c
100551@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
100552 static void copy_aal_stats(struct k_atm_aal_stats *from,
100553 struct atm_aal_stats *to)
100554 {
100555-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
100556+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
100557 __AAL_STAT_ITEMS
100558 #undef __HANDLE_ITEM
100559 }
100560@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
100561 static void subtract_aal_stats(struct k_atm_aal_stats *from,
100562 struct atm_aal_stats *to)
100563 {
100564-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
100565+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
100566 __AAL_STAT_ITEMS
100567 #undef __HANDLE_ITEM
100568 }
100569diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
100570index 919a5ce..cc6b444 100644
100571--- a/net/ax25/sysctl_net_ax25.c
100572+++ b/net/ax25/sysctl_net_ax25.c
100573@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
100574 {
100575 char path[sizeof("net/ax25/") + IFNAMSIZ];
100576 int k;
100577- struct ctl_table *table;
100578+ ctl_table_no_const *table;
100579
100580 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
100581 if (!table)
100582diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
100583index 1e80539..676c37a 100644
100584--- a/net/batman-adv/bat_iv_ogm.c
100585+++ b/net/batman-adv/bat_iv_ogm.c
100586@@ -313,7 +313,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
100587
100588 /* randomize initial seqno to avoid collision */
100589 get_random_bytes(&random_seqno, sizeof(random_seqno));
100590- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
100591+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
100592
100593 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
100594 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
100595@@ -918,9 +918,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
100596 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
100597
100598 /* change sequence number to network order */
100599- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
100600+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
100601 batadv_ogm_packet->seqno = htonl(seqno);
100602- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
100603+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
100604
100605 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
100606
100607@@ -1597,7 +1597,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
100608 return;
100609
100610 /* could be changed by schedule_own_packet() */
100611- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
100612+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
100613
100614 if (ogm_packet->flags & BATADV_DIRECTLINK)
100615 has_directlink_flag = true;
100616diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
100617index fc1835c..42f2c2f 100644
100618--- a/net/batman-adv/fragmentation.c
100619+++ b/net/batman-adv/fragmentation.c
100620@@ -251,7 +251,7 @@ batadv_frag_merge_packets(struct hlist_head *chain, struct sk_buff *skb)
100621 kfree(entry);
100622
100623 /* Make room for the rest of the fragments. */
100624- if (pskb_expand_head(skb_out, 0, size - skb->len, GFP_ATOMIC) < 0) {
100625+ if (pskb_expand_head(skb_out, 0, size - skb_out->len, GFP_ATOMIC) < 0) {
100626 kfree_skb(skb_out);
100627 skb_out = NULL;
100628 goto free;
100629@@ -450,7 +450,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
100630 frag_header.packet_type = BATADV_UNICAST_FRAG;
100631 frag_header.version = BATADV_COMPAT_VERSION;
100632 frag_header.ttl = BATADV_TTL;
100633- frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
100634+ frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
100635 frag_header.reserved = 0;
100636 frag_header.no = 0;
100637 frag_header.total_size = htons(skb->len);
100638diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
100639index 5467955..75ad4e3 100644
100640--- a/net/batman-adv/soft-interface.c
100641+++ b/net/batman-adv/soft-interface.c
100642@@ -296,7 +296,7 @@ send:
100643 primary_if->net_dev->dev_addr);
100644
100645 /* set broadcast sequence number */
100646- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
100647+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
100648 bcast_packet->seqno = htonl(seqno);
100649
100650 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
100651@@ -761,7 +761,7 @@ static int batadv_softif_init_late(struct net_device *dev)
100652 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
100653
100654 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
100655- atomic_set(&bat_priv->bcast_seqno, 1);
100656+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
100657 atomic_set(&bat_priv->tt.vn, 0);
100658 atomic_set(&bat_priv->tt.local_changes, 0);
100659 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
100660@@ -775,7 +775,7 @@ static int batadv_softif_init_late(struct net_device *dev)
100661
100662 /* randomize initial seqno to avoid collision */
100663 get_random_bytes(&random_seqno, sizeof(random_seqno));
100664- atomic_set(&bat_priv->frag_seqno, random_seqno);
100665+ atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
100666
100667 bat_priv->primary_if = NULL;
100668 bat_priv->num_ifaces = 0;
100669@@ -983,7 +983,7 @@ int batadv_softif_is_valid(const struct net_device *net_dev)
100670 return 0;
100671 }
100672
100673-struct rtnl_link_ops batadv_link_ops __read_mostly = {
100674+struct rtnl_link_ops batadv_link_ops = {
100675 .kind = "batadv",
100676 .priv_size = sizeof(struct batadv_priv),
100677 .setup = batadv_softif_init_early,
100678diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
100679index 8854c05..ee5d5497 100644
100680--- a/net/batman-adv/types.h
100681+++ b/net/batman-adv/types.h
100682@@ -67,7 +67,7 @@ enum batadv_dhcp_recipient {
100683 struct batadv_hard_iface_bat_iv {
100684 unsigned char *ogm_buff;
100685 int ogm_buff_len;
100686- atomic_t ogm_seqno;
100687+ atomic_unchecked_t ogm_seqno;
100688 };
100689
100690 /**
100691@@ -768,7 +768,7 @@ struct batadv_priv {
100692 atomic_t bonding;
100693 atomic_t fragmentation;
100694 atomic_t packet_size_max;
100695- atomic_t frag_seqno;
100696+ atomic_unchecked_t frag_seqno;
100697 #ifdef CONFIG_BATMAN_ADV_BLA
100698 atomic_t bridge_loop_avoidance;
100699 #endif
100700@@ -787,7 +787,7 @@ struct batadv_priv {
100701 #endif
100702 uint32_t isolation_mark;
100703 uint32_t isolation_mark_mask;
100704- atomic_t bcast_seqno;
100705+ atomic_unchecked_t bcast_seqno;
100706 atomic_t bcast_queue_left;
100707 atomic_t batman_queue_left;
100708 char num_ifaces;
100709diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c
100710index c2e0d14..bfa852b 100644
100711--- a/net/bluetooth/6lowpan.c
100712+++ b/net/bluetooth/6lowpan.c
100713@@ -367,7 +367,6 @@ static int recv_pkt(struct sk_buff *skb, struct net_device *dev,
100714
100715 drop:
100716 dev->stats.rx_dropped++;
100717- kfree_skb(skb);
100718 return NET_RX_DROP;
100719 }
100720
100721diff --git a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c
100722index 85bcc21..ce82722d 100644
100723--- a/net/bluetooth/bnep/core.c
100724+++ b/net/bluetooth/bnep/core.c
100725@@ -533,6 +533,9 @@ int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock)
100726
100727 BT_DBG("");
100728
100729+ if (!l2cap_is_socket(sock))
100730+ return -EBADFD;
100731+
100732 baswap((void *) dst, &l2cap_pi(sock->sk)->chan->dst);
100733 baswap((void *) src, &l2cap_pi(sock->sk)->chan->src);
100734
100735diff --git a/net/bluetooth/cmtp/core.c b/net/bluetooth/cmtp/core.c
100736index 67fe5e8..278a194 100644
100737--- a/net/bluetooth/cmtp/core.c
100738+++ b/net/bluetooth/cmtp/core.c
100739@@ -334,6 +334,9 @@ int cmtp_add_connection(struct cmtp_connadd_req *req, struct socket *sock)
100740
100741 BT_DBG("");
100742
100743+ if (!l2cap_is_socket(sock))
100744+ return -EBADFD;
100745+
100746 session = kzalloc(sizeof(struct cmtp_session), GFP_KERNEL);
100747 if (!session)
100748 return -ENOMEM;
100749diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
100750index 115f149..f0ba286 100644
100751--- a/net/bluetooth/hci_sock.c
100752+++ b/net/bluetooth/hci_sock.c
100753@@ -1067,7 +1067,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
100754 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
100755 }
100756
100757- len = min_t(unsigned int, len, sizeof(uf));
100758+ len = min((size_t)len, sizeof(uf));
100759 if (copy_from_user(&uf, optval, len)) {
100760 err = -EFAULT;
100761 break;
100762diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c
100763index 1b7d605..02ebd10 100644
100764--- a/net/bluetooth/hidp/core.c
100765+++ b/net/bluetooth/hidp/core.c
100766@@ -1318,13 +1318,14 @@ int hidp_connection_add(struct hidp_connadd_req *req,
100767 {
100768 struct hidp_session *session;
100769 struct l2cap_conn *conn;
100770- struct l2cap_chan *chan = l2cap_pi(ctrl_sock->sk)->chan;
100771+ struct l2cap_chan *chan;
100772 int ret;
100773
100774 ret = hidp_verify_sockets(ctrl_sock, intr_sock);
100775 if (ret)
100776 return ret;
100777
100778+ chan = l2cap_pi(ctrl_sock->sk)->chan;
100779 conn = NULL;
100780 l2cap_chan_lock(chan);
100781 if (chan->conn)
100782diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
100783index b6f9777..36d3039 100644
100784--- a/net/bluetooth/l2cap_core.c
100785+++ b/net/bluetooth/l2cap_core.c
100786@@ -3512,8 +3512,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
100787 break;
100788
100789 case L2CAP_CONF_RFC:
100790- if (olen == sizeof(rfc))
100791- memcpy(&rfc, (void *)val, olen);
100792+ if (olen != sizeof(rfc))
100793+ break;
100794+
100795+ memcpy(&rfc, (void *)val, olen);
100796
100797 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
100798 rfc.mode != chan->mode)
100799diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
100800index 31f106e..323f606 100644
100801--- a/net/bluetooth/l2cap_sock.c
100802+++ b/net/bluetooth/l2cap_sock.c
100803@@ -628,7 +628,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
100804 struct sock *sk = sock->sk;
100805 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
100806 struct l2cap_options opts;
100807- int len, err = 0;
100808+ int err = 0;
100809+ size_t len = optlen;
100810 u32 opt;
100811
100812 BT_DBG("sk %p", sk);
100813@@ -655,7 +656,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
100814 opts.max_tx = chan->max_tx;
100815 opts.txwin_size = chan->tx_win;
100816
100817- len = min_t(unsigned int, sizeof(opts), optlen);
100818+ len = min(sizeof(opts), len);
100819 if (copy_from_user((char *) &opts, optval, len)) {
100820 err = -EFAULT;
100821 break;
100822@@ -742,7 +743,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
100823 struct bt_security sec;
100824 struct bt_power pwr;
100825 struct l2cap_conn *conn;
100826- int len, err = 0;
100827+ int err = 0;
100828+ size_t len = optlen;
100829 u32 opt;
100830
100831 BT_DBG("sk %p", sk);
100832@@ -766,7 +768,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
100833
100834 sec.level = BT_SECURITY_LOW;
100835
100836- len = min_t(unsigned int, sizeof(sec), optlen);
100837+ len = min(sizeof(sec), len);
100838 if (copy_from_user((char *) &sec, optval, len)) {
100839 err = -EFAULT;
100840 break;
100841@@ -862,7 +864,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
100842
100843 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
100844
100845- len = min_t(unsigned int, sizeof(pwr), optlen);
100846+ len = min(sizeof(pwr), len);
100847 if (copy_from_user((char *) &pwr, optval, len)) {
100848 err = -EFAULT;
100849 break;
100850diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
100851index 8bbbb5e..6fc0950 100644
100852--- a/net/bluetooth/rfcomm/sock.c
100853+++ b/net/bluetooth/rfcomm/sock.c
100854@@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
100855 struct sock *sk = sock->sk;
100856 struct bt_security sec;
100857 int err = 0;
100858- size_t len;
100859+ size_t len = optlen;
100860 u32 opt;
100861
100862 BT_DBG("sk %p", sk);
100863@@ -709,7 +709,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
100864
100865 sec.level = BT_SECURITY_LOW;
100866
100867- len = min_t(unsigned int, sizeof(sec), optlen);
100868+ len = min(sizeof(sec), len);
100869 if (copy_from_user((char *) &sec, optval, len)) {
100870 err = -EFAULT;
100871 break;
100872diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
100873index 8e385a0..a5bdd8e 100644
100874--- a/net/bluetooth/rfcomm/tty.c
100875+++ b/net/bluetooth/rfcomm/tty.c
100876@@ -752,7 +752,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
100877 BT_DBG("tty %p id %d", tty, tty->index);
100878
100879 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
100880- dev->channel, dev->port.count);
100881+ dev->channel, atomic_read(&dev->port.count));
100882
100883 err = tty_port_open(&dev->port, tty, filp);
100884 if (err)
100885@@ -775,7 +775,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
100886 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
100887
100888 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
100889- dev->port.count);
100890+ atomic_read(&dev->port.count));
100891
100892 tty_port_close(&dev->port, tty, filp);
100893 }
100894diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c
100895index e5ec470..cbfabd1 100644
100896--- a/net/bridge/br_netlink.c
100897+++ b/net/bridge/br_netlink.c
100898@@ -564,7 +564,7 @@ static struct rtnl_af_ops br_af_ops = {
100899 .get_link_af_size = br_get_link_af_size,
100900 };
100901
100902-struct rtnl_link_ops br_link_ops __read_mostly = {
100903+struct rtnl_link_ops br_link_ops = {
100904 .kind = "bridge",
100905 .priv_size = sizeof(struct net_bridge),
100906 .setup = br_dev_setup,
100907diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
100908index d9a8c05..8dadc6c6 100644
100909--- a/net/bridge/netfilter/ebtables.c
100910+++ b/net/bridge/netfilter/ebtables.c
100911@@ -1533,7 +1533,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100912 tmp.valid_hooks = t->table->valid_hooks;
100913 }
100914 mutex_unlock(&ebt_mutex);
100915- if (copy_to_user(user, &tmp, *len) != 0) {
100916+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
100917 BUGPRINT("c2u Didn't work\n");
100918 ret = -EFAULT;
100919 break;
100920@@ -2339,7 +2339,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
100921 goto out;
100922 tmp.valid_hooks = t->valid_hooks;
100923
100924- if (copy_to_user(user, &tmp, *len) != 0) {
100925+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
100926 ret = -EFAULT;
100927 break;
100928 }
100929@@ -2350,7 +2350,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
100930 tmp.entries_size = t->table->entries_size;
100931 tmp.valid_hooks = t->table->valid_hooks;
100932
100933- if (copy_to_user(user, &tmp, *len) != 0) {
100934+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
100935 ret = -EFAULT;
100936 break;
100937 }
100938diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
100939index f5afda1..dcf770a 100644
100940--- a/net/caif/cfctrl.c
100941+++ b/net/caif/cfctrl.c
100942@@ -10,6 +10,7 @@
100943 #include <linux/spinlock.h>
100944 #include <linux/slab.h>
100945 #include <linux/pkt_sched.h>
100946+#include <linux/sched.h>
100947 #include <net/caif/caif_layer.h>
100948 #include <net/caif/cfpkt.h>
100949 #include <net/caif/cfctrl.h>
100950@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
100951 memset(&dev_info, 0, sizeof(dev_info));
100952 dev_info.id = 0xff;
100953 cfsrvl_init(&this->serv, 0, &dev_info, false);
100954- atomic_set(&this->req_seq_no, 1);
100955- atomic_set(&this->rsp_seq_no, 1);
100956+ atomic_set_unchecked(&this->req_seq_no, 1);
100957+ atomic_set_unchecked(&this->rsp_seq_no, 1);
100958 this->serv.layer.receive = cfctrl_recv;
100959 sprintf(this->serv.layer.name, "ctrl");
100960 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
100961@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
100962 struct cfctrl_request_info *req)
100963 {
100964 spin_lock_bh(&ctrl->info_list_lock);
100965- atomic_inc(&ctrl->req_seq_no);
100966- req->sequence_no = atomic_read(&ctrl->req_seq_no);
100967+ atomic_inc_unchecked(&ctrl->req_seq_no);
100968+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
100969 list_add_tail(&req->list, &ctrl->list);
100970 spin_unlock_bh(&ctrl->info_list_lock);
100971 }
100972@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
100973 if (p != first)
100974 pr_warn("Requests are not received in order\n");
100975
100976- atomic_set(&ctrl->rsp_seq_no,
100977+ atomic_set_unchecked(&ctrl->rsp_seq_no,
100978 p->sequence_no);
100979 list_del(&p->list);
100980 goto out;
100981diff --git a/net/caif/chnl_net.c b/net/caif/chnl_net.c
100982index 4589ff67..46d6b8f 100644
100983--- a/net/caif/chnl_net.c
100984+++ b/net/caif/chnl_net.c
100985@@ -516,7 +516,7 @@ static const struct nla_policy ipcaif_policy[IFLA_CAIF_MAX + 1] = {
100986 };
100987
100988
100989-static struct rtnl_link_ops ipcaif_link_ops __read_mostly = {
100990+static struct rtnl_link_ops ipcaif_link_ops = {
100991 .kind = "caif",
100992 .priv_size = sizeof(struct chnl_net),
100993 .setup = ipcaif_net_setup,
100994diff --git a/net/can/af_can.c b/net/can/af_can.c
100995index ce82337..5d17b4d 100644
100996--- a/net/can/af_can.c
100997+++ b/net/can/af_can.c
100998@@ -884,7 +884,7 @@ static const struct net_proto_family can_family_ops = {
100999 };
101000
101001 /* notifier block for netdevice event */
101002-static struct notifier_block can_netdev_notifier __read_mostly = {
101003+static struct notifier_block can_netdev_notifier = {
101004 .notifier_call = can_notifier,
101005 };
101006
101007diff --git a/net/can/bcm.c b/net/can/bcm.c
101008index dcb75c0..24b1b43 100644
101009--- a/net/can/bcm.c
101010+++ b/net/can/bcm.c
101011@@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
101012 }
101013
101014 /* create /proc/net/can-bcm directory */
101015- proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
101016+ proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
101017 return 0;
101018 }
101019
101020diff --git a/net/can/gw.c b/net/can/gw.c
101021index 050a211..bb9fe33 100644
101022--- a/net/can/gw.c
101023+++ b/net/can/gw.c
101024@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
101025 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
101026
101027 static HLIST_HEAD(cgw_list);
101028-static struct notifier_block notifier;
101029
101030 static struct kmem_cache *cgw_cache __read_mostly;
101031
101032@@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
101033 return err;
101034 }
101035
101036+static struct notifier_block notifier = {
101037+ .notifier_call = cgw_notifier
101038+};
101039+
101040 static __init int cgw_module_init(void)
101041 {
101042 /* sanitize given module parameter */
101043@@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
101044 return -ENOMEM;
101045
101046 /* set notifier */
101047- notifier.notifier_call = cgw_notifier;
101048 register_netdevice_notifier(&notifier);
101049
101050 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
101051diff --git a/net/can/proc.c b/net/can/proc.c
101052index 1a19b98..df2b4ec 100644
101053--- a/net/can/proc.c
101054+++ b/net/can/proc.c
101055@@ -514,7 +514,7 @@ static void can_remove_proc_readentry(const char *name)
101056 void can_init_proc(void)
101057 {
101058 /* create /proc/net/can directory */
101059- can_dir = proc_mkdir("can", init_net.proc_net);
101060+ can_dir = proc_mkdir_restrict("can", init_net.proc_net);
101061
101062 if (!can_dir) {
101063 printk(KERN_INFO "can: failed to create /proc/net/can . "
101064diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
101065index 8d1653c..77ad145 100644
101066--- a/net/ceph/messenger.c
101067+++ b/net/ceph/messenger.c
101068@@ -188,7 +188,7 @@ static void con_fault(struct ceph_connection *con);
101069 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
101070
101071 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
101072-static atomic_t addr_str_seq = ATOMIC_INIT(0);
101073+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
101074
101075 static struct page *zero_page; /* used in certain error cases */
101076
101077@@ -199,7 +199,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
101078 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
101079 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
101080
101081- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
101082+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
101083 s = addr_str[i];
101084
101085 switch (ss->ss_family) {
101086diff --git a/net/compat.c b/net/compat.c
101087index bc8aeef..f9c070c 100644
101088--- a/net/compat.c
101089+++ b/net/compat.c
101090@@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
101091 return -EFAULT;
101092 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
101093 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
101094- kmsg->msg_name = compat_ptr(tmp1);
101095- kmsg->msg_iov = compat_ptr(tmp2);
101096- kmsg->msg_control = compat_ptr(tmp3);
101097+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
101098+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
101099+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
101100 return 0;
101101 }
101102
101103@@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101104
101105 if (kern_msg->msg_name && kern_msg->msg_namelen) {
101106 if (mode == VERIFY_READ) {
101107- int err = move_addr_to_kernel(kern_msg->msg_name,
101108+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
101109 kern_msg->msg_namelen,
101110 kern_address);
101111 if (err < 0)
101112@@ -100,7 +100,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101113 }
101114
101115 tot_len = iov_from_user_compat_to_kern(kern_iov,
101116- (struct compat_iovec __user *)kern_msg->msg_iov,
101117+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
101118 kern_msg->msg_iovlen);
101119 if (tot_len >= 0)
101120 kern_msg->msg_iov = kern_iov;
101121@@ -120,20 +120,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101122
101123 #define CMSG_COMPAT_FIRSTHDR(msg) \
101124 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
101125- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
101126+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
101127 (struct compat_cmsghdr __user *)NULL)
101128
101129 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
101130 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
101131 (ucmlen) <= (unsigned long) \
101132 ((mhdr)->msg_controllen - \
101133- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
101134+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
101135
101136 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
101137 struct compat_cmsghdr __user *cmsg, int cmsg_len)
101138 {
101139 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
101140- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
101141+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
101142 msg->msg_controllen)
101143 return NULL;
101144 return (struct compat_cmsghdr __user *)ptr;
101145@@ -223,7 +223,7 @@ Efault:
101146
101147 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
101148 {
101149- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
101150+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
101151 struct compat_cmsghdr cmhdr;
101152 struct compat_timeval ctv;
101153 struct compat_timespec cts[3];
101154@@ -279,7 +279,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
101155
101156 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
101157 {
101158- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
101159+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
101160 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
101161 int fdnum = scm->fp->count;
101162 struct file **fp = scm->fp->fp;
101163@@ -367,7 +367,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
101164 return -EFAULT;
101165 old_fs = get_fs();
101166 set_fs(KERNEL_DS);
101167- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
101168+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
101169 set_fs(old_fs);
101170
101171 return err;
101172@@ -428,7 +428,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
101173 len = sizeof(ktime);
101174 old_fs = get_fs();
101175 set_fs(KERNEL_DS);
101176- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
101177+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
101178 set_fs(old_fs);
101179
101180 if (!err) {
101181@@ -571,7 +571,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101182 case MCAST_JOIN_GROUP:
101183 case MCAST_LEAVE_GROUP:
101184 {
101185- struct compat_group_req __user *gr32 = (void *)optval;
101186+ struct compat_group_req __user *gr32 = (void __user *)optval;
101187 struct group_req __user *kgr =
101188 compat_alloc_user_space(sizeof(struct group_req));
101189 u32 interface;
101190@@ -592,7 +592,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101191 case MCAST_BLOCK_SOURCE:
101192 case MCAST_UNBLOCK_SOURCE:
101193 {
101194- struct compat_group_source_req __user *gsr32 = (void *)optval;
101195+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
101196 struct group_source_req __user *kgsr = compat_alloc_user_space(
101197 sizeof(struct group_source_req));
101198 u32 interface;
101199@@ -613,7 +613,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101200 }
101201 case MCAST_MSFILTER:
101202 {
101203- struct compat_group_filter __user *gf32 = (void *)optval;
101204+ struct compat_group_filter __user *gf32 = (void __user *)optval;
101205 struct group_filter __user *kgf;
101206 u32 interface, fmode, numsrc;
101207
101208@@ -651,7 +651,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
101209 char __user *optval, int __user *optlen,
101210 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
101211 {
101212- struct compat_group_filter __user *gf32 = (void *)optval;
101213+ struct compat_group_filter __user *gf32 = (void __user *)optval;
101214 struct group_filter __user *kgf;
101215 int __user *koptlen;
101216 u32 interface, fmode, numsrc;
101217@@ -804,7 +804,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
101218
101219 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
101220 return -EINVAL;
101221- if (copy_from_user(a, args, nas[call]))
101222+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
101223 return -EFAULT;
101224 a0 = a[0];
101225 a1 = a[1];
101226diff --git a/net/core/datagram.c b/net/core/datagram.c
101227index fdbc9a8..cd6972c 100644
101228--- a/net/core/datagram.c
101229+++ b/net/core/datagram.c
101230@@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
101231 }
101232
101233 kfree_skb(skb);
101234- atomic_inc(&sk->sk_drops);
101235+ atomic_inc_unchecked(&sk->sk_drops);
101236 sk_mem_reclaim_partial(sk);
101237
101238 return err;
101239diff --git a/net/core/dev.c b/net/core/dev.c
101240index 945bbd0..8b1a370 100644
101241--- a/net/core/dev.c
101242+++ b/net/core/dev.c
101243@@ -1683,14 +1683,14 @@ int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
101244 {
101245 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
101246 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
101247- atomic_long_inc(&dev->rx_dropped);
101248+ atomic_long_inc_unchecked(&dev->rx_dropped);
101249 kfree_skb(skb);
101250 return NET_RX_DROP;
101251 }
101252 }
101253
101254 if (unlikely(!is_skb_forwardable(dev, skb))) {
101255- atomic_long_inc(&dev->rx_dropped);
101256+ atomic_long_inc_unchecked(&dev->rx_dropped);
101257 kfree_skb(skb);
101258 return NET_RX_DROP;
101259 }
101260@@ -2985,7 +2985,7 @@ recursion_alert:
101261 drop:
101262 rcu_read_unlock_bh();
101263
101264- atomic_long_inc(&dev->tx_dropped);
101265+ atomic_long_inc_unchecked(&dev->tx_dropped);
101266 kfree_skb_list(skb);
101267 return rc;
101268 out:
101269@@ -3328,7 +3328,7 @@ enqueue:
101270
101271 local_irq_restore(flags);
101272
101273- atomic_long_inc(&skb->dev->rx_dropped);
101274+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
101275 kfree_skb(skb);
101276 return NET_RX_DROP;
101277 }
101278@@ -3405,7 +3405,7 @@ int netif_rx_ni(struct sk_buff *skb)
101279 }
101280 EXPORT_SYMBOL(netif_rx_ni);
101281
101282-static void net_tx_action(struct softirq_action *h)
101283+static __latent_entropy void net_tx_action(void)
101284 {
101285 struct softnet_data *sd = this_cpu_ptr(&softnet_data);
101286
101287@@ -3738,7 +3738,7 @@ ncls:
101288 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
101289 } else {
101290 drop:
101291- atomic_long_inc(&skb->dev->rx_dropped);
101292+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
101293 kfree_skb(skb);
101294 /* Jamal, now you will not able to escape explaining
101295 * me how you were going to use this. :-)
101296@@ -4502,7 +4502,7 @@ void netif_napi_del(struct napi_struct *napi)
101297 }
101298 EXPORT_SYMBOL(netif_napi_del);
101299
101300-static void net_rx_action(struct softirq_action *h)
101301+static __latent_entropy void net_rx_action(void)
101302 {
101303 struct softnet_data *sd = this_cpu_ptr(&softnet_data);
101304 unsigned long time_limit = jiffies + 2;
101305@@ -6548,8 +6548,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
101306 } else {
101307 netdev_stats_to_stats64(storage, &dev->stats);
101308 }
101309- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
101310- storage->tx_dropped += atomic_long_read(&dev->tx_dropped);
101311+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
101312+ storage->tx_dropped += atomic_long_read_unchecked(&dev->tx_dropped);
101313 return storage;
101314 }
101315 EXPORT_SYMBOL(dev_get_stats);
101316diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
101317index 72e899a..79a9409 100644
101318--- a/net/core/dev_ioctl.c
101319+++ b/net/core/dev_ioctl.c
101320@@ -365,8 +365,13 @@ void dev_load(struct net *net, const char *name)
101321 no_module = !dev;
101322 if (no_module && capable(CAP_NET_ADMIN))
101323 no_module = request_module("netdev-%s", name);
101324- if (no_module && capable(CAP_SYS_MODULE))
101325+ if (no_module && capable(CAP_SYS_MODULE)) {
101326+#ifdef CONFIG_GRKERNSEC_MODHARDEN
101327+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
101328+#else
101329 request_module("%s", name);
101330+#endif
101331+ }
101332 }
101333 EXPORT_SYMBOL(dev_load);
101334
101335diff --git a/net/core/filter.c b/net/core/filter.c
101336index 647b122..18a7ff6 100644
101337--- a/net/core/filter.c
101338+++ b/net/core/filter.c
101339@@ -532,7 +532,11 @@ do_pass:
101340
101341 /* Unkown instruction. */
101342 default:
101343- goto err;
101344+ WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
101345+ fp->code, fp->jt, fp->jf, fp->k);
101346+ kfree(addrs);
101347+ BUG();
101348+ return -EINVAL;
101349 }
101350
101351 insn++;
101352@@ -576,7 +580,7 @@ static int check_load_and_stores(const struct sock_filter *filter, int flen)
101353 u16 *masks, memvalid = 0; /* One bit per cell, 16 cells */
101354 int pc, ret = 0;
101355
101356- BUILD_BUG_ON(BPF_MEMWORDS > 16);
101357+ BUILD_BUG_ON(BPF_MEMWORDS != 16);
101358
101359 masks = kmalloc_array(flen, sizeof(*masks), GFP_KERNEL);
101360 if (!masks)
101361@@ -987,7 +991,7 @@ int bpf_prog_create(struct bpf_prog **pfp, struct sock_fprog_kern *fprog)
101362 if (!fp)
101363 return -ENOMEM;
101364
101365- memcpy(fp->insns, fprog->filter, fsize);
101366+ memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
101367
101368 fp->len = fprog->len;
101369 /* Since unattached filters are not copied back to user
101370diff --git a/net/core/flow.c b/net/core/flow.c
101371index a0348fd..6951c76 100644
101372--- a/net/core/flow.c
101373+++ b/net/core/flow.c
101374@@ -65,7 +65,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
101375 static int flow_entry_valid(struct flow_cache_entry *fle,
101376 struct netns_xfrm *xfrm)
101377 {
101378- if (atomic_read(&xfrm->flow_cache_genid) != fle->genid)
101379+ if (atomic_read_unchecked(&xfrm->flow_cache_genid) != fle->genid)
101380 return 0;
101381 if (fle->object && !fle->object->ops->check(fle->object))
101382 return 0;
101383@@ -242,7 +242,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
101384 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
101385 fcp->hash_count++;
101386 }
101387- } else if (likely(fle->genid == atomic_read(&net->xfrm.flow_cache_genid))) {
101388+ } else if (likely(fle->genid == atomic_read_unchecked(&net->xfrm.flow_cache_genid))) {
101389 flo = fle->object;
101390 if (!flo)
101391 goto ret_object;
101392@@ -263,7 +263,7 @@ nocache:
101393 }
101394 flo = resolver(net, key, family, dir, flo, ctx);
101395 if (fle) {
101396- fle->genid = atomic_read(&net->xfrm.flow_cache_genid);
101397+ fle->genid = atomic_read_unchecked(&net->xfrm.flow_cache_genid);
101398 if (!IS_ERR(flo))
101399 fle->object = flo;
101400 else
101401diff --git a/net/core/iovec.c b/net/core/iovec.c
101402index e1ec45a..e5c6f16 100644
101403--- a/net/core/iovec.c
101404+++ b/net/core/iovec.c
101405@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
101406 if (m->msg_name && m->msg_namelen) {
101407 if (mode == VERIFY_READ) {
101408 void __user *namep;
101409- namep = (void __user __force *) m->msg_name;
101410+ namep = (void __force_user *) m->msg_name;
101411 err = move_addr_to_kernel(namep, m->msg_namelen,
101412 address);
101413 if (err < 0)
101414@@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
101415 }
101416
101417 size = m->msg_iovlen * sizeof(struct iovec);
101418- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
101419+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
101420 return -EFAULT;
101421
101422 m->msg_iov = iov;
101423diff --git a/net/core/neighbour.c b/net/core/neighbour.c
101424index ef31fef..8be66d9 100644
101425--- a/net/core/neighbour.c
101426+++ b/net/core/neighbour.c
101427@@ -2825,7 +2825,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
101428 void __user *buffer, size_t *lenp, loff_t *ppos)
101429 {
101430 int size, ret;
101431- struct ctl_table tmp = *ctl;
101432+ ctl_table_no_const tmp = *ctl;
101433
101434 tmp.extra1 = &zero;
101435 tmp.extra2 = &unres_qlen_max;
101436@@ -2887,7 +2887,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
101437 void __user *buffer,
101438 size_t *lenp, loff_t *ppos)
101439 {
101440- struct ctl_table tmp = *ctl;
101441+ ctl_table_no_const tmp = *ctl;
101442 int ret;
101443
101444 tmp.extra1 = &zero;
101445diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
101446index 2bf8329..2eb1423 100644
101447--- a/net/core/net-procfs.c
101448+++ b/net/core/net-procfs.c
101449@@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
101450 struct rtnl_link_stats64 temp;
101451 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
101452
101453- seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101454+ if (gr_proc_is_restricted())
101455+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101456+ "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
101457+ dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
101458+ 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
101459+ else
101460+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101461 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
101462 dev->name, stats->rx_bytes, stats->rx_packets,
101463 stats->rx_errors,
101464@@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
101465 return 0;
101466 }
101467
101468-static const struct seq_operations dev_seq_ops = {
101469+const struct seq_operations dev_seq_ops = {
101470 .start = dev_seq_start,
101471 .next = dev_seq_next,
101472 .stop = dev_seq_stop,
101473@@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
101474
101475 static int softnet_seq_open(struct inode *inode, struct file *file)
101476 {
101477- return seq_open(file, &softnet_seq_ops);
101478+ return seq_open_restrict(file, &softnet_seq_ops);
101479 }
101480
101481 static const struct file_operations softnet_seq_fops = {
101482@@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
101483 else
101484 seq_printf(seq, "%04x", ntohs(pt->type));
101485
101486+#ifdef CONFIG_GRKERNSEC_HIDESYM
101487+ seq_printf(seq, " %-8s %pf\n",
101488+ pt->dev ? pt->dev->name : "", NULL);
101489+#else
101490 seq_printf(seq, " %-8s %pf\n",
101491 pt->dev ? pt->dev->name : "", pt->func);
101492+#endif
101493 }
101494
101495 return 0;
101496diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
101497index 9dd0669..c52fb1b 100644
101498--- a/net/core/net-sysfs.c
101499+++ b/net/core/net-sysfs.c
101500@@ -278,7 +278,7 @@ static ssize_t carrier_changes_show(struct device *dev,
101501 {
101502 struct net_device *netdev = to_net_dev(dev);
101503 return sprintf(buf, fmt_dec,
101504- atomic_read(&netdev->carrier_changes));
101505+ atomic_read_unchecked(&netdev->carrier_changes));
101506 }
101507 static DEVICE_ATTR_RO(carrier_changes);
101508
101509diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
101510index 7f15517..f7d65c0 100644
101511--- a/net/core/net_namespace.c
101512+++ b/net/core/net_namespace.c
101513@@ -445,7 +445,7 @@ static int __register_pernet_operations(struct list_head *list,
101514 int error;
101515 LIST_HEAD(net_exit_list);
101516
101517- list_add_tail(&ops->list, list);
101518+ pax_list_add_tail((struct list_head *)&ops->list, list);
101519 if (ops->init || (ops->id && ops->size)) {
101520 for_each_net(net) {
101521 error = ops_init(ops, net);
101522@@ -458,7 +458,7 @@ static int __register_pernet_operations(struct list_head *list,
101523
101524 out_undo:
101525 /* If I have an error cleanup all namespaces I initialized */
101526- list_del(&ops->list);
101527+ pax_list_del((struct list_head *)&ops->list);
101528 ops_exit_list(ops, &net_exit_list);
101529 ops_free_list(ops, &net_exit_list);
101530 return error;
101531@@ -469,7 +469,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
101532 struct net *net;
101533 LIST_HEAD(net_exit_list);
101534
101535- list_del(&ops->list);
101536+ pax_list_del((struct list_head *)&ops->list);
101537 for_each_net(net)
101538 list_add_tail(&net->exit_list, &net_exit_list);
101539 ops_exit_list(ops, &net_exit_list);
101540@@ -603,7 +603,7 @@ int register_pernet_device(struct pernet_operations *ops)
101541 mutex_lock(&net_mutex);
101542 error = register_pernet_operations(&pernet_list, ops);
101543 if (!error && (first_device == &pernet_list))
101544- first_device = &ops->list;
101545+ first_device = (struct list_head *)&ops->list;
101546 mutex_unlock(&net_mutex);
101547 return error;
101548 }
101549diff --git a/net/core/netpoll.c b/net/core/netpoll.c
101550index e6645b4..43e1af9 100644
101551--- a/net/core/netpoll.c
101552+++ b/net/core/netpoll.c
101553@@ -379,7 +379,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
101554 struct udphdr *udph;
101555 struct iphdr *iph;
101556 struct ethhdr *eth;
101557- static atomic_t ip_ident;
101558+ static atomic_unchecked_t ip_ident;
101559 struct ipv6hdr *ip6h;
101560
101561 udp_len = len + sizeof(*udph);
101562@@ -450,7 +450,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
101563 put_unaligned(0x45, (unsigned char *)iph);
101564 iph->tos = 0;
101565 put_unaligned(htons(ip_len), &(iph->tot_len));
101566- iph->id = htons(atomic_inc_return(&ip_ident));
101567+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
101568 iph->frag_off = 0;
101569 iph->ttl = 64;
101570 iph->protocol = IPPROTO_UDP;
101571diff --git a/net/core/pktgen.c b/net/core/pktgen.c
101572index 443256b..bbff424 100644
101573--- a/net/core/pktgen.c
101574+++ b/net/core/pktgen.c
101575@@ -3753,7 +3753,7 @@ static int __net_init pg_net_init(struct net *net)
101576 pn->net = net;
101577 INIT_LIST_HEAD(&pn->pktgen_threads);
101578 pn->pktgen_exiting = false;
101579- pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
101580+ pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
101581 if (!pn->proc_dir) {
101582 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
101583 return -ENODEV;
101584diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
101585index 76321ea..3129bd6 100644
101586--- a/net/core/rtnetlink.c
101587+++ b/net/core/rtnetlink.c
101588@@ -58,7 +58,7 @@ struct rtnl_link {
101589 rtnl_doit_func doit;
101590 rtnl_dumpit_func dumpit;
101591 rtnl_calcit_func calcit;
101592-};
101593+} __no_const;
101594
101595 static DEFINE_MUTEX(rtnl_mutex);
101596
101597@@ -304,10 +304,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
101598 * to use the ops for creating device. So do not
101599 * fill up dellink as well. That disables rtnl_dellink.
101600 */
101601- if (ops->setup && !ops->dellink)
101602- ops->dellink = unregister_netdevice_queue;
101603+ if (ops->setup && !ops->dellink) {
101604+ pax_open_kernel();
101605+ *(void **)&ops->dellink = unregister_netdevice_queue;
101606+ pax_close_kernel();
101607+ }
101608
101609- list_add_tail(&ops->list, &link_ops);
101610+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
101611 return 0;
101612 }
101613 EXPORT_SYMBOL_GPL(__rtnl_link_register);
101614@@ -354,7 +357,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
101615 for_each_net(net) {
101616 __rtnl_kill_links(net, ops);
101617 }
101618- list_del(&ops->list);
101619+ pax_list_del((struct list_head *)&ops->list);
101620 }
101621 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
101622
101623@@ -1014,7 +1017,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
101624 (dev->ifalias &&
101625 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
101626 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
101627- atomic_read(&dev->carrier_changes)))
101628+ atomic_read_unchecked(&dev->carrier_changes)))
101629 goto nla_put_failure;
101630
101631 if (1) {
101632diff --git a/net/core/scm.c b/net/core/scm.c
101633index b442e7e..6f5b5a2 100644
101634--- a/net/core/scm.c
101635+++ b/net/core/scm.c
101636@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
101637 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
101638 {
101639 struct cmsghdr __user *cm
101640- = (__force struct cmsghdr __user *)msg->msg_control;
101641+ = (struct cmsghdr __force_user *)msg->msg_control;
101642 struct cmsghdr cmhdr;
101643 int cmlen = CMSG_LEN(len);
101644 int err;
101645@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
101646 err = -EFAULT;
101647 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
101648 goto out;
101649- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
101650+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
101651 goto out;
101652 cmlen = CMSG_SPACE(len);
101653 if (msg->msg_controllen < cmlen)
101654@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
101655 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
101656 {
101657 struct cmsghdr __user *cm
101658- = (__force struct cmsghdr __user*)msg->msg_control;
101659+ = (struct cmsghdr __force_user *)msg->msg_control;
101660
101661 int fdmax = 0;
101662 int fdnum = scm->fp->count;
101663@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
101664 if (fdnum < fdmax)
101665 fdmax = fdnum;
101666
101667- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
101668+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
101669 i++, cmfptr++)
101670 {
101671 struct socket *sock;
101672diff --git a/net/core/skbuff.c b/net/core/skbuff.c
101673index 32e31c2..e981248 100644
101674--- a/net/core/skbuff.c
101675+++ b/net/core/skbuff.c
101676@@ -2025,7 +2025,7 @@ EXPORT_SYMBOL(__skb_checksum);
101677 __wsum skb_checksum(const struct sk_buff *skb, int offset,
101678 int len, __wsum csum)
101679 {
101680- const struct skb_checksum_ops ops = {
101681+ static const struct skb_checksum_ops ops = {
101682 .update = csum_partial_ext,
101683 .combine = csum_block_add_ext,
101684 };
101685@@ -3255,12 +3255,14 @@ void __init skb_init(void)
101686 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
101687 sizeof(struct sk_buff),
101688 0,
101689- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
101690+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
101691+ SLAB_NO_SANITIZE,
101692 NULL);
101693 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
101694 sizeof(struct sk_buff_fclones),
101695 0,
101696- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
101697+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
101698+ SLAB_NO_SANITIZE,
101699 NULL);
101700 }
101701
101702diff --git a/net/core/sock.c b/net/core/sock.c
101703index 15e0c67..0310f4a 100644
101704--- a/net/core/sock.c
101705+++ b/net/core/sock.c
101706@@ -441,7 +441,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
101707 struct sk_buff_head *list = &sk->sk_receive_queue;
101708
101709 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
101710- atomic_inc(&sk->sk_drops);
101711+ atomic_inc_unchecked(&sk->sk_drops);
101712 trace_sock_rcvqueue_full(sk, skb);
101713 return -ENOMEM;
101714 }
101715@@ -451,7 +451,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
101716 return err;
101717
101718 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
101719- atomic_inc(&sk->sk_drops);
101720+ atomic_inc_unchecked(&sk->sk_drops);
101721 return -ENOBUFS;
101722 }
101723
101724@@ -464,7 +464,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
101725 skb_dst_force(skb);
101726
101727 spin_lock_irqsave(&list->lock, flags);
101728- skb->dropcount = atomic_read(&sk->sk_drops);
101729+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
101730 __skb_queue_tail(list, skb);
101731 spin_unlock_irqrestore(&list->lock, flags);
101732
101733@@ -484,7 +484,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
101734 skb->dev = NULL;
101735
101736 if (sk_rcvqueues_full(sk, sk->sk_rcvbuf)) {
101737- atomic_inc(&sk->sk_drops);
101738+ atomic_inc_unchecked(&sk->sk_drops);
101739 goto discard_and_relse;
101740 }
101741 if (nested)
101742@@ -502,7 +502,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
101743 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
101744 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
101745 bh_unlock_sock(sk);
101746- atomic_inc(&sk->sk_drops);
101747+ atomic_inc_unchecked(&sk->sk_drops);
101748 goto discard_and_relse;
101749 }
101750
101751@@ -991,12 +991,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
101752 struct timeval tm;
101753 } v;
101754
101755- int lv = sizeof(int);
101756- int len;
101757+ unsigned int lv = sizeof(int);
101758+ unsigned int len;
101759
101760 if (get_user(len, optlen))
101761 return -EFAULT;
101762- if (len < 0)
101763+ if (len > INT_MAX)
101764 return -EINVAL;
101765
101766 memset(&v, 0, sizeof(v));
101767@@ -1134,11 +1134,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
101768
101769 case SO_PEERNAME:
101770 {
101771- char address[128];
101772+ char address[_K_SS_MAXSIZE];
101773
101774 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
101775 return -ENOTCONN;
101776- if (lv < len)
101777+ if (lv < len || sizeof address < len)
101778 return -EINVAL;
101779 if (copy_to_user(optval, address, len))
101780 return -EFAULT;
101781@@ -1219,7 +1219,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
101782
101783 if (len > lv)
101784 len = lv;
101785- if (copy_to_user(optval, &v, len))
101786+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
101787 return -EFAULT;
101788 lenout:
101789 if (put_user(len, optlen))
101790@@ -2315,7 +2315,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
101791 */
101792 smp_wmb();
101793 atomic_set(&sk->sk_refcnt, 1);
101794- atomic_set(&sk->sk_drops, 0);
101795+ atomic_set_unchecked(&sk->sk_drops, 0);
101796 }
101797 EXPORT_SYMBOL(sock_init_data);
101798
101799@@ -2443,6 +2443,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
101800 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
101801 int level, int type)
101802 {
101803+ struct sock_extended_err ee;
101804 struct sock_exterr_skb *serr;
101805 struct sk_buff *skb;
101806 int copied, err;
101807@@ -2464,7 +2465,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
101808 sock_recv_timestamp(msg, sk, skb);
101809
101810 serr = SKB_EXT_ERR(skb);
101811- put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
101812+ ee = serr->ee;
101813+ put_cmsg(msg, level, type, sizeof ee, &ee);
101814
101815 msg->msg_flags |= MSG_ERRQUEUE;
101816 err = copied;
101817diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
101818index ad704c7..ca48aff 100644
101819--- a/net/core/sock_diag.c
101820+++ b/net/core/sock_diag.c
101821@@ -9,26 +9,33 @@
101822 #include <linux/inet_diag.h>
101823 #include <linux/sock_diag.h>
101824
101825-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
101826+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
101827 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
101828 static DEFINE_MUTEX(sock_diag_table_mutex);
101829
101830 int sock_diag_check_cookie(void *sk, __u32 *cookie)
101831 {
101832+#ifndef CONFIG_GRKERNSEC_HIDESYM
101833 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
101834 cookie[1] != INET_DIAG_NOCOOKIE) &&
101835 ((u32)(unsigned long)sk != cookie[0] ||
101836 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
101837 return -ESTALE;
101838 else
101839+#endif
101840 return 0;
101841 }
101842 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
101843
101844 void sock_diag_save_cookie(void *sk, __u32 *cookie)
101845 {
101846+#ifdef CONFIG_GRKERNSEC_HIDESYM
101847+ cookie[0] = 0;
101848+ cookie[1] = 0;
101849+#else
101850 cookie[0] = (u32)(unsigned long)sk;
101851 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
101852+#endif
101853 }
101854 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
101855
101856@@ -110,8 +117,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
101857 mutex_lock(&sock_diag_table_mutex);
101858 if (sock_diag_handlers[hndl->family])
101859 err = -EBUSY;
101860- else
101861+ else {
101862+ pax_open_kernel();
101863 sock_diag_handlers[hndl->family] = hndl;
101864+ pax_close_kernel();
101865+ }
101866 mutex_unlock(&sock_diag_table_mutex);
101867
101868 return err;
101869@@ -127,7 +137,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
101870
101871 mutex_lock(&sock_diag_table_mutex);
101872 BUG_ON(sock_diag_handlers[family] != hnld);
101873+ pax_open_kernel();
101874 sock_diag_handlers[family] = NULL;
101875+ pax_close_kernel();
101876 mutex_unlock(&sock_diag_table_mutex);
101877 }
101878 EXPORT_SYMBOL_GPL(sock_diag_unregister);
101879diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
101880index cf9cd13..50683950 100644
101881--- a/net/core/sysctl_net_core.c
101882+++ b/net/core/sysctl_net_core.c
101883@@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
101884 {
101885 unsigned int orig_size, size;
101886 int ret, i;
101887- struct ctl_table tmp = {
101888+ ctl_table_no_const tmp = {
101889 .data = &size,
101890 .maxlen = sizeof(size),
101891 .mode = table->mode
101892@@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
101893 void __user *buffer, size_t *lenp, loff_t *ppos)
101894 {
101895 char id[IFNAMSIZ];
101896- struct ctl_table tbl = {
101897+ ctl_table_no_const tbl = {
101898 .data = id,
101899 .maxlen = IFNAMSIZ,
101900 };
101901@@ -263,7 +263,7 @@ static struct ctl_table net_core_table[] = {
101902 .mode = 0644,
101903 .proc_handler = proc_dointvec
101904 },
101905-#ifdef CONFIG_BPF_JIT
101906+#if defined(CONFIG_BPF_JIT) && !defined(CONFIG_GRKERNSEC_BPF_HARDEN)
101907 {
101908 .procname = "bpf_jit_enable",
101909 .data = &bpf_jit_enable,
101910@@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
101911
101912 static __net_init int sysctl_core_net_init(struct net *net)
101913 {
101914- struct ctl_table *tbl;
101915+ ctl_table_no_const *tbl = NULL;
101916
101917 net->core.sysctl_somaxconn = SOMAXCONN;
101918
101919- tbl = netns_core_table;
101920 if (!net_eq(net, &init_net)) {
101921- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
101922+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
101923 if (tbl == NULL)
101924 goto err_dup;
101925
101926@@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
101927 if (net->user_ns != &init_user_ns) {
101928 tbl[0].procname = NULL;
101929 }
101930- }
101931-
101932- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
101933+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
101934+ } else
101935+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
101936 if (net->core.sysctl_hdr == NULL)
101937 goto err_reg;
101938
101939 return 0;
101940
101941 err_reg:
101942- if (tbl != netns_core_table)
101943- kfree(tbl);
101944+ kfree(tbl);
101945 err_dup:
101946 return -ENOMEM;
101947 }
101948@@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
101949 kfree(tbl);
101950 }
101951
101952-static __net_initdata struct pernet_operations sysctl_core_ops = {
101953+static __net_initconst struct pernet_operations sysctl_core_ops = {
101954 .init = sysctl_core_net_init,
101955 .exit = sysctl_core_net_exit,
101956 };
101957diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
101958index 25733d5..b9360f0 100644
101959--- a/net/decnet/af_decnet.c
101960+++ b/net/decnet/af_decnet.c
101961@@ -466,6 +466,7 @@ static struct proto dn_proto = {
101962 .sysctl_rmem = sysctl_decnet_rmem,
101963 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
101964 .obj_size = sizeof(struct dn_sock),
101965+ .slab_flags = SLAB_USERCOPY,
101966 };
101967
101968 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
101969diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
101970index 4400da7..3429972 100644
101971--- a/net/decnet/dn_dev.c
101972+++ b/net/decnet/dn_dev.c
101973@@ -201,7 +201,7 @@ static struct dn_dev_sysctl_table {
101974 .extra1 = &min_t3,
101975 .extra2 = &max_t3
101976 },
101977- {0}
101978+ { }
101979 },
101980 };
101981
101982diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
101983index 5325b54..a0d4d69 100644
101984--- a/net/decnet/sysctl_net_decnet.c
101985+++ b/net/decnet/sysctl_net_decnet.c
101986@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
101987
101988 if (len > *lenp) len = *lenp;
101989
101990- if (copy_to_user(buffer, addr, len))
101991+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
101992 return -EFAULT;
101993
101994 *lenp = len;
101995@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
101996
101997 if (len > *lenp) len = *lenp;
101998
101999- if (copy_to_user(buffer, devname, len))
102000+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
102001 return -EFAULT;
102002
102003 *lenp = len;
102004diff --git a/net/hsr/hsr_netlink.c b/net/hsr/hsr_netlink.c
102005index a2c7e4c..3dc9f67 100644
102006--- a/net/hsr/hsr_netlink.c
102007+++ b/net/hsr/hsr_netlink.c
102008@@ -102,7 +102,7 @@ nla_put_failure:
102009 return -EMSGSIZE;
102010 }
102011
102012-static struct rtnl_link_ops hsr_link_ops __read_mostly = {
102013+static struct rtnl_link_ops hsr_link_ops = {
102014 .kind = "hsr",
102015 .maxtype = IFLA_HSR_MAX,
102016 .policy = hsr_policy,
102017diff --git a/net/ieee802154/6lowpan_rtnl.c b/net/ieee802154/6lowpan_rtnl.c
102018index 4413629..dea596a 100644
102019--- a/net/ieee802154/6lowpan_rtnl.c
102020+++ b/net/ieee802154/6lowpan_rtnl.c
102021@@ -635,7 +635,7 @@ static void lowpan_dellink(struct net_device *dev, struct list_head *head)
102022 dev_put(real_dev);
102023 }
102024
102025-static struct rtnl_link_ops lowpan_link_ops __read_mostly = {
102026+static struct rtnl_link_ops lowpan_link_ops = {
102027 .kind = "lowpan",
102028 .priv_size = sizeof(struct lowpan_dev_info),
102029 .setup = lowpan_setup,
102030diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
102031index 7cfcd68..84ca5b7 100644
102032--- a/net/ieee802154/reassembly.c
102033+++ b/net/ieee802154/reassembly.c
102034@@ -433,14 +433,13 @@ static struct ctl_table lowpan_frags_ctl_table[] = {
102035
102036 static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102037 {
102038- struct ctl_table *table;
102039+ ctl_table_no_const *table = NULL;
102040 struct ctl_table_header *hdr;
102041 struct netns_ieee802154_lowpan *ieee802154_lowpan =
102042 net_ieee802154_lowpan(net);
102043
102044- table = lowpan_frags_ns_ctl_table;
102045 if (!net_eq(net, &init_net)) {
102046- table = kmemdup(table, sizeof(lowpan_frags_ns_ctl_table),
102047+ table = kmemdup(lowpan_frags_ns_ctl_table, sizeof(lowpan_frags_ns_ctl_table),
102048 GFP_KERNEL);
102049 if (table == NULL)
102050 goto err_alloc;
102051@@ -455,9 +454,9 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102052 /* Don't export sysctls to unprivileged users */
102053 if (net->user_ns != &init_user_ns)
102054 table[0].procname = NULL;
102055- }
102056-
102057- hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
102058+ hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
102059+ } else
102060+ hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", lowpan_frags_ns_ctl_table);
102061 if (hdr == NULL)
102062 goto err_reg;
102063
102064@@ -465,8 +464,7 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102065 return 0;
102066
102067 err_reg:
102068- if (!net_eq(net, &init_net))
102069- kfree(table);
102070+ kfree(table);
102071 err_alloc:
102072 return -ENOMEM;
102073 }
102074diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
102075index e67da4e..da217942 100644
102076--- a/net/ipv4/af_inet.c
102077+++ b/net/ipv4/af_inet.c
102078@@ -1392,7 +1392,7 @@ int inet_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
102079 return ip_recv_error(sk, msg, len, addr_len);
102080 #if IS_ENABLED(CONFIG_IPV6)
102081 if (sk->sk_family == AF_INET6)
102082- return pingv6_ops.ipv6_recv_error(sk, msg, len, addr_len);
102083+ return pingv6_ops->ipv6_recv_error(sk, msg, len, addr_len);
102084 #endif
102085 return -EINVAL;
102086 }
102087diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
102088index 214882e..ec032f6 100644
102089--- a/net/ipv4/devinet.c
102090+++ b/net/ipv4/devinet.c
102091@@ -69,7 +69,8 @@
102092
102093 static struct ipv4_devconf ipv4_devconf = {
102094 .data = {
102095- [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
102096+ [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 0,
102097+ [IPV4_DEVCONF_RP_FILTER - 1] = 1,
102098 [IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1,
102099 [IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1,
102100 [IPV4_DEVCONF_SHARED_MEDIA - 1] = 1,
102101@@ -80,7 +81,8 @@ static struct ipv4_devconf ipv4_devconf = {
102102
102103 static struct ipv4_devconf ipv4_devconf_dflt = {
102104 .data = {
102105- [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
102106+ [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 0,
102107+ [IPV4_DEVCONF_RP_FILTER - 1] = 1,
102108 [IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1,
102109 [IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1,
102110 [IPV4_DEVCONF_SHARED_MEDIA - 1] = 1,
102111@@ -1548,7 +1550,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
102112 idx = 0;
102113 head = &net->dev_index_head[h];
102114 rcu_read_lock();
102115- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
102116+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
102117 net->dev_base_seq;
102118 hlist_for_each_entry_rcu(dev, head, index_hlist) {
102119 if (idx < s_idx)
102120@@ -1866,7 +1868,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
102121 idx = 0;
102122 head = &net->dev_index_head[h];
102123 rcu_read_lock();
102124- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
102125+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
102126 net->dev_base_seq;
102127 hlist_for_each_entry_rcu(dev, head, index_hlist) {
102128 if (idx < s_idx)
102129@@ -2101,7 +2103,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
102130 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
102131 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
102132
102133-static struct devinet_sysctl_table {
102134+static const struct devinet_sysctl_table {
102135 struct ctl_table_header *sysctl_header;
102136 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
102137 } devinet_sysctl = {
102138@@ -2233,7 +2235,7 @@ static __net_init int devinet_init_net(struct net *net)
102139 int err;
102140 struct ipv4_devconf *all, *dflt;
102141 #ifdef CONFIG_SYSCTL
102142- struct ctl_table *tbl = ctl_forward_entry;
102143+ ctl_table_no_const *tbl = NULL;
102144 struct ctl_table_header *forw_hdr;
102145 #endif
102146
102147@@ -2251,7 +2253,7 @@ static __net_init int devinet_init_net(struct net *net)
102148 goto err_alloc_dflt;
102149
102150 #ifdef CONFIG_SYSCTL
102151- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
102152+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
102153 if (tbl == NULL)
102154 goto err_alloc_ctl;
102155
102156@@ -2271,7 +2273,10 @@ static __net_init int devinet_init_net(struct net *net)
102157 goto err_reg_dflt;
102158
102159 err = -ENOMEM;
102160- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
102161+ if (!net_eq(net, &init_net))
102162+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
102163+ else
102164+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
102165 if (forw_hdr == NULL)
102166 goto err_reg_ctl;
102167 net->ipv4.forw_hdr = forw_hdr;
102168@@ -2287,8 +2292,7 @@ err_reg_ctl:
102169 err_reg_dflt:
102170 __devinet_sysctl_unregister(all);
102171 err_reg_all:
102172- if (tbl != ctl_forward_entry)
102173- kfree(tbl);
102174+ kfree(tbl);
102175 err_alloc_ctl:
102176 #endif
102177 if (dflt != &ipv4_devconf_dflt)
102178diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
102179index 23104a3..9f5570b 100644
102180--- a/net/ipv4/fib_frontend.c
102181+++ b/net/ipv4/fib_frontend.c
102182@@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
102183 #ifdef CONFIG_IP_ROUTE_MULTIPATH
102184 fib_sync_up(dev);
102185 #endif
102186- atomic_inc(&net->ipv4.dev_addr_genid);
102187+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102188 rt_cache_flush(dev_net(dev));
102189 break;
102190 case NETDEV_DOWN:
102191 fib_del_ifaddr(ifa, NULL);
102192- atomic_inc(&net->ipv4.dev_addr_genid);
102193+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102194 if (ifa->ifa_dev->ifa_list == NULL) {
102195 /* Last address was deleted from this interface.
102196 * Disable IP.
102197@@ -1060,7 +1060,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
102198 #ifdef CONFIG_IP_ROUTE_MULTIPATH
102199 fib_sync_up(dev);
102200 #endif
102201- atomic_inc(&net->ipv4.dev_addr_genid);
102202+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102203 rt_cache_flush(net);
102204 break;
102205 case NETDEV_DOWN:
102206diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
102207index f99f41b..1879da9 100644
102208--- a/net/ipv4/fib_semantics.c
102209+++ b/net/ipv4/fib_semantics.c
102210@@ -770,7 +770,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
102211 nh->nh_saddr = inet_select_addr(nh->nh_dev,
102212 nh->nh_gw,
102213 nh->nh_parent->fib_scope);
102214- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
102215+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
102216
102217 return nh->nh_saddr;
102218 }
102219diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
102220index 9111a4e..3576905 100644
102221--- a/net/ipv4/inet_hashtables.c
102222+++ b/net/ipv4/inet_hashtables.c
102223@@ -18,6 +18,7 @@
102224 #include <linux/sched.h>
102225 #include <linux/slab.h>
102226 #include <linux/wait.h>
102227+#include <linux/security.h>
102228
102229 #include <net/inet_connection_sock.h>
102230 #include <net/inet_hashtables.h>
102231@@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
102232 return inet_ehashfn(net, laddr, lport, faddr, fport);
102233 }
102234
102235+extern void gr_update_task_in_ip_table(const struct inet_sock *inet);
102236+
102237 /*
102238 * Allocate and initialize a new local port bind bucket.
102239 * The bindhash mutex for snum's hash chain must be held here.
102240@@ -554,6 +557,8 @@ ok:
102241 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
102242 spin_unlock(&head->lock);
102243
102244+ gr_update_task_in_ip_table(inet_sk(sk));
102245+
102246 if (tw) {
102247 inet_twsk_deschedule(tw, death_row);
102248 while (twrefcnt) {
102249diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
102250index 241afd7..31b95d5 100644
102251--- a/net/ipv4/inetpeer.c
102252+++ b/net/ipv4/inetpeer.c
102253@@ -461,7 +461,7 @@ relookup:
102254 if (p) {
102255 p->daddr = *daddr;
102256 atomic_set(&p->refcnt, 1);
102257- atomic_set(&p->rid, 0);
102258+ atomic_set_unchecked(&p->rid, 0);
102259 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
102260 p->rate_tokens = 0;
102261 /* 60*HZ is arbitrary, but chosen enough high so that the first
102262diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
102263index 2811cc1..ad5a534 100644
102264--- a/net/ipv4/ip_fragment.c
102265+++ b/net/ipv4/ip_fragment.c
102266@@ -268,7 +268,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
102267 return 0;
102268
102269 start = qp->rid;
102270- end = atomic_inc_return(&peer->rid);
102271+ end = atomic_inc_return_unchecked(&peer->rid);
102272 qp->rid = end;
102273
102274 rc = qp->q.fragments && (end - start) > max;
102275@@ -746,12 +746,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
102276
102277 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102278 {
102279- struct ctl_table *table;
102280+ ctl_table_no_const *table = NULL;
102281 struct ctl_table_header *hdr;
102282
102283- table = ip4_frags_ns_ctl_table;
102284 if (!net_eq(net, &init_net)) {
102285- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
102286+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
102287 if (table == NULL)
102288 goto err_alloc;
102289
102290@@ -765,9 +764,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102291 /* Don't export sysctls to unprivileged users */
102292 if (net->user_ns != &init_user_ns)
102293 table[0].procname = NULL;
102294- }
102295+ hdr = register_net_sysctl(net, "net/ipv4", table);
102296+ } else
102297+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
102298
102299- hdr = register_net_sysctl(net, "net/ipv4", table);
102300 if (hdr == NULL)
102301 goto err_reg;
102302
102303@@ -775,8 +775,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102304 return 0;
102305
102306 err_reg:
102307- if (!net_eq(net, &init_net))
102308- kfree(table);
102309+ kfree(table);
102310 err_alloc:
102311 return -ENOMEM;
102312 }
102313diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
102314index 12055fd..df852c4 100644
102315--- a/net/ipv4/ip_gre.c
102316+++ b/net/ipv4/ip_gre.c
102317@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
102318 module_param(log_ecn_error, bool, 0644);
102319 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
102320
102321-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
102322+static struct rtnl_link_ops ipgre_link_ops;
102323 static int ipgre_tunnel_init(struct net_device *dev);
102324
102325 static int ipgre_net_id __read_mostly;
102326@@ -815,7 +815,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
102327 [IFLA_GRE_ENCAP_DPORT] = { .type = NLA_U16 },
102328 };
102329
102330-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
102331+static struct rtnl_link_ops ipgre_link_ops = {
102332 .kind = "gre",
102333 .maxtype = IFLA_GRE_MAX,
102334 .policy = ipgre_policy,
102335@@ -829,7 +829,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
102336 .fill_info = ipgre_fill_info,
102337 };
102338
102339-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
102340+static struct rtnl_link_ops ipgre_tap_ops = {
102341 .kind = "gretap",
102342 .maxtype = IFLA_GRE_MAX,
102343 .policy = ipgre_policy,
102344diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
102345index 3d4da2c..40f9c29 100644
102346--- a/net/ipv4/ip_input.c
102347+++ b/net/ipv4/ip_input.c
102348@@ -147,6 +147,10 @@
102349 #include <linux/mroute.h>
102350 #include <linux/netlink.h>
102351
102352+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102353+extern int grsec_enable_blackhole;
102354+#endif
102355+
102356 /*
102357 * Process Router Attention IP option (RFC 2113)
102358 */
102359@@ -223,6 +227,9 @@ static int ip_local_deliver_finish(struct sk_buff *skb)
102360 if (!raw) {
102361 if (xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
102362 IP_INC_STATS_BH(net, IPSTATS_MIB_INUNKNOWNPROTOS);
102363+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102364+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
102365+#endif
102366 icmp_send(skb, ICMP_DEST_UNREACH,
102367 ICMP_PROT_UNREACH, 0);
102368 }
102369diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
102370index 9daf217..dc6972d 100644
102371--- a/net/ipv4/ip_sockglue.c
102372+++ b/net/ipv4/ip_sockglue.c
102373@@ -1177,7 +1177,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
102374 len = min_t(unsigned int, len, opt->optlen);
102375 if (put_user(len, optlen))
102376 return -EFAULT;
102377- if (copy_to_user(optval, opt->__data, len))
102378+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
102379+ copy_to_user(optval, opt->__data, len))
102380 return -EFAULT;
102381 return 0;
102382 }
102383@@ -1308,7 +1309,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
102384 if (sk->sk_type != SOCK_STREAM)
102385 return -ENOPROTOOPT;
102386
102387- msg.msg_control = (__force void *) optval;
102388+ msg.msg_control = (__force_kernel void *) optval;
102389 msg.msg_controllen = len;
102390 msg.msg_flags = flags;
102391
102392diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
102393index 1a7e979..fd05aa4 100644
102394--- a/net/ipv4/ip_vti.c
102395+++ b/net/ipv4/ip_vti.c
102396@@ -45,7 +45,7 @@
102397 #include <net/net_namespace.h>
102398 #include <net/netns/generic.h>
102399
102400-static struct rtnl_link_ops vti_link_ops __read_mostly;
102401+static struct rtnl_link_ops vti_link_ops;
102402
102403 static int vti_net_id __read_mostly;
102404 static int vti_tunnel_init(struct net_device *dev);
102405@@ -519,7 +519,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
102406 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
102407 };
102408
102409-static struct rtnl_link_ops vti_link_ops __read_mostly = {
102410+static struct rtnl_link_ops vti_link_ops = {
102411 .kind = "vti",
102412 .maxtype = IFLA_VTI_MAX,
102413 .policy = vti_policy,
102414diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
102415index 648fa14..97864d0 100644
102416--- a/net/ipv4/ipconfig.c
102417+++ b/net/ipv4/ipconfig.c
102418@@ -333,7 +333,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
102419
102420 mm_segment_t oldfs = get_fs();
102421 set_fs(get_ds());
102422- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
102423+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
102424 set_fs(oldfs);
102425 return res;
102426 }
102427@@ -344,7 +344,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
102428
102429 mm_segment_t oldfs = get_fs();
102430 set_fs(get_ds());
102431- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
102432+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
102433 set_fs(oldfs);
102434 return res;
102435 }
102436@@ -355,7 +355,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
102437
102438 mm_segment_t oldfs = get_fs();
102439 set_fs(get_ds());
102440- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
102441+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
102442 set_fs(oldfs);
102443 return res;
102444 }
102445diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
102446index 37096d6..86abb03 100644
102447--- a/net/ipv4/ipip.c
102448+++ b/net/ipv4/ipip.c
102449@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
102450 static int ipip_net_id __read_mostly;
102451
102452 static int ipip_tunnel_init(struct net_device *dev);
102453-static struct rtnl_link_ops ipip_link_ops __read_mostly;
102454+static struct rtnl_link_ops ipip_link_ops;
102455
102456 static int ipip_err(struct sk_buff *skb, u32 info)
102457 {
102458@@ -487,7 +487,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
102459 [IFLA_IPTUN_ENCAP_DPORT] = { .type = NLA_U16 },
102460 };
102461
102462-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
102463+static struct rtnl_link_ops ipip_link_ops = {
102464 .kind = "ipip",
102465 .maxtype = IFLA_IPTUN_MAX,
102466 .policy = ipip_policy,
102467diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
102468index f95b6f9..2ee2097 100644
102469--- a/net/ipv4/netfilter/arp_tables.c
102470+++ b/net/ipv4/netfilter/arp_tables.c
102471@@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
102472 #endif
102473
102474 static int get_info(struct net *net, void __user *user,
102475- const int *len, int compat)
102476+ int len, int compat)
102477 {
102478 char name[XT_TABLE_MAXNAMELEN];
102479 struct xt_table *t;
102480 int ret;
102481
102482- if (*len != sizeof(struct arpt_getinfo)) {
102483- duprintf("length %u != %Zu\n", *len,
102484+ if (len != sizeof(struct arpt_getinfo)) {
102485+ duprintf("length %u != %Zu\n", len,
102486 sizeof(struct arpt_getinfo));
102487 return -EINVAL;
102488 }
102489@@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
102490 info.size = private->size;
102491 strcpy(info.name, name);
102492
102493- if (copy_to_user(user, &info, *len) != 0)
102494+ if (copy_to_user(user, &info, len) != 0)
102495 ret = -EFAULT;
102496 else
102497 ret = 0;
102498@@ -1690,7 +1690,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
102499
102500 switch (cmd) {
102501 case ARPT_SO_GET_INFO:
102502- ret = get_info(sock_net(sk), user, len, 1);
102503+ ret = get_info(sock_net(sk), user, *len, 1);
102504 break;
102505 case ARPT_SO_GET_ENTRIES:
102506 ret = compat_get_entries(sock_net(sk), user, len);
102507@@ -1735,7 +1735,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
102508
102509 switch (cmd) {
102510 case ARPT_SO_GET_INFO:
102511- ret = get_info(sock_net(sk), user, len, 0);
102512+ ret = get_info(sock_net(sk), user, *len, 0);
102513 break;
102514
102515 case ARPT_SO_GET_ENTRIES:
102516diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
102517index 99e810f..3711b81 100644
102518--- a/net/ipv4/netfilter/ip_tables.c
102519+++ b/net/ipv4/netfilter/ip_tables.c
102520@@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
102521 #endif
102522
102523 static int get_info(struct net *net, void __user *user,
102524- const int *len, int compat)
102525+ int len, int compat)
102526 {
102527 char name[XT_TABLE_MAXNAMELEN];
102528 struct xt_table *t;
102529 int ret;
102530
102531- if (*len != sizeof(struct ipt_getinfo)) {
102532- duprintf("length %u != %zu\n", *len,
102533+ if (len != sizeof(struct ipt_getinfo)) {
102534+ duprintf("length %u != %zu\n", len,
102535 sizeof(struct ipt_getinfo));
102536 return -EINVAL;
102537 }
102538@@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
102539 info.size = private->size;
102540 strcpy(info.name, name);
102541
102542- if (copy_to_user(user, &info, *len) != 0)
102543+ if (copy_to_user(user, &info, len) != 0)
102544 ret = -EFAULT;
102545 else
102546 ret = 0;
102547@@ -1973,7 +1973,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
102548
102549 switch (cmd) {
102550 case IPT_SO_GET_INFO:
102551- ret = get_info(sock_net(sk), user, len, 1);
102552+ ret = get_info(sock_net(sk), user, *len, 1);
102553 break;
102554 case IPT_SO_GET_ENTRIES:
102555 ret = compat_get_entries(sock_net(sk), user, len);
102556@@ -2020,7 +2020,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
102557
102558 switch (cmd) {
102559 case IPT_SO_GET_INFO:
102560- ret = get_info(sock_net(sk), user, len, 0);
102561+ ret = get_info(sock_net(sk), user, *len, 0);
102562 break;
102563
102564 case IPT_SO_GET_ENTRIES:
102565diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
102566index e90f83a..3e6acca 100644
102567--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
102568+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
102569@@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
102570 spin_lock_init(&cn->lock);
102571
102572 #ifdef CONFIG_PROC_FS
102573- cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
102574+ cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
102575 if (!cn->procdir) {
102576 pr_err("Unable to proc dir entry\n");
102577 return -ENOMEM;
102578diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
102579index 5d740cc..b2842b9 100644
102580--- a/net/ipv4/ping.c
102581+++ b/net/ipv4/ping.c
102582@@ -59,7 +59,7 @@ struct ping_table {
102583 };
102584
102585 static struct ping_table ping_table;
102586-struct pingv6_ops pingv6_ops;
102587+struct pingv6_ops *pingv6_ops;
102588 EXPORT_SYMBOL_GPL(pingv6_ops);
102589
102590 static u16 ping_port_rover;
102591@@ -350,7 +350,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
102592 return -ENODEV;
102593 }
102594 }
102595- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
102596+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
102597 scoped);
102598 rcu_read_unlock();
102599
102600@@ -558,7 +558,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
102601 }
102602 #if IS_ENABLED(CONFIG_IPV6)
102603 } else if (skb->protocol == htons(ETH_P_IPV6)) {
102604- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
102605+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
102606 #endif
102607 }
102608
102609@@ -576,7 +576,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
102610 info, (u8 *)icmph);
102611 #if IS_ENABLED(CONFIG_IPV6)
102612 } else if (family == AF_INET6) {
102613- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
102614+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
102615 info, (u8 *)icmph);
102616 #endif
102617 }
102618@@ -910,10 +910,10 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
102619 }
102620
102621 if (inet6_sk(sk)->rxopt.all)
102622- pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
102623+ pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
102624 if (skb->protocol == htons(ETH_P_IPV6) &&
102625 inet6_sk(sk)->rxopt.all)
102626- pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
102627+ pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
102628 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
102629 ip_cmsg_recv(msg, skb);
102630 #endif
102631@@ -1105,7 +1105,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
102632 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
102633 0, sock_i_ino(sp),
102634 atomic_read(&sp->sk_refcnt), sp,
102635- atomic_read(&sp->sk_drops));
102636+ atomic_read_unchecked(&sp->sk_drops));
102637 }
102638
102639 static int ping_v4_seq_show(struct seq_file *seq, void *v)
102640diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
102641index 739db31..74f0210 100644
102642--- a/net/ipv4/raw.c
102643+++ b/net/ipv4/raw.c
102644@@ -314,7 +314,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
102645 int raw_rcv(struct sock *sk, struct sk_buff *skb)
102646 {
102647 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
102648- atomic_inc(&sk->sk_drops);
102649+ atomic_inc_unchecked(&sk->sk_drops);
102650 kfree_skb(skb);
102651 return NET_RX_DROP;
102652 }
102653@@ -755,16 +755,20 @@ static int raw_init(struct sock *sk)
102654
102655 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
102656 {
102657+ struct icmp_filter filter;
102658+
102659 if (optlen > sizeof(struct icmp_filter))
102660 optlen = sizeof(struct icmp_filter);
102661- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
102662+ if (copy_from_user(&filter, optval, optlen))
102663 return -EFAULT;
102664+ raw_sk(sk)->filter = filter;
102665 return 0;
102666 }
102667
102668 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
102669 {
102670 int len, ret = -EFAULT;
102671+ struct icmp_filter filter;
102672
102673 if (get_user(len, optlen))
102674 goto out;
102675@@ -774,8 +778,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
102676 if (len > sizeof(struct icmp_filter))
102677 len = sizeof(struct icmp_filter);
102678 ret = -EFAULT;
102679- if (put_user(len, optlen) ||
102680- copy_to_user(optval, &raw_sk(sk)->filter, len))
102681+ filter = raw_sk(sk)->filter;
102682+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
102683 goto out;
102684 ret = 0;
102685 out: return ret;
102686@@ -1004,7 +1008,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
102687 0, 0L, 0,
102688 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
102689 0, sock_i_ino(sp),
102690- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
102691+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
102692 }
102693
102694 static int raw_seq_show(struct seq_file *seq, void *v)
102695diff --git a/net/ipv4/route.c b/net/ipv4/route.c
102696index 6a2155b..d426880 100644
102697--- a/net/ipv4/route.c
102698+++ b/net/ipv4/route.c
102699@@ -228,7 +228,7 @@ static const struct seq_operations rt_cache_seq_ops = {
102700
102701 static int rt_cache_seq_open(struct inode *inode, struct file *file)
102702 {
102703- return seq_open(file, &rt_cache_seq_ops);
102704+ return seq_open_restrict(file, &rt_cache_seq_ops);
102705 }
102706
102707 static const struct file_operations rt_cache_seq_fops = {
102708@@ -319,7 +319,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
102709
102710 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
102711 {
102712- return seq_open(file, &rt_cpu_seq_ops);
102713+ return seq_open_restrict(file, &rt_cpu_seq_ops);
102714 }
102715
102716 static const struct file_operations rt_cpu_seq_fops = {
102717@@ -357,7 +357,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
102718
102719 static int rt_acct_proc_open(struct inode *inode, struct file *file)
102720 {
102721- return single_open(file, rt_acct_proc_show, NULL);
102722+ return single_open_restrict(file, rt_acct_proc_show, NULL);
102723 }
102724
102725 static const struct file_operations rt_acct_proc_fops = {
102726@@ -459,11 +459,11 @@ static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst,
102727
102728 #define IP_IDENTS_SZ 2048u
102729 struct ip_ident_bucket {
102730- atomic_t id;
102731+ atomic_unchecked_t id;
102732 u32 stamp32;
102733 };
102734
102735-static struct ip_ident_bucket *ip_idents __read_mostly;
102736+static struct ip_ident_bucket ip_idents[IP_IDENTS_SZ] __read_mostly;
102737
102738 /* In order to protect privacy, we add a perturbation to identifiers
102739 * if one generator is seldom used. This makes hard for an attacker
102740@@ -479,7 +479,7 @@ u32 ip_idents_reserve(u32 hash, int segs)
102741 if (old != now && cmpxchg(&bucket->stamp32, old, now) == old)
102742 delta = prandom_u32_max(now - old);
102743
102744- return atomic_add_return(segs + delta, &bucket->id) - segs;
102745+ return atomic_add_return_unchecked(segs + delta, &bucket->id) - segs;
102746 }
102747 EXPORT_SYMBOL(ip_idents_reserve);
102748
102749@@ -2624,34 +2624,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
102750 .maxlen = sizeof(int),
102751 .mode = 0200,
102752 .proc_handler = ipv4_sysctl_rtcache_flush,
102753+ .extra1 = &init_net,
102754 },
102755 { },
102756 };
102757
102758 static __net_init int sysctl_route_net_init(struct net *net)
102759 {
102760- struct ctl_table *tbl;
102761+ ctl_table_no_const *tbl = NULL;
102762
102763- tbl = ipv4_route_flush_table;
102764 if (!net_eq(net, &init_net)) {
102765- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
102766+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
102767 if (tbl == NULL)
102768 goto err_dup;
102769
102770 /* Don't export sysctls to unprivileged users */
102771 if (net->user_ns != &init_user_ns)
102772 tbl[0].procname = NULL;
102773- }
102774- tbl[0].extra1 = net;
102775+ tbl[0].extra1 = net;
102776+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
102777+ } else
102778+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
102779
102780- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
102781 if (net->ipv4.route_hdr == NULL)
102782 goto err_reg;
102783 return 0;
102784
102785 err_reg:
102786- if (tbl != ipv4_route_flush_table)
102787- kfree(tbl);
102788+ kfree(tbl);
102789 err_dup:
102790 return -ENOMEM;
102791 }
102792@@ -2674,8 +2674,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
102793
102794 static __net_init int rt_genid_init(struct net *net)
102795 {
102796- atomic_set(&net->ipv4.rt_genid, 0);
102797- atomic_set(&net->fnhe_genid, 0);
102798+ atomic_set_unchecked(&net->ipv4.rt_genid, 0);
102799+ atomic_set_unchecked(&net->fnhe_genid, 0);
102800 get_random_bytes(&net->ipv4.dev_addr_genid,
102801 sizeof(net->ipv4.dev_addr_genid));
102802 return 0;
102803@@ -2718,11 +2718,7 @@ int __init ip_rt_init(void)
102804 {
102805 int rc = 0;
102806
102807- ip_idents = kmalloc(IP_IDENTS_SZ * sizeof(*ip_idents), GFP_KERNEL);
102808- if (!ip_idents)
102809- panic("IP: failed to allocate ip_idents\n");
102810-
102811- prandom_bytes(ip_idents, IP_IDENTS_SZ * sizeof(*ip_idents));
102812+ prandom_bytes(ip_idents, sizeof(ip_idents));
102813
102814 #ifdef CONFIG_IP_ROUTE_CLASSID
102815 ip_rt_acct = __alloc_percpu(256 * sizeof(struct ip_rt_acct), __alignof__(struct ip_rt_acct));
102816diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
102817index b3c53c8..35cc18d 100644
102818--- a/net/ipv4/sysctl_net_ipv4.c
102819+++ b/net/ipv4/sysctl_net_ipv4.c
102820@@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
102821 container_of(table->data, struct net, ipv4.ip_local_ports.range);
102822 int ret;
102823 int range[2];
102824- struct ctl_table tmp = {
102825+ ctl_table_no_const tmp = {
102826 .data = &range,
102827 .maxlen = sizeof(range),
102828 .mode = table->mode,
102829@@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
102830 int ret;
102831 gid_t urange[2];
102832 kgid_t low, high;
102833- struct ctl_table tmp = {
102834+ ctl_table_no_const tmp = {
102835 .data = &urange,
102836 .maxlen = sizeof(urange),
102837 .mode = table->mode,
102838@@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
102839 void __user *buffer, size_t *lenp, loff_t *ppos)
102840 {
102841 char val[TCP_CA_NAME_MAX];
102842- struct ctl_table tbl = {
102843+ ctl_table_no_const tbl = {
102844 .data = val,
102845 .maxlen = TCP_CA_NAME_MAX,
102846 };
102847@@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
102848 void __user *buffer, size_t *lenp,
102849 loff_t *ppos)
102850 {
102851- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
102852+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
102853 int ret;
102854
102855 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
102856@@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
102857 void __user *buffer, size_t *lenp,
102858 loff_t *ppos)
102859 {
102860- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
102861+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
102862 int ret;
102863
102864 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
102865@@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
102866 void __user *buffer, size_t *lenp,
102867 loff_t *ppos)
102868 {
102869- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
102870+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
102871 struct tcp_fastopen_context *ctxt;
102872 int ret;
102873 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
102874@@ -874,13 +874,12 @@ static struct ctl_table ipv4_net_table[] = {
102875
102876 static __net_init int ipv4_sysctl_init_net(struct net *net)
102877 {
102878- struct ctl_table *table;
102879+ ctl_table_no_const *table = NULL;
102880
102881- table = ipv4_net_table;
102882 if (!net_eq(net, &init_net)) {
102883 int i;
102884
102885- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
102886+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
102887 if (table == NULL)
102888 goto err_alloc;
102889
102890@@ -889,7 +888,10 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
102891 table[i].data += (void *)net - (void *)&init_net;
102892 }
102893
102894- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
102895+ if (!net_eq(net, &init_net))
102896+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
102897+ else
102898+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
102899 if (net->ipv4.ipv4_hdr == NULL)
102900 goto err_reg;
102901
102902diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
102903index d107ee2..bcebf11 100644
102904--- a/net/ipv4/tcp_input.c
102905+++ b/net/ipv4/tcp_input.c
102906@@ -765,7 +765,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
102907 * without any lock. We want to make sure compiler wont store
102908 * intermediate values in this location.
102909 */
102910- ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
102911+ ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
102912 sk->sk_max_pacing_rate);
102913 }
102914
102915@@ -4527,7 +4527,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
102916 * simplifies code)
102917 */
102918 static void
102919-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
102920+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
102921 struct sk_buff *head, struct sk_buff *tail,
102922 u32 start, u32 end)
102923 {
102924@@ -5506,6 +5506,7 @@ discard:
102925 tcp_paws_reject(&tp->rx_opt, 0))
102926 goto discard_and_undo;
102927
102928+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
102929 if (th->syn) {
102930 /* We see SYN without ACK. It is attempt of
102931 * simultaneous connect with crossed SYNs.
102932@@ -5556,6 +5557,7 @@ discard:
102933 goto discard;
102934 #endif
102935 }
102936+#endif
102937 /* "fifth, if neither of the SYN or RST bits is set then
102938 * drop the segment and return."
102939 */
102940@@ -5602,7 +5604,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
102941 goto discard;
102942
102943 if (th->syn) {
102944- if (th->fin)
102945+ if (th->fin || th->urg || th->psh)
102946 goto discard;
102947 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
102948 return 1;
102949diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
102950index ef7089c..a3e65fb 100644
102951--- a/net/ipv4/tcp_ipv4.c
102952+++ b/net/ipv4/tcp_ipv4.c
102953@@ -89,6 +89,10 @@ int sysctl_tcp_tw_reuse __read_mostly;
102954 int sysctl_tcp_low_latency __read_mostly;
102955 EXPORT_SYMBOL(sysctl_tcp_low_latency);
102956
102957+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102958+extern int grsec_enable_blackhole;
102959+#endif
102960+
102961 #ifdef CONFIG_TCP_MD5SIG
102962 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
102963 __be32 daddr, __be32 saddr, const struct tcphdr *th);
102964@@ -1469,6 +1473,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
102965 return 0;
102966
102967 reset:
102968+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102969+ if (!grsec_enable_blackhole)
102970+#endif
102971 tcp_v4_send_reset(rsk, skb);
102972 discard:
102973 kfree_skb(skb);
102974@@ -1633,12 +1640,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
102975 TCP_SKB_CB(skb)->sacked = 0;
102976
102977 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
102978- if (!sk)
102979+ if (!sk) {
102980+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102981+ ret = 1;
102982+#endif
102983 goto no_tcp_socket;
102984-
102985+ }
102986 process:
102987- if (sk->sk_state == TCP_TIME_WAIT)
102988+ if (sk->sk_state == TCP_TIME_WAIT) {
102989+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102990+ ret = 2;
102991+#endif
102992 goto do_time_wait;
102993+ }
102994
102995 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
102996 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
102997@@ -1694,6 +1708,10 @@ csum_error:
102998 bad_packet:
102999 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
103000 } else {
103001+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103002+ if (!grsec_enable_blackhole || (ret == 1 &&
103003+ (skb->dev->flags & IFF_LOOPBACK)))
103004+#endif
103005 tcp_v4_send_reset(NULL, skb);
103006 }
103007
103008diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
103009index 63d2680..2db9d6b 100644
103010--- a/net/ipv4/tcp_minisocks.c
103011+++ b/net/ipv4/tcp_minisocks.c
103012@@ -27,6 +27,10 @@
103013 #include <net/inet_common.h>
103014 #include <net/xfrm.h>
103015
103016+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103017+extern int grsec_enable_blackhole;
103018+#endif
103019+
103020 int sysctl_tcp_syncookies __read_mostly = 1;
103021 EXPORT_SYMBOL(sysctl_tcp_syncookies);
103022
103023@@ -739,7 +743,10 @@ embryonic_reset:
103024 * avoid becoming vulnerable to outside attack aiming at
103025 * resetting legit local connections.
103026 */
103027- req->rsk_ops->send_reset(sk, skb);
103028+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103029+ if (!grsec_enable_blackhole)
103030+#endif
103031+ req->rsk_ops->send_reset(sk, skb);
103032 } else if (fastopen) { /* received a valid RST pkt */
103033 reqsk_fastopen_remove(sk, req, true);
103034 tcp_reset(sk);
103035diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
103036index ebf5ff5..4d1ff32 100644
103037--- a/net/ipv4/tcp_probe.c
103038+++ b/net/ipv4/tcp_probe.c
103039@@ -236,7 +236,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
103040 if (cnt + width >= len)
103041 break;
103042
103043- if (copy_to_user(buf + cnt, tbuf, width))
103044+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
103045 return -EFAULT;
103046 cnt += width;
103047 }
103048diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
103049index 9b21ae8..4eb67df 100644
103050--- a/net/ipv4/tcp_timer.c
103051+++ b/net/ipv4/tcp_timer.c
103052@@ -22,6 +22,10 @@
103053 #include <linux/gfp.h>
103054 #include <net/tcp.h>
103055
103056+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103057+extern int grsec_lastack_retries;
103058+#endif
103059+
103060 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
103061 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
103062 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
103063@@ -191,6 +195,13 @@ static int tcp_write_timeout(struct sock *sk)
103064 }
103065 }
103066
103067+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103068+ if ((sk->sk_state == TCP_LAST_ACK) &&
103069+ (grsec_lastack_retries > 0) &&
103070+ (grsec_lastack_retries < retry_until))
103071+ retry_until = grsec_lastack_retries;
103072+#endif
103073+
103074 if (retransmits_timed_out(sk, retry_until,
103075 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
103076 /* Has it gone just too far? */
103077diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
103078index cd0db54..93a6518 100644
103079--- a/net/ipv4/udp.c
103080+++ b/net/ipv4/udp.c
103081@@ -87,6 +87,7 @@
103082 #include <linux/types.h>
103083 #include <linux/fcntl.h>
103084 #include <linux/module.h>
103085+#include <linux/security.h>
103086 #include <linux/socket.h>
103087 #include <linux/sockios.h>
103088 #include <linux/igmp.h>
103089@@ -114,6 +115,10 @@
103090 #include <net/busy_poll.h>
103091 #include "udp_impl.h"
103092
103093+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103094+extern int grsec_enable_blackhole;
103095+#endif
103096+
103097 struct udp_table udp_table __read_mostly;
103098 EXPORT_SYMBOL(udp_table);
103099
103100@@ -595,6 +600,9 @@ static inline bool __udp_is_mcast_sock(struct net *net, struct sock *sk,
103101 return true;
103102 }
103103
103104+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
103105+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
103106+
103107 /*
103108 * This routine is called by the ICMP module when it gets some
103109 * sort of error condition. If err < 0 then the socket should
103110@@ -932,9 +940,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
103111 dport = usin->sin_port;
103112 if (dport == 0)
103113 return -EINVAL;
103114+
103115+ err = gr_search_udp_sendmsg(sk, usin);
103116+ if (err)
103117+ return err;
103118 } else {
103119 if (sk->sk_state != TCP_ESTABLISHED)
103120 return -EDESTADDRREQ;
103121+
103122+ err = gr_search_udp_sendmsg(sk, NULL);
103123+ if (err)
103124+ return err;
103125+
103126 daddr = inet->inet_daddr;
103127 dport = inet->inet_dport;
103128 /* Open fast path for connected socket.
103129@@ -1182,7 +1199,7 @@ static unsigned int first_packet_length(struct sock *sk)
103130 IS_UDPLITE(sk));
103131 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
103132 IS_UDPLITE(sk));
103133- atomic_inc(&sk->sk_drops);
103134+ atomic_inc_unchecked(&sk->sk_drops);
103135 __skb_unlink(skb, rcvq);
103136 __skb_queue_tail(&list_kill, skb);
103137 }
103138@@ -1262,6 +1279,10 @@ try_again:
103139 if (!skb)
103140 goto out;
103141
103142+ err = gr_search_udp_recvmsg(sk, skb);
103143+ if (err)
103144+ goto out_free;
103145+
103146 ulen = skb->len - sizeof(struct udphdr);
103147 copied = len;
103148 if (copied > ulen)
103149@@ -1295,7 +1316,7 @@ try_again:
103150 if (unlikely(err)) {
103151 trace_kfree_skb(skb, udp_recvmsg);
103152 if (!peeked) {
103153- atomic_inc(&sk->sk_drops);
103154+ atomic_inc_unchecked(&sk->sk_drops);
103155 UDP_INC_STATS_USER(sock_net(sk),
103156 UDP_MIB_INERRORS, is_udplite);
103157 }
103158@@ -1592,7 +1613,7 @@ csum_error:
103159 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
103160 drop:
103161 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
103162- atomic_inc(&sk->sk_drops);
103163+ atomic_inc_unchecked(&sk->sk_drops);
103164 kfree_skb(skb);
103165 return -1;
103166 }
103167@@ -1611,7 +1632,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
103168 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
103169
103170 if (!skb1) {
103171- atomic_inc(&sk->sk_drops);
103172+ atomic_inc_unchecked(&sk->sk_drops);
103173 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
103174 IS_UDPLITE(sk));
103175 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
103176@@ -1812,6 +1833,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
103177 goto csum_error;
103178
103179 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
103180+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103181+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
103182+#endif
103183 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
103184
103185 /*
103186@@ -2398,7 +2422,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
103187 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
103188 0, sock_i_ino(sp),
103189 atomic_read(&sp->sk_refcnt), sp,
103190- atomic_read(&sp->sk_drops));
103191+ atomic_read_unchecked(&sp->sk_drops));
103192 }
103193
103194 int udp4_seq_show(struct seq_file *seq, void *v)
103195diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
103196index 6156f68..d6ab46d 100644
103197--- a/net/ipv4/xfrm4_policy.c
103198+++ b/net/ipv4/xfrm4_policy.c
103199@@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
103200 fl4->flowi4_tos = iph->tos;
103201 }
103202
103203-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
103204+static int xfrm4_garbage_collect(struct dst_ops *ops)
103205 {
103206 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
103207
103208- xfrm4_policy_afinfo.garbage_collect(net);
103209+ xfrm_garbage_collect_deferred(net);
103210 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
103211 }
103212
103213@@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
103214
103215 static int __net_init xfrm4_net_init(struct net *net)
103216 {
103217- struct ctl_table *table;
103218+ ctl_table_no_const *table = NULL;
103219 struct ctl_table_header *hdr;
103220
103221- table = xfrm4_policy_table;
103222 if (!net_eq(net, &init_net)) {
103223- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
103224+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
103225 if (!table)
103226 goto err_alloc;
103227
103228 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
103229- }
103230-
103231- hdr = register_net_sysctl(net, "net/ipv4", table);
103232+ hdr = register_net_sysctl(net, "net/ipv4", table);
103233+ } else
103234+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
103235 if (!hdr)
103236 goto err_reg;
103237
103238@@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
103239 return 0;
103240
103241 err_reg:
103242- if (!net_eq(net, &init_net))
103243- kfree(table);
103244+ kfree(table);
103245 err_alloc:
103246 return -ENOMEM;
103247 }
103248diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
103249index 0169ccf..50d7b04 100644
103250--- a/net/ipv6/addrconf.c
103251+++ b/net/ipv6/addrconf.c
103252@@ -171,7 +171,7 @@ static struct ipv6_devconf ipv6_devconf __read_mostly = {
103253 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
103254 .mtu6 = IPV6_MIN_MTU,
103255 .accept_ra = 1,
103256- .accept_redirects = 1,
103257+ .accept_redirects = 0,
103258 .autoconf = 1,
103259 .force_mld_version = 0,
103260 .mldv1_unsolicited_report_interval = 10 * HZ,
103261@@ -208,7 +208,7 @@ static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = {
103262 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
103263 .mtu6 = IPV6_MIN_MTU,
103264 .accept_ra = 1,
103265- .accept_redirects = 1,
103266+ .accept_redirects = 0,
103267 .autoconf = 1,
103268 .force_mld_version = 0,
103269 .mldv1_unsolicited_report_interval = 10 * HZ,
103270@@ -604,7 +604,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
103271 idx = 0;
103272 head = &net->dev_index_head[h];
103273 rcu_read_lock();
103274- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
103275+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
103276 net->dev_base_seq;
103277 hlist_for_each_entry_rcu(dev, head, index_hlist) {
103278 if (idx < s_idx)
103279@@ -2396,7 +2396,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
103280 p.iph.ihl = 5;
103281 p.iph.protocol = IPPROTO_IPV6;
103282 p.iph.ttl = 64;
103283- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
103284+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
103285
103286 if (ops->ndo_do_ioctl) {
103287 mm_segment_t oldfs = get_fs();
103288@@ -3534,16 +3534,23 @@ static const struct file_operations if6_fops = {
103289 .release = seq_release_net,
103290 };
103291
103292+extern void register_ipv6_seq_ops_addr(struct seq_operations *addr);
103293+extern void unregister_ipv6_seq_ops_addr(void);
103294+
103295 static int __net_init if6_proc_net_init(struct net *net)
103296 {
103297- if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops))
103298+ register_ipv6_seq_ops_addr(&if6_seq_ops);
103299+ if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops)) {
103300+ unregister_ipv6_seq_ops_addr();
103301 return -ENOMEM;
103302+ }
103303 return 0;
103304 }
103305
103306 static void __net_exit if6_proc_net_exit(struct net *net)
103307 {
103308 remove_proc_entry("if_inet6", net->proc_net);
103309+ unregister_ipv6_seq_ops_addr();
103310 }
103311
103312 static struct pernet_operations if6_proc_net_ops = {
103313@@ -4159,7 +4166,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
103314 s_ip_idx = ip_idx = cb->args[2];
103315
103316 rcu_read_lock();
103317- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
103318+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
103319 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
103320 idx = 0;
103321 head = &net->dev_index_head[h];
103322@@ -4788,7 +4795,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
103323 rt_genid_bump_ipv6(net);
103324 break;
103325 }
103326- atomic_inc(&net->ipv6.dev_addr_genid);
103327+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
103328 }
103329
103330 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
103331@@ -4808,7 +4815,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
103332 int *valp = ctl->data;
103333 int val = *valp;
103334 loff_t pos = *ppos;
103335- struct ctl_table lctl;
103336+ ctl_table_no_const lctl;
103337 int ret;
103338
103339 /*
103340@@ -4893,7 +4900,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
103341 int *valp = ctl->data;
103342 int val = *valp;
103343 loff_t pos = *ppos;
103344- struct ctl_table lctl;
103345+ ctl_table_no_const lctl;
103346 int ret;
103347
103348 /*
103349diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
103350index e8c4400..a4cd5da 100644
103351--- a/net/ipv6/af_inet6.c
103352+++ b/net/ipv6/af_inet6.c
103353@@ -766,7 +766,7 @@ static int __net_init inet6_net_init(struct net *net)
103354 net->ipv6.sysctl.icmpv6_time = 1*HZ;
103355 net->ipv6.sysctl.flowlabel_consistency = 1;
103356 net->ipv6.sysctl.auto_flowlabels = 0;
103357- atomic_set(&net->ipv6.fib6_sernum, 1);
103358+ atomic_set_unchecked(&net->ipv6.fib6_sernum, 1);
103359
103360 err = ipv6_init_mibs(net);
103361 if (err)
103362diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
103363index 2cdc383..09cffb8 100644
103364--- a/net/ipv6/datagram.c
103365+++ b/net/ipv6/datagram.c
103366@@ -928,5 +928,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
103367 0,
103368 sock_i_ino(sp),
103369 atomic_read(&sp->sk_refcnt), sp,
103370- atomic_read(&sp->sk_drops));
103371+ atomic_read_unchecked(&sp->sk_drops));
103372 }
103373diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
103374index 97ae700..18dcae0 100644
103375--- a/net/ipv6/icmp.c
103376+++ b/net/ipv6/icmp.c
103377@@ -997,7 +997,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
103378
103379 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
103380 {
103381- struct ctl_table *table;
103382+ ctl_table_no_const *table;
103383
103384 table = kmemdup(ipv6_icmp_table_template,
103385 sizeof(ipv6_icmp_table_template),
103386diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
103387index b2d1838..0194c04 100644
103388--- a/net/ipv6/ip6_fib.c
103389+++ b/net/ipv6/ip6_fib.c
103390@@ -99,9 +99,9 @@ static int fib6_new_sernum(struct net *net)
103391 int new, old;
103392
103393 do {
103394- old = atomic_read(&net->ipv6.fib6_sernum);
103395+ old = atomic_read_unchecked(&net->ipv6.fib6_sernum);
103396 new = old < INT_MAX ? old + 1 : 1;
103397- } while (atomic_cmpxchg(&net->ipv6.fib6_sernum,
103398+ } while (atomic_cmpxchg_unchecked(&net->ipv6.fib6_sernum,
103399 old, new) != old);
103400 return new;
103401 }
103402diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
103403index 0e32d2e..98cbe65 100644
103404--- a/net/ipv6/ip6_gre.c
103405+++ b/net/ipv6/ip6_gre.c
103406@@ -71,8 +71,8 @@ struct ip6gre_net {
103407 struct net_device *fb_tunnel_dev;
103408 };
103409
103410-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
103411-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly;
103412+static struct rtnl_link_ops ip6gre_link_ops;
103413+static struct rtnl_link_ops ip6gre_tap_ops;
103414 static int ip6gre_tunnel_init(struct net_device *dev);
103415 static void ip6gre_tunnel_setup(struct net_device *dev);
103416 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
103417@@ -1289,7 +1289,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
103418 }
103419
103420
103421-static struct inet6_protocol ip6gre_protocol __read_mostly = {
103422+static struct inet6_protocol ip6gre_protocol = {
103423 .handler = ip6gre_rcv,
103424 .err_handler = ip6gre_err,
103425 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
103426@@ -1650,7 +1650,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
103427 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
103428 };
103429
103430-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
103431+static struct rtnl_link_ops ip6gre_link_ops = {
103432 .kind = "ip6gre",
103433 .maxtype = IFLA_GRE_MAX,
103434 .policy = ip6gre_policy,
103435@@ -1664,7 +1664,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
103436 .fill_info = ip6gre_fill_info,
103437 };
103438
103439-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
103440+static struct rtnl_link_ops ip6gre_tap_ops = {
103441 .kind = "ip6gretap",
103442 .maxtype = IFLA_GRE_MAX,
103443 .policy = ip6gre_policy,
103444diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
103445index 9cb94cf..5678108 100644
103446--- a/net/ipv6/ip6_tunnel.c
103447+++ b/net/ipv6/ip6_tunnel.c
103448@@ -86,7 +86,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
103449
103450 static int ip6_tnl_dev_init(struct net_device *dev);
103451 static void ip6_tnl_dev_setup(struct net_device *dev);
103452-static struct rtnl_link_ops ip6_link_ops __read_mostly;
103453+static struct rtnl_link_ops ip6_link_ops;
103454
103455 static int ip6_tnl_net_id __read_mostly;
103456 struct ip6_tnl_net {
103457@@ -1706,7 +1706,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
103458 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
103459 };
103460
103461-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
103462+static struct rtnl_link_ops ip6_link_ops = {
103463 .kind = "ip6tnl",
103464 .maxtype = IFLA_IPTUN_MAX,
103465 .policy = ip6_tnl_policy,
103466diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
103467index bcda14d..49378c9 100644
103468--- a/net/ipv6/ip6_vti.c
103469+++ b/net/ipv6/ip6_vti.c
103470@@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
103471
103472 static int vti6_dev_init(struct net_device *dev);
103473 static void vti6_dev_setup(struct net_device *dev);
103474-static struct rtnl_link_ops vti6_link_ops __read_mostly;
103475+static struct rtnl_link_ops vti6_link_ops;
103476
103477 static int vti6_net_id __read_mostly;
103478 struct vti6_net {
103479@@ -981,7 +981,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
103480 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
103481 };
103482
103483-static struct rtnl_link_ops vti6_link_ops __read_mostly = {
103484+static struct rtnl_link_ops vti6_link_ops = {
103485 .kind = "vti6",
103486 .maxtype = IFLA_VTI_MAX,
103487 .policy = vti6_policy,
103488diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
103489index e1a9583..7dd8f4d 100644
103490--- a/net/ipv6/ipv6_sockglue.c
103491+++ b/net/ipv6/ipv6_sockglue.c
103492@@ -993,7 +993,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
103493 if (sk->sk_type != SOCK_STREAM)
103494 return -ENOPROTOOPT;
103495
103496- msg.msg_control = optval;
103497+ msg.msg_control = (void __force_kernel *)optval;
103498 msg.msg_controllen = len;
103499 msg.msg_flags = flags;
103500
103501diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
103502index e080fbb..412b3cf 100644
103503--- a/net/ipv6/netfilter/ip6_tables.c
103504+++ b/net/ipv6/netfilter/ip6_tables.c
103505@@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
103506 #endif
103507
103508 static int get_info(struct net *net, void __user *user,
103509- const int *len, int compat)
103510+ int len, int compat)
103511 {
103512 char name[XT_TABLE_MAXNAMELEN];
103513 struct xt_table *t;
103514 int ret;
103515
103516- if (*len != sizeof(struct ip6t_getinfo)) {
103517- duprintf("length %u != %zu\n", *len,
103518+ if (len != sizeof(struct ip6t_getinfo)) {
103519+ duprintf("length %u != %zu\n", len,
103520 sizeof(struct ip6t_getinfo));
103521 return -EINVAL;
103522 }
103523@@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
103524 info.size = private->size;
103525 strcpy(info.name, name);
103526
103527- if (copy_to_user(user, &info, *len) != 0)
103528+ if (copy_to_user(user, &info, len) != 0)
103529 ret = -EFAULT;
103530 else
103531 ret = 0;
103532@@ -1983,7 +1983,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
103533
103534 switch (cmd) {
103535 case IP6T_SO_GET_INFO:
103536- ret = get_info(sock_net(sk), user, len, 1);
103537+ ret = get_info(sock_net(sk), user, *len, 1);
103538 break;
103539 case IP6T_SO_GET_ENTRIES:
103540 ret = compat_get_entries(sock_net(sk), user, len);
103541@@ -2030,7 +2030,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
103542
103543 switch (cmd) {
103544 case IP6T_SO_GET_INFO:
103545- ret = get_info(sock_net(sk), user, len, 0);
103546+ ret = get_info(sock_net(sk), user, *len, 0);
103547 break;
103548
103549 case IP6T_SO_GET_ENTRIES:
103550diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
103551index 6f187c8..34b367f 100644
103552--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
103553+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
103554@@ -96,12 +96,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
103555
103556 static int nf_ct_frag6_sysctl_register(struct net *net)
103557 {
103558- struct ctl_table *table;
103559+ ctl_table_no_const *table = NULL;
103560 struct ctl_table_header *hdr;
103561
103562- table = nf_ct_frag6_sysctl_table;
103563 if (!net_eq(net, &init_net)) {
103564- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
103565+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
103566 GFP_KERNEL);
103567 if (table == NULL)
103568 goto err_alloc;
103569@@ -112,9 +111,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
103570 table[2].data = &net->nf_frag.frags.high_thresh;
103571 table[2].extra1 = &net->nf_frag.frags.low_thresh;
103572 table[2].extra2 = &init_net.nf_frag.frags.high_thresh;
103573- }
103574-
103575- hdr = register_net_sysctl(net, "net/netfilter", table);
103576+ hdr = register_net_sysctl(net, "net/netfilter", table);
103577+ } else
103578+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
103579 if (hdr == NULL)
103580 goto err_reg;
103581
103582@@ -122,8 +121,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
103583 return 0;
103584
103585 err_reg:
103586- if (!net_eq(net, &init_net))
103587- kfree(table);
103588+ kfree(table);
103589 err_alloc:
103590 return -ENOMEM;
103591 }
103592diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
103593index 5b7a1ed..d9da205 100644
103594--- a/net/ipv6/ping.c
103595+++ b/net/ipv6/ping.c
103596@@ -240,6 +240,24 @@ static struct pernet_operations ping_v6_net_ops = {
103597 };
103598 #endif
103599
103600+static struct pingv6_ops real_pingv6_ops = {
103601+ .ipv6_recv_error = ipv6_recv_error,
103602+ .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
103603+ .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
103604+ .icmpv6_err_convert = icmpv6_err_convert,
103605+ .ipv6_icmp_error = ipv6_icmp_error,
103606+ .ipv6_chk_addr = ipv6_chk_addr,
103607+};
103608+
103609+static struct pingv6_ops dummy_pingv6_ops = {
103610+ .ipv6_recv_error = dummy_ipv6_recv_error,
103611+ .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
103612+ .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
103613+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
103614+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
103615+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
103616+};
103617+
103618 int __init pingv6_init(void)
103619 {
103620 #ifdef CONFIG_PROC_FS
103621@@ -247,13 +265,7 @@ int __init pingv6_init(void)
103622 if (ret)
103623 return ret;
103624 #endif
103625- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
103626- pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
103627- pingv6_ops.ip6_datagram_recv_specific_ctl =
103628- ip6_datagram_recv_specific_ctl;
103629- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
103630- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
103631- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
103632+ pingv6_ops = &real_pingv6_ops;
103633 return inet6_register_protosw(&pingv6_protosw);
103634 }
103635
103636@@ -262,14 +274,9 @@ int __init pingv6_init(void)
103637 */
103638 void pingv6_exit(void)
103639 {
103640- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
103641- pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
103642- pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
103643- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
103644- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
103645- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
103646 #ifdef CONFIG_PROC_FS
103647 unregister_pernet_subsys(&ping_v6_net_ops);
103648 #endif
103649+ pingv6_ops = &dummy_pingv6_ops;
103650 inet6_unregister_protosw(&pingv6_protosw);
103651 }
103652diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
103653index 1752cd0..3c6af41 100644
103654--- a/net/ipv6/proc.c
103655+++ b/net/ipv6/proc.c
103656@@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
103657 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
103658 goto proc_snmp6_fail;
103659
103660- net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
103661+ net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
103662 if (!net->mib.proc_net_devsnmp6)
103663 goto proc_dev_snmp6_fail;
103664 return 0;
103665diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
103666index 896af88..6e2ba628 100644
103667--- a/net/ipv6/raw.c
103668+++ b/net/ipv6/raw.c
103669@@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
103670 {
103671 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
103672 skb_checksum_complete(skb)) {
103673- atomic_inc(&sk->sk_drops);
103674+ atomic_inc_unchecked(&sk->sk_drops);
103675 kfree_skb(skb);
103676 return NET_RX_DROP;
103677 }
103678@@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
103679 struct raw6_sock *rp = raw6_sk(sk);
103680
103681 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
103682- atomic_inc(&sk->sk_drops);
103683+ atomic_inc_unchecked(&sk->sk_drops);
103684 kfree_skb(skb);
103685 return NET_RX_DROP;
103686 }
103687@@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
103688
103689 if (inet->hdrincl) {
103690 if (skb_checksum_complete(skb)) {
103691- atomic_inc(&sk->sk_drops);
103692+ atomic_inc_unchecked(&sk->sk_drops);
103693 kfree_skb(skb);
103694 return NET_RX_DROP;
103695 }
103696@@ -608,7 +608,7 @@ out:
103697 return err;
103698 }
103699
103700-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
103701+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
103702 struct flowi6 *fl6, struct dst_entry **dstp,
103703 unsigned int flags)
103704 {
103705@@ -914,12 +914,15 @@ do_confirm:
103706 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
103707 char __user *optval, int optlen)
103708 {
103709+ struct icmp6_filter filter;
103710+
103711 switch (optname) {
103712 case ICMPV6_FILTER:
103713 if (optlen > sizeof(struct icmp6_filter))
103714 optlen = sizeof(struct icmp6_filter);
103715- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
103716+ if (copy_from_user(&filter, optval, optlen))
103717 return -EFAULT;
103718+ raw6_sk(sk)->filter = filter;
103719 return 0;
103720 default:
103721 return -ENOPROTOOPT;
103722@@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
103723 char __user *optval, int __user *optlen)
103724 {
103725 int len;
103726+ struct icmp6_filter filter;
103727
103728 switch (optname) {
103729 case ICMPV6_FILTER:
103730@@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
103731 len = sizeof(struct icmp6_filter);
103732 if (put_user(len, optlen))
103733 return -EFAULT;
103734- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
103735+ filter = raw6_sk(sk)->filter;
103736+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
103737 return -EFAULT;
103738 return 0;
103739 default:
103740diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
103741index 1a157ca..9fc05f4 100644
103742--- a/net/ipv6/reassembly.c
103743+++ b/net/ipv6/reassembly.c
103744@@ -625,12 +625,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
103745
103746 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
103747 {
103748- struct ctl_table *table;
103749+ ctl_table_no_const *table = NULL;
103750 struct ctl_table_header *hdr;
103751
103752- table = ip6_frags_ns_ctl_table;
103753 if (!net_eq(net, &init_net)) {
103754- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
103755+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
103756 if (table == NULL)
103757 goto err_alloc;
103758
103759@@ -644,9 +643,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
103760 /* Don't export sysctls to unprivileged users */
103761 if (net->user_ns != &init_user_ns)
103762 table[0].procname = NULL;
103763- }
103764+ hdr = register_net_sysctl(net, "net/ipv6", table);
103765+ } else
103766+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
103767
103768- hdr = register_net_sysctl(net, "net/ipv6", table);
103769 if (hdr == NULL)
103770 goto err_reg;
103771
103772@@ -654,8 +654,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
103773 return 0;
103774
103775 err_reg:
103776- if (!net_eq(net, &init_net))
103777- kfree(table);
103778+ kfree(table);
103779 err_alloc:
103780 return -ENOMEM;
103781 }
103782diff --git a/net/ipv6/route.c b/net/ipv6/route.c
103783index a318dd89..7ecfea6 100644
103784--- a/net/ipv6/route.c
103785+++ b/net/ipv6/route.c
103786@@ -2965,7 +2965,7 @@ struct ctl_table ipv6_route_table_template[] = {
103787
103788 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
103789 {
103790- struct ctl_table *table;
103791+ ctl_table_no_const *table;
103792
103793 table = kmemdup(ipv6_route_table_template,
103794 sizeof(ipv6_route_table_template),
103795diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
103796index a24557a..00a9ed1 100644
103797--- a/net/ipv6/sit.c
103798+++ b/net/ipv6/sit.c
103799@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
103800 static void ipip6_dev_free(struct net_device *dev);
103801 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
103802 __be32 *v4dst);
103803-static struct rtnl_link_ops sit_link_ops __read_mostly;
103804+static struct rtnl_link_ops sit_link_ops;
103805
103806 static int sit_net_id __read_mostly;
103807 struct sit_net {
103808@@ -1750,7 +1750,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
103809 unregister_netdevice_queue(dev, head);
103810 }
103811
103812-static struct rtnl_link_ops sit_link_ops __read_mostly = {
103813+static struct rtnl_link_ops sit_link_ops = {
103814 .kind = "sit",
103815 .maxtype = IFLA_IPTUN_MAX,
103816 .policy = ipip6_policy,
103817diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
103818index c5c10fa..2577d51 100644
103819--- a/net/ipv6/sysctl_net_ipv6.c
103820+++ b/net/ipv6/sysctl_net_ipv6.c
103821@@ -78,7 +78,7 @@ static struct ctl_table ipv6_rotable[] = {
103822
103823 static int __net_init ipv6_sysctl_net_init(struct net *net)
103824 {
103825- struct ctl_table *ipv6_table;
103826+ ctl_table_no_const *ipv6_table;
103827 struct ctl_table *ipv6_route_table;
103828 struct ctl_table *ipv6_icmp_table;
103829 int err;
103830diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
103831index c277951..c7ee5bf 100644
103832--- a/net/ipv6/tcp_ipv6.c
103833+++ b/net/ipv6/tcp_ipv6.c
103834@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
103835 }
103836 }
103837
103838+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103839+extern int grsec_enable_blackhole;
103840+#endif
103841+
103842 static void tcp_v6_hash(struct sock *sk)
103843 {
103844 if (sk->sk_state != TCP_CLOSE) {
103845@@ -1341,6 +1345,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
103846 return 0;
103847
103848 reset:
103849+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103850+ if (!grsec_enable_blackhole)
103851+#endif
103852 tcp_v6_send_reset(sk, skb);
103853 discard:
103854 if (opt_skb)
103855@@ -1434,12 +1441,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
103856
103857 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest,
103858 tcp_v6_iif(skb));
103859- if (!sk)
103860+ if (!sk) {
103861+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103862+ ret = 1;
103863+#endif
103864 goto no_tcp_socket;
103865+ }
103866
103867 process:
103868- if (sk->sk_state == TCP_TIME_WAIT)
103869+ if (sk->sk_state == TCP_TIME_WAIT) {
103870+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103871+ ret = 2;
103872+#endif
103873 goto do_time_wait;
103874+ }
103875
103876 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
103877 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
103878@@ -1486,6 +1501,10 @@ csum_error:
103879 bad_packet:
103880 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
103881 } else {
103882+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103883+ if (!grsec_enable_blackhole || (ret == 1 &&
103884+ (skb->dev->flags & IFF_LOOPBACK)))
103885+#endif
103886 tcp_v6_send_reset(NULL, skb);
103887 }
103888
103889diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
103890index f6ba535..b41033f 100644
103891--- a/net/ipv6/udp.c
103892+++ b/net/ipv6/udp.c
103893@@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
103894 udp_ipv6_hash_secret + net_hash_mix(net));
103895 }
103896
103897+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103898+extern int grsec_enable_blackhole;
103899+#endif
103900+
103901 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
103902 {
103903 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
103904@@ -434,7 +438,7 @@ try_again:
103905 if (unlikely(err)) {
103906 trace_kfree_skb(skb, udpv6_recvmsg);
103907 if (!peeked) {
103908- atomic_inc(&sk->sk_drops);
103909+ atomic_inc_unchecked(&sk->sk_drops);
103910 if (is_udp4)
103911 UDP_INC_STATS_USER(sock_net(sk),
103912 UDP_MIB_INERRORS,
103913@@ -701,7 +705,7 @@ csum_error:
103914 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
103915 drop:
103916 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
103917- atomic_inc(&sk->sk_drops);
103918+ atomic_inc_unchecked(&sk->sk_drops);
103919 kfree_skb(skb);
103920 return -1;
103921 }
103922@@ -740,7 +744,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
103923 if (likely(skb1 == NULL))
103924 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
103925 if (!skb1) {
103926- atomic_inc(&sk->sk_drops);
103927+ atomic_inc_unchecked(&sk->sk_drops);
103928 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
103929 IS_UDPLITE(sk));
103930 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
103931@@ -919,6 +923,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
103932 goto csum_error;
103933
103934 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
103935+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103936+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
103937+#endif
103938 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
103939
103940 kfree_skb(skb);
103941diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
103942index 5f98364..5ca982a 100644
103943--- a/net/ipv6/xfrm6_policy.c
103944+++ b/net/ipv6/xfrm6_policy.c
103945@@ -130,8 +130,8 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
103946 {
103947 struct flowi6 *fl6 = &fl->u.ip6;
103948 int onlyproto = 0;
103949- u16 offset = skb_network_header_len(skb);
103950 const struct ipv6hdr *hdr = ipv6_hdr(skb);
103951+ u16 offset = sizeof(*hdr);
103952 struct ipv6_opt_hdr *exthdr;
103953 const unsigned char *nh = skb_network_header(skb);
103954 u8 nexthdr = nh[IP6CB(skb)->nhoff];
103955@@ -217,11 +217,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
103956 }
103957 }
103958
103959-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
103960+static int xfrm6_garbage_collect(struct dst_ops *ops)
103961 {
103962 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
103963
103964- xfrm6_policy_afinfo.garbage_collect(net);
103965+ xfrm_garbage_collect_deferred(net);
103966 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
103967 }
103968
103969@@ -334,19 +334,19 @@ static struct ctl_table xfrm6_policy_table[] = {
103970
103971 static int __net_init xfrm6_net_init(struct net *net)
103972 {
103973- struct ctl_table *table;
103974+ ctl_table_no_const *table = NULL;
103975 struct ctl_table_header *hdr;
103976
103977- table = xfrm6_policy_table;
103978 if (!net_eq(net, &init_net)) {
103979- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
103980+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
103981 if (!table)
103982 goto err_alloc;
103983
103984 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
103985- }
103986+ hdr = register_net_sysctl(net, "net/ipv6", table);
103987+ } else
103988+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
103989
103990- hdr = register_net_sysctl(net, "net/ipv6", table);
103991 if (!hdr)
103992 goto err_reg;
103993
103994@@ -354,8 +354,7 @@ static int __net_init xfrm6_net_init(struct net *net)
103995 return 0;
103996
103997 err_reg:
103998- if (!net_eq(net, &init_net))
103999- kfree(table);
104000+ kfree(table);
104001 err_alloc:
104002 return -ENOMEM;
104003 }
104004diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
104005index e15c16a..7cf07aa 100644
104006--- a/net/ipx/ipx_proc.c
104007+++ b/net/ipx/ipx_proc.c
104008@@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
104009 struct proc_dir_entry *p;
104010 int rc = -ENOMEM;
104011
104012- ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
104013+ ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
104014
104015 if (!ipx_proc_dir)
104016 goto out;
104017diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
104018index 61ceb4c..e788eb8 100644
104019--- a/net/irda/ircomm/ircomm_tty.c
104020+++ b/net/irda/ircomm/ircomm_tty.c
104021@@ -317,10 +317,10 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104022 add_wait_queue(&port->open_wait, &wait);
104023
104024 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
104025- __FILE__, __LINE__, tty->driver->name, port->count);
104026+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104027
104028 spin_lock_irqsave(&port->lock, flags);
104029- port->count--;
104030+ atomic_dec(&port->count);
104031 port->blocked_open++;
104032 spin_unlock_irqrestore(&port->lock, flags);
104033
104034@@ -355,7 +355,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104035 }
104036
104037 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
104038- __FILE__, __LINE__, tty->driver->name, port->count);
104039+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104040
104041 schedule();
104042 }
104043@@ -365,12 +365,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104044
104045 spin_lock_irqsave(&port->lock, flags);
104046 if (!tty_hung_up_p(filp))
104047- port->count++;
104048+ atomic_inc(&port->count);
104049 port->blocked_open--;
104050 spin_unlock_irqrestore(&port->lock, flags);
104051
104052 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
104053- __FILE__, __LINE__, tty->driver->name, port->count);
104054+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104055
104056 if (!retval)
104057 port->flags |= ASYNC_NORMAL_ACTIVE;
104058@@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
104059
104060 /* ++ is not atomic, so this should be protected - Jean II */
104061 spin_lock_irqsave(&self->port.lock, flags);
104062- self->port.count++;
104063+ atomic_inc(&self->port.count);
104064 spin_unlock_irqrestore(&self->port.lock, flags);
104065 tty_port_tty_set(&self->port, tty);
104066
104067 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
104068- self->line, self->port.count);
104069+ self->line, atomic_read(&self->port.count));
104070
104071 /* Not really used by us, but lets do it anyway */
104072 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
104073@@ -985,7 +985,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
104074 tty_kref_put(port->tty);
104075 }
104076 port->tty = NULL;
104077- port->count = 0;
104078+ atomic_set(&port->count, 0);
104079 spin_unlock_irqrestore(&port->lock, flags);
104080
104081 wake_up_interruptible(&port->open_wait);
104082@@ -1342,7 +1342,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
104083 seq_putc(m, '\n');
104084
104085 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
104086- seq_printf(m, "Open count: %d\n", self->port.count);
104087+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
104088 seq_printf(m, "Max data size: %d\n", self->max_data_size);
104089 seq_printf(m, "Max header size: %d\n", self->max_header_size);
104090
104091diff --git a/net/irda/irproc.c b/net/irda/irproc.c
104092index b9ac598..f88cc56 100644
104093--- a/net/irda/irproc.c
104094+++ b/net/irda/irproc.c
104095@@ -66,7 +66,7 @@ void __init irda_proc_register(void)
104096 {
104097 int i;
104098
104099- proc_irda = proc_mkdir("irda", init_net.proc_net);
104100+ proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
104101 if (proc_irda == NULL)
104102 return;
104103
104104diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
104105index a089b6b..3ca3b60 100644
104106--- a/net/iucv/af_iucv.c
104107+++ b/net/iucv/af_iucv.c
104108@@ -686,10 +686,10 @@ static void __iucv_auto_name(struct iucv_sock *iucv)
104109 {
104110 char name[12];
104111
104112- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
104113+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
104114 while (__iucv_get_sock_by_name(name)) {
104115 sprintf(name, "%08x",
104116- atomic_inc_return(&iucv_sk_list.autobind_name));
104117+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
104118 }
104119 memcpy(iucv->src_name, name, 8);
104120 }
104121diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
104122index 2a6a1fd..6c112b0 100644
104123--- a/net/iucv/iucv.c
104124+++ b/net/iucv/iucv.c
104125@@ -702,7 +702,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
104126 return NOTIFY_OK;
104127 }
104128
104129-static struct notifier_block __refdata iucv_cpu_notifier = {
104130+static struct notifier_block iucv_cpu_notifier = {
104131 .notifier_call = iucv_cpu_notify,
104132 };
104133
104134diff --git a/net/key/af_key.c b/net/key/af_key.c
104135index 1847ec4..26ef732 100644
104136--- a/net/key/af_key.c
104137+++ b/net/key/af_key.c
104138@@ -3049,10 +3049,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
104139 static u32 get_acqseq(void)
104140 {
104141 u32 res;
104142- static atomic_t acqseq;
104143+ static atomic_unchecked_t acqseq;
104144
104145 do {
104146- res = atomic_inc_return(&acqseq);
104147+ res = atomic_inc_return_unchecked(&acqseq);
104148 } while (!res);
104149 return res;
104150 }
104151diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
104152index edb78e6..8dc654a 100644
104153--- a/net/l2tp/l2tp_eth.c
104154+++ b/net/l2tp/l2tp_eth.c
104155@@ -42,12 +42,12 @@ struct l2tp_eth {
104156 struct sock *tunnel_sock;
104157 struct l2tp_session *session;
104158 struct list_head list;
104159- atomic_long_t tx_bytes;
104160- atomic_long_t tx_packets;
104161- atomic_long_t tx_dropped;
104162- atomic_long_t rx_bytes;
104163- atomic_long_t rx_packets;
104164- atomic_long_t rx_errors;
104165+ atomic_long_unchecked_t tx_bytes;
104166+ atomic_long_unchecked_t tx_packets;
104167+ atomic_long_unchecked_t tx_dropped;
104168+ atomic_long_unchecked_t rx_bytes;
104169+ atomic_long_unchecked_t rx_packets;
104170+ atomic_long_unchecked_t rx_errors;
104171 };
104172
104173 /* via l2tp_session_priv() */
104174@@ -98,10 +98,10 @@ static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *dev)
104175 int ret = l2tp_xmit_skb(session, skb, session->hdr_len);
104176
104177 if (likely(ret == NET_XMIT_SUCCESS)) {
104178- atomic_long_add(len, &priv->tx_bytes);
104179- atomic_long_inc(&priv->tx_packets);
104180+ atomic_long_add_unchecked(len, &priv->tx_bytes);
104181+ atomic_long_inc_unchecked(&priv->tx_packets);
104182 } else {
104183- atomic_long_inc(&priv->tx_dropped);
104184+ atomic_long_inc_unchecked(&priv->tx_dropped);
104185 }
104186 return NETDEV_TX_OK;
104187 }
104188@@ -111,12 +111,12 @@ static struct rtnl_link_stats64 *l2tp_eth_get_stats64(struct net_device *dev,
104189 {
104190 struct l2tp_eth *priv = netdev_priv(dev);
104191
104192- stats->tx_bytes = atomic_long_read(&priv->tx_bytes);
104193- stats->tx_packets = atomic_long_read(&priv->tx_packets);
104194- stats->tx_dropped = atomic_long_read(&priv->tx_dropped);
104195- stats->rx_bytes = atomic_long_read(&priv->rx_bytes);
104196- stats->rx_packets = atomic_long_read(&priv->rx_packets);
104197- stats->rx_errors = atomic_long_read(&priv->rx_errors);
104198+ stats->tx_bytes = atomic_long_read_unchecked(&priv->tx_bytes);
104199+ stats->tx_packets = atomic_long_read_unchecked(&priv->tx_packets);
104200+ stats->tx_dropped = atomic_long_read_unchecked(&priv->tx_dropped);
104201+ stats->rx_bytes = atomic_long_read_unchecked(&priv->rx_bytes);
104202+ stats->rx_packets = atomic_long_read_unchecked(&priv->rx_packets);
104203+ stats->rx_errors = atomic_long_read_unchecked(&priv->rx_errors);
104204 return stats;
104205 }
104206
104207@@ -166,15 +166,15 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
104208 nf_reset(skb);
104209
104210 if (dev_forward_skb(dev, skb) == NET_RX_SUCCESS) {
104211- atomic_long_inc(&priv->rx_packets);
104212- atomic_long_add(data_len, &priv->rx_bytes);
104213+ atomic_long_inc_unchecked(&priv->rx_packets);
104214+ atomic_long_add_unchecked(data_len, &priv->rx_bytes);
104215 } else {
104216- atomic_long_inc(&priv->rx_errors);
104217+ atomic_long_inc_unchecked(&priv->rx_errors);
104218 }
104219 return;
104220
104221 error:
104222- atomic_long_inc(&priv->rx_errors);
104223+ atomic_long_inc_unchecked(&priv->rx_errors);
104224 kfree_skb(skb);
104225 }
104226
104227diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
104228index 1a3c7e0..80f8b0c 100644
104229--- a/net/llc/llc_proc.c
104230+++ b/net/llc/llc_proc.c
104231@@ -247,7 +247,7 @@ int __init llc_proc_init(void)
104232 int rc = -ENOMEM;
104233 struct proc_dir_entry *p;
104234
104235- llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
104236+ llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
104237 if (!llc_proc_dir)
104238 goto out;
104239
104240diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
104241index 343da1e..509873f 100644
104242--- a/net/mac80211/cfg.c
104243+++ b/net/mac80211/cfg.c
104244@@ -541,7 +541,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
104245 ret = ieee80211_vif_use_channel(sdata, chandef,
104246 IEEE80211_CHANCTX_EXCLUSIVE);
104247 }
104248- } else if (local->open_count == local->monitors) {
104249+ } else if (local_read(&local->open_count) == local->monitors) {
104250 local->_oper_chandef = *chandef;
104251 ieee80211_hw_config(local, 0);
104252 }
104253@@ -3326,7 +3326,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
104254 else
104255 local->probe_req_reg--;
104256
104257- if (!local->open_count)
104258+ if (!local_read(&local->open_count))
104259 break;
104260
104261 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
104262@@ -3460,8 +3460,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
104263 if (chanctx_conf) {
104264 *chandef = sdata->vif.bss_conf.chandef;
104265 ret = 0;
104266- } else if (local->open_count > 0 &&
104267- local->open_count == local->monitors &&
104268+ } else if (local_read(&local->open_count) > 0 &&
104269+ local_read(&local->open_count) == local->monitors &&
104270 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
104271 if (local->use_chanctx)
104272 *chandef = local->monitor_chandef;
104273diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
104274index 8c68da3..0695016 100644
104275--- a/net/mac80211/ieee80211_i.h
104276+++ b/net/mac80211/ieee80211_i.h
104277@@ -29,6 +29,7 @@
104278 #include <net/ieee80211_radiotap.h>
104279 #include <net/cfg80211.h>
104280 #include <net/mac80211.h>
104281+#include <asm/local.h>
104282 #include "key.h"
104283 #include "sta_info.h"
104284 #include "debug.h"
104285@@ -1057,7 +1058,7 @@ struct ieee80211_local {
104286 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
104287 spinlock_t queue_stop_reason_lock;
104288
104289- int open_count;
104290+ local_t open_count;
104291 int monitors, cooked_mntrs;
104292 /* number of interfaces with corresponding FIF_ flags */
104293 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
104294diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
104295index 653f5eb..02994ee 100644
104296--- a/net/mac80211/iface.c
104297+++ b/net/mac80211/iface.c
104298@@ -532,7 +532,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104299 break;
104300 }
104301
104302- if (local->open_count == 0) {
104303+ if (local_read(&local->open_count) == 0) {
104304 res = drv_start(local);
104305 if (res)
104306 goto err_del_bss;
104307@@ -579,7 +579,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104308 res = drv_add_interface(local, sdata);
104309 if (res)
104310 goto err_stop;
104311- } else if (local->monitors == 0 && local->open_count == 0) {
104312+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
104313 res = ieee80211_add_virtual_monitor(local);
104314 if (res)
104315 goto err_stop;
104316@@ -688,7 +688,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104317 atomic_inc(&local->iff_promiscs);
104318
104319 if (coming_up)
104320- local->open_count++;
104321+ local_inc(&local->open_count);
104322
104323 if (hw_reconf_flags)
104324 ieee80211_hw_config(local, hw_reconf_flags);
104325@@ -726,7 +726,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104326 err_del_interface:
104327 drv_remove_interface(local, sdata);
104328 err_stop:
104329- if (!local->open_count)
104330+ if (!local_read(&local->open_count))
104331 drv_stop(local);
104332 err_del_bss:
104333 sdata->bss = NULL;
104334@@ -892,7 +892,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104335 }
104336
104337 if (going_down)
104338- local->open_count--;
104339+ local_dec(&local->open_count);
104340
104341 switch (sdata->vif.type) {
104342 case NL80211_IFTYPE_AP_VLAN:
104343@@ -954,7 +954,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104344 }
104345 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
104346
104347- if (local->open_count == 0)
104348+ if (local_read(&local->open_count) == 0)
104349 ieee80211_clear_tx_pending(local);
104350
104351 /*
104352@@ -997,7 +997,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104353 if (cancel_scan)
104354 flush_delayed_work(&local->scan_work);
104355
104356- if (local->open_count == 0) {
104357+ if (local_read(&local->open_count) == 0) {
104358 ieee80211_stop_device(local);
104359
104360 /* no reconfiguring after stop! */
104361@@ -1008,7 +1008,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104362 ieee80211_configure_filter(local);
104363 ieee80211_hw_config(local, hw_reconf_flags);
104364
104365- if (local->monitors == local->open_count)
104366+ if (local->monitors == local_read(&local->open_count))
104367 ieee80211_add_virtual_monitor(local);
104368 }
104369
104370diff --git a/net/mac80211/main.c b/net/mac80211/main.c
104371index 0de7c93..884b2ca 100644
104372--- a/net/mac80211/main.c
104373+++ b/net/mac80211/main.c
104374@@ -175,7 +175,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
104375 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
104376 IEEE80211_CONF_CHANGE_POWER);
104377
104378- if (changed && local->open_count) {
104379+ if (changed && local_read(&local->open_count)) {
104380 ret = drv_config(local, changed);
104381 /*
104382 * Goal:
104383diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
104384index 4c5192e..04cc0d8 100644
104385--- a/net/mac80211/pm.c
104386+++ b/net/mac80211/pm.c
104387@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
104388 struct ieee80211_sub_if_data *sdata;
104389 struct sta_info *sta;
104390
104391- if (!local->open_count)
104392+ if (!local_read(&local->open_count))
104393 goto suspend;
104394
104395 ieee80211_scan_cancel(local);
104396@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
104397 cancel_work_sync(&local->dynamic_ps_enable_work);
104398 del_timer_sync(&local->dynamic_ps_timer);
104399
104400- local->wowlan = wowlan && local->open_count;
104401+ local->wowlan = wowlan && local_read(&local->open_count);
104402 if (local->wowlan) {
104403 int err = drv_suspend(local, wowlan);
104404 if (err < 0) {
104405@@ -125,7 +125,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
104406 WARN_ON(!list_empty(&local->chanctx_list));
104407
104408 /* stop hardware - this must stop RX */
104409- if (local->open_count)
104410+ if (local_read(&local->open_count))
104411 ieee80211_stop_device(local);
104412
104413 suspend:
104414diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
104415index 6081329..ab23834 100644
104416--- a/net/mac80211/rate.c
104417+++ b/net/mac80211/rate.c
104418@@ -720,7 +720,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
104419
104420 ASSERT_RTNL();
104421
104422- if (local->open_count)
104423+ if (local_read(&local->open_count))
104424 return -EBUSY;
104425
104426 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
104427diff --git a/net/mac80211/util.c b/net/mac80211/util.c
104428index 3c61060..7bed2e3 100644
104429--- a/net/mac80211/util.c
104430+++ b/net/mac80211/util.c
104431@@ -1669,7 +1669,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
104432 }
104433 #endif
104434 /* everything else happens only if HW was up & running */
104435- if (!local->open_count)
104436+ if (!local_read(&local->open_count))
104437 goto wake_up;
104438
104439 /*
104440@@ -1895,7 +1895,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
104441 local->in_reconfig = false;
104442 barrier();
104443
104444- if (local->monitors == local->open_count && local->monitors > 0)
104445+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
104446 ieee80211_add_virtual_monitor(local);
104447
104448 /*
104449diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
104450index ae5096ab..e5aa70a 100644
104451--- a/net/netfilter/Kconfig
104452+++ b/net/netfilter/Kconfig
104453@@ -1105,6 +1105,16 @@ config NETFILTER_XT_MATCH_ESP
104454
104455 To compile it as a module, choose M here. If unsure, say N.
104456
104457+config NETFILTER_XT_MATCH_GRADM
104458+ tristate '"gradm" match support'
104459+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
104460+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
104461+ ---help---
104462+ The gradm match allows to match on grsecurity RBAC being enabled.
104463+ It is useful when iptables rules are applied early on bootup to
104464+ prevent connections to the machine (except from a trusted host)
104465+ while the RBAC system is disabled.
104466+
104467 config NETFILTER_XT_MATCH_HASHLIMIT
104468 tristate '"hashlimit" match support'
104469 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
104470diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
104471index a9571be..c59e173 100644
104472--- a/net/netfilter/Makefile
104473+++ b/net/netfilter/Makefile
104474@@ -137,6 +137,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
104475 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
104476 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
104477 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
104478+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
104479 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
104480 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
104481 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
104482diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
104483index d259da3..6a32b2c 100644
104484--- a/net/netfilter/ipset/ip_set_core.c
104485+++ b/net/netfilter/ipset/ip_set_core.c
104486@@ -1952,7 +1952,7 @@ done:
104487 return ret;
104488 }
104489
104490-static struct nf_sockopt_ops so_set __read_mostly = {
104491+static struct nf_sockopt_ops so_set = {
104492 .pf = PF_INET,
104493 .get_optmin = SO_IP_SET,
104494 .get_optmax = SO_IP_SET + 1,
104495diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
104496index b0f7b62..0541842 100644
104497--- a/net/netfilter/ipvs/ip_vs_conn.c
104498+++ b/net/netfilter/ipvs/ip_vs_conn.c
104499@@ -572,7 +572,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
104500 /* Increase the refcnt counter of the dest */
104501 ip_vs_dest_hold(dest);
104502
104503- conn_flags = atomic_read(&dest->conn_flags);
104504+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
104505 if (cp->protocol != IPPROTO_UDP)
104506 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
104507 flags = cp->flags;
104508@@ -922,7 +922,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af,
104509
104510 cp->control = NULL;
104511 atomic_set(&cp->n_control, 0);
104512- atomic_set(&cp->in_pkts, 0);
104513+ atomic_set_unchecked(&cp->in_pkts, 0);
104514
104515 cp->packet_xmit = NULL;
104516 cp->app = NULL;
104517@@ -1229,7 +1229,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
104518
104519 /* Don't drop the entry if its number of incoming packets is not
104520 located in [0, 8] */
104521- i = atomic_read(&cp->in_pkts);
104522+ i = atomic_read_unchecked(&cp->in_pkts);
104523 if (i > 8 || i < 0) return 0;
104524
104525 if (!todrop_rate[i]) return 0;
104526diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
104527index 990decb..5075248 100644
104528--- a/net/netfilter/ipvs/ip_vs_core.c
104529+++ b/net/netfilter/ipvs/ip_vs_core.c
104530@@ -568,7 +568,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
104531 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
104532 /* do not touch skb anymore */
104533
104534- atomic_inc(&cp->in_pkts);
104535+ atomic_inc_unchecked(&cp->in_pkts);
104536 ip_vs_conn_put(cp);
104537 return ret;
104538 }
104539@@ -1712,7 +1712,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
104540 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
104541 pkts = sysctl_sync_threshold(ipvs);
104542 else
104543- pkts = atomic_add_return(1, &cp->in_pkts);
104544+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
104545
104546 if (ipvs->sync_state & IP_VS_STATE_MASTER)
104547 ip_vs_sync_conn(net, cp, pkts);
104548diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
104549index ac7ba68..9735acb9 100644
104550--- a/net/netfilter/ipvs/ip_vs_ctl.c
104551+++ b/net/netfilter/ipvs/ip_vs_ctl.c
104552@@ -800,7 +800,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
104553 */
104554 ip_vs_rs_hash(ipvs, dest);
104555 }
104556- atomic_set(&dest->conn_flags, conn_flags);
104557+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
104558
104559 /* bind the service */
104560 old_svc = rcu_dereference_protected(dest->svc, 1);
104561@@ -1665,7 +1665,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
104562 * align with netns init in ip_vs_control_net_init()
104563 */
104564
104565-static struct ctl_table vs_vars[] = {
104566+static ctl_table_no_const vs_vars[] __read_only = {
104567 {
104568 .procname = "amemthresh",
104569 .maxlen = sizeof(int),
104570@@ -2000,7 +2000,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
104571 " %-7s %-6d %-10d %-10d\n",
104572 &dest->addr.in6,
104573 ntohs(dest->port),
104574- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
104575+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
104576 atomic_read(&dest->weight),
104577 atomic_read(&dest->activeconns),
104578 atomic_read(&dest->inactconns));
104579@@ -2011,7 +2011,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
104580 "%-7s %-6d %-10d %-10d\n",
104581 ntohl(dest->addr.ip),
104582 ntohs(dest->port),
104583- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
104584+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
104585 atomic_read(&dest->weight),
104586 atomic_read(&dest->activeconns),
104587 atomic_read(&dest->inactconns));
104588@@ -2500,7 +2500,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
104589
104590 entry.addr = dest->addr.ip;
104591 entry.port = dest->port;
104592- entry.conn_flags = atomic_read(&dest->conn_flags);
104593+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
104594 entry.weight = atomic_read(&dest->weight);
104595 entry.u_threshold = dest->u_threshold;
104596 entry.l_threshold = dest->l_threshold;
104597@@ -3040,7 +3040,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
104598 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
104599 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
104600 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
104601- (atomic_read(&dest->conn_flags) &
104602+ (atomic_read_unchecked(&dest->conn_flags) &
104603 IP_VS_CONN_F_FWD_MASK)) ||
104604 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
104605 atomic_read(&dest->weight)) ||
104606@@ -3673,7 +3673,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
104607 {
104608 int idx;
104609 struct netns_ipvs *ipvs = net_ipvs(net);
104610- struct ctl_table *tbl;
104611+ ctl_table_no_const *tbl;
104612
104613 atomic_set(&ipvs->dropentry, 0);
104614 spin_lock_init(&ipvs->dropentry_lock);
104615diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
104616index 127f140..553d652 100644
104617--- a/net/netfilter/ipvs/ip_vs_lblc.c
104618+++ b/net/netfilter/ipvs/ip_vs_lblc.c
104619@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
104620 * IPVS LBLC sysctl table
104621 */
104622 #ifdef CONFIG_SYSCTL
104623-static struct ctl_table vs_vars_table[] = {
104624+static ctl_table_no_const vs_vars_table[] __read_only = {
104625 {
104626 .procname = "lblc_expiration",
104627 .data = NULL,
104628diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
104629index 2229d2d..b32b785 100644
104630--- a/net/netfilter/ipvs/ip_vs_lblcr.c
104631+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
104632@@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
104633 * IPVS LBLCR sysctl table
104634 */
104635
104636-static struct ctl_table vs_vars_table[] = {
104637+static ctl_table_no_const vs_vars_table[] __read_only = {
104638 {
104639 .procname = "lblcr_expiration",
104640 .data = NULL,
104641diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
104642index 7162c86..9eeb60e 100644
104643--- a/net/netfilter/ipvs/ip_vs_sync.c
104644+++ b/net/netfilter/ipvs/ip_vs_sync.c
104645@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
104646 cp = cp->control;
104647 if (cp) {
104648 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
104649- pkts = atomic_add_return(1, &cp->in_pkts);
104650+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
104651 else
104652 pkts = sysctl_sync_threshold(ipvs);
104653 ip_vs_sync_conn(net, cp->control, pkts);
104654@@ -771,7 +771,7 @@ control:
104655 if (!cp)
104656 return;
104657 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
104658- pkts = atomic_add_return(1, &cp->in_pkts);
104659+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
104660 else
104661 pkts = sysctl_sync_threshold(ipvs);
104662 goto sloop;
104663@@ -901,7 +901,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
104664
104665 if (opt)
104666 memcpy(&cp->in_seq, opt, sizeof(*opt));
104667- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
104668+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
104669 cp->state = state;
104670 cp->old_state = cp->state;
104671 /*
104672diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
104673index bd90bf8..816a020d 100644
104674--- a/net/netfilter/ipvs/ip_vs_xmit.c
104675+++ b/net/netfilter/ipvs/ip_vs_xmit.c
104676@@ -1215,7 +1215,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
104677 else
104678 rc = NF_ACCEPT;
104679 /* do not touch skb anymore */
104680- atomic_inc(&cp->in_pkts);
104681+ atomic_inc_unchecked(&cp->in_pkts);
104682 goto out;
104683 }
104684
104685@@ -1308,7 +1308,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
104686 else
104687 rc = NF_ACCEPT;
104688 /* do not touch skb anymore */
104689- atomic_inc(&cp->in_pkts);
104690+ atomic_inc_unchecked(&cp->in_pkts);
104691 goto out;
104692 }
104693
104694diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
104695index a4b5e2a..13b1de3 100644
104696--- a/net/netfilter/nf_conntrack_acct.c
104697+++ b/net/netfilter/nf_conntrack_acct.c
104698@@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
104699 #ifdef CONFIG_SYSCTL
104700 static int nf_conntrack_acct_init_sysctl(struct net *net)
104701 {
104702- struct ctl_table *table;
104703+ ctl_table_no_const *table;
104704
104705 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
104706 GFP_KERNEL);
104707diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
104708index 5016a69..594f8e9 100644
104709--- a/net/netfilter/nf_conntrack_core.c
104710+++ b/net/netfilter/nf_conntrack_core.c
104711@@ -1739,6 +1739,10 @@ void nf_conntrack_init_end(void)
104712 #define DYING_NULLS_VAL ((1<<30)+1)
104713 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
104714
104715+#ifdef CONFIG_GRKERNSEC_HIDESYM
104716+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
104717+#endif
104718+
104719 int nf_conntrack_init_net(struct net *net)
104720 {
104721 int ret = -ENOMEM;
104722@@ -1764,7 +1768,11 @@ int nf_conntrack_init_net(struct net *net)
104723 if (!net->ct.stat)
104724 goto err_pcpu_lists;
104725
104726+#ifdef CONFIG_GRKERNSEC_HIDESYM
104727+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08x", atomic_inc_return_unchecked(&conntrack_cache_id));
104728+#else
104729 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
104730+#endif
104731 if (!net->ct.slabname)
104732 goto err_slabname;
104733
104734diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
104735index 4e78c57..ec8fb74 100644
104736--- a/net/netfilter/nf_conntrack_ecache.c
104737+++ b/net/netfilter/nf_conntrack_ecache.c
104738@@ -264,7 +264,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
104739 #ifdef CONFIG_SYSCTL
104740 static int nf_conntrack_event_init_sysctl(struct net *net)
104741 {
104742- struct ctl_table *table;
104743+ ctl_table_no_const *table;
104744
104745 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
104746 GFP_KERNEL);
104747diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
104748index 5b3eae7..dd4b8fe 100644
104749--- a/net/netfilter/nf_conntrack_helper.c
104750+++ b/net/netfilter/nf_conntrack_helper.c
104751@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
104752
104753 static int nf_conntrack_helper_init_sysctl(struct net *net)
104754 {
104755- struct ctl_table *table;
104756+ ctl_table_no_const *table;
104757
104758 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
104759 GFP_KERNEL);
104760diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
104761index b65d586..beec902 100644
104762--- a/net/netfilter/nf_conntrack_proto.c
104763+++ b/net/netfilter/nf_conntrack_proto.c
104764@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
104765
104766 static void
104767 nf_ct_unregister_sysctl(struct ctl_table_header **header,
104768- struct ctl_table **table,
104769+ ctl_table_no_const **table,
104770 unsigned int users)
104771 {
104772 if (users > 0)
104773diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
104774index cf65a1e..2f291e9 100644
104775--- a/net/netfilter/nf_conntrack_standalone.c
104776+++ b/net/netfilter/nf_conntrack_standalone.c
104777@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
104778
104779 static int nf_conntrack_standalone_init_sysctl(struct net *net)
104780 {
104781- struct ctl_table *table;
104782+ ctl_table_no_const *table;
104783
104784 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
104785 GFP_KERNEL);
104786diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
104787index 7a394df..bd91a8a 100644
104788--- a/net/netfilter/nf_conntrack_timestamp.c
104789+++ b/net/netfilter/nf_conntrack_timestamp.c
104790@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
104791 #ifdef CONFIG_SYSCTL
104792 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
104793 {
104794- struct ctl_table *table;
104795+ ctl_table_no_const *table;
104796
104797 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
104798 GFP_KERNEL);
104799diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
104800index d719764..311bc60 100644
104801--- a/net/netfilter/nf_log.c
104802+++ b/net/netfilter/nf_log.c
104803@@ -353,7 +353,7 @@ static const struct file_operations nflog_file_ops = {
104804
104805 #ifdef CONFIG_SYSCTL
104806 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
104807-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
104808+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
104809
104810 static int nf_log_proc_dostring(struct ctl_table *table, int write,
104811 void __user *buffer, size_t *lenp, loff_t *ppos)
104812@@ -384,14 +384,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
104813 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
104814 mutex_unlock(&nf_log_mutex);
104815 } else {
104816+ ctl_table_no_const nf_log_table = *table;
104817+
104818 mutex_lock(&nf_log_mutex);
104819 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
104820 lockdep_is_held(&nf_log_mutex));
104821 if (!logger)
104822- table->data = "NONE";
104823+ nf_log_table.data = "NONE";
104824 else
104825- table->data = logger->name;
104826- r = proc_dostring(table, write, buffer, lenp, ppos);
104827+ nf_log_table.data = logger->name;
104828+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
104829 mutex_unlock(&nf_log_mutex);
104830 }
104831
104832diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
104833index c68c1e5..8b5d670 100644
104834--- a/net/netfilter/nf_sockopt.c
104835+++ b/net/netfilter/nf_sockopt.c
104836@@ -43,7 +43,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
104837 }
104838 }
104839
104840- list_add(&reg->list, &nf_sockopts);
104841+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
104842 out:
104843 mutex_unlock(&nf_sockopt_mutex);
104844 return ret;
104845@@ -53,7 +53,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
104846 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
104847 {
104848 mutex_lock(&nf_sockopt_mutex);
104849- list_del(&reg->list);
104850+ pax_list_del((struct list_head *)&reg->list);
104851 mutex_unlock(&nf_sockopt_mutex);
104852 }
104853 EXPORT_SYMBOL(nf_unregister_sockopt);
104854diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
104855index 5f1be5b..2cba8cd 100644
104856--- a/net/netfilter/nfnetlink_log.c
104857+++ b/net/netfilter/nfnetlink_log.c
104858@@ -80,7 +80,7 @@ static int nfnl_log_net_id __read_mostly;
104859 struct nfnl_log_net {
104860 spinlock_t instances_lock;
104861 struct hlist_head instance_table[INSTANCE_BUCKETS];
104862- atomic_t global_seq;
104863+ atomic_unchecked_t global_seq;
104864 };
104865
104866 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
104867@@ -563,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
104868 /* global sequence number */
104869 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
104870 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
104871- htonl(atomic_inc_return(&log->global_seq))))
104872+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
104873 goto nla_put_failure;
104874
104875 if (data_len) {
104876diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
104877new file mode 100644
104878index 0000000..c566332
104879--- /dev/null
104880+++ b/net/netfilter/xt_gradm.c
104881@@ -0,0 +1,51 @@
104882+/*
104883+ * gradm match for netfilter
104884